From bfe45e20550272f9ff0504d9f3dd1a0fc2cc7ee4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Thu, 26 Dec 2019 14:33:50 +0100 Subject: [PATCH] Fix rollup build --- Gulpfile.js | 1 + babel.config.js | 13 ++++--------- scripts/rollup-plugin-babel-source.js | 15 +++++++++++---- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/Gulpfile.js b/Gulpfile.js index 9af1c2a79478..a78f68ea4914 100644 --- a/Gulpfile.js +++ b/Gulpfile.js @@ -183,6 +183,7 @@ function buildRollup(packages) { rollupCommonJs({ include: [ /node_modules/, + "packages/babel-runtime/regenerator/**", "packages/babel-preset-env/data/*.js", // Rollup doesn't read export maps, so it loads the cjs fallback "packages/babel-compat-data/*.js", diff --git a/babel.config.js b/babel.config.js index b3b107466635..8fa932136dfd 100644 --- a/babel.config.js +++ b/babel.config.js @@ -1,7 +1,5 @@ "use strict"; -const path = require("path"); - module.exports = function(api) { const env = api.env(); @@ -35,21 +33,19 @@ module.exports = function(api) { switch (env) { // Configs used during bundling builds. - case "rollup": - envOpts.targets = { - node: nodeVersion, - }; case "standalone": + includeRegeneratorRuntime = true; + unambiguousSources.push("packages/babel-runtime/regenerator"); + case "rollup": convertESM = false; ignoreLib = false; - includeRegeneratorRuntime = true; // rollup-commonjs will converts node_modules to ESM unambiguousSources.push( "**/node_modules", "packages/babel-preset-env/data", "packages/babel-compat-data" ); - // targets to browserslists: defaults + if (env === "rollup") envOpts.targets = { node: nodeVersion }; break; case "production": // Config during builds before publish. @@ -77,7 +73,6 @@ module.exports = function(api) { helpers: false, // Helpers are handled by rollup when needed regenerator: true, version: require(babelRuntimePkgPath).version, - absoluteRuntime: path.dirname(babelRuntimePkgPath), }; } diff --git a/scripts/rollup-plugin-babel-source.js b/scripts/rollup-plugin-babel-source.js index 79f1a6c4101b..54f71f34e050 100644 --- a/scripts/rollup-plugin-babel-source.js +++ b/scripts/rollup-plugin-babel-source.js @@ -37,13 +37,20 @@ module.exports = function() { return null; }, resolveId(importee) { - let packageFolderName; + if (importee === "@babel/runtime/regenerator") { + return path.join( + dirname, + "packages", + "babel-runtime", + "regenerator", + "index.js" + ); + } + const matches = importee.match(/^@babel\/([^/]+)$/); if (matches) { - packageFolderName = `babel-${matches[1]}`; - } + const packageFolderName = `babel-${matches[1]}`; - if (packageFolderName) { // resolve babel package names to their src index file const packageFolder = path.join(dirname, "packages", packageFolderName); const packageJson = require(path.join(packageFolder, "package.json"));