From 53c74e888b51f2fef01c24919cc9a536a49f9cd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Sat, 21 Dec 2019 00:12:48 +0100 Subject: [PATCH] Include regenerator-runtime in standalone build --- babel.config.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/babel.config.js b/babel.config.js index 367b87d714da..0f1dbeaf4027 100644 --- a/babel.config.js +++ b/babel.config.js @@ -1,5 +1,7 @@ "use strict"; +const path = require("path"); + module.exports = function(api) { const env = api.env(); @@ -14,6 +16,10 @@ module.exports = function(api) { let convertESM = true; let ignoreLib = true; + let includeRegeneratorRuntime = false; + + let transformRuntimeOptions; + const nodeVersion = "6.9"; // The vast majority of our src files are modules, but we use // unambiguous to keep things simple until we get around to renaming @@ -45,8 +51,11 @@ module.exports = function(api) { case "standalone": convertESM = false; ignoreLib = false; + includeRegeneratorRuntime = true; + // rollup-commonjs will converts node_modules to ESM unambiguousSources.push( "**/node_modules", + // todo: remove this after it is rewritten into ESM "packages/babel-preset-env/data" ); // targets to browserslists: defaults @@ -70,6 +79,17 @@ module.exports = function(api) { break; } + if (includeRegeneratorRuntime) { + const babelRuntimePkgPath = require.resolve("@babel/runtime/package.json"); + + transformRuntimeOptions = { + helpers: false, // Helpers are handled by rollup when needed + regenerator: true, + version: require(babelRuntimePkgPath).version, + absoluteRuntime: path.dirname(babelRuntimePkgPath), + }; + } + const config = { // Our dependencies are all standard CommonJS, along with all sorts of // other random files in Babel's codebase, so we use script as the default, @@ -127,6 +147,10 @@ module.exports = function(api) { test: unambiguousSources, sourceType: "unambiguous", }, + includeRegeneratorRuntime && { + exclude: /regenerator-runtime/, + plugins: [["@babel/transform-runtime", transformRuntimeOptions]], + }, ].filter(Boolean), };