From 2909d4ecc3b4f6b9e3da4ae2c94a36badde8baba 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 | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/babel.config.js b/babel.config.js index 5102c9141d9d..b3b107466635 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 @@ -36,6 +42,8 @@ module.exports = function(api) { case "standalone": convertESM = false; ignoreLib = false; + includeRegeneratorRuntime = true; + // rollup-commonjs will converts node_modules to ESM unambiguousSources.push( "**/node_modules", "packages/babel-preset-env/data", @@ -62,6 +70,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, @@ -119,6 +138,10 @@ module.exports = function(api) { test: unambiguousSources, sourceType: "unambiguous", }, + includeRegeneratorRuntime && { + exclude: /regenerator-runtime/, + plugins: [["@babel/transform-runtime", transformRuntimeOptions]], + }, ].filter(Boolean), };