diff --git a/Gulpfile.js b/Gulpfile.js index eeec97362bfd..28f016f6c982 100644 --- a/Gulpfile.js +++ b/Gulpfile.js @@ -110,7 +110,7 @@ if (process.env.CIRCLE_PR_NUMBER) { const babelVersion = require("./packages/babel-core/package.json").version + versionSuffix; -function buildRollup(packages) { +function buildRollup(packages, targetBrowsers) { const sourcemap = process.env.NODE_ENV === "production"; return Promise.all( packages.map(async ({ src, format, dest, name, filename }) => { @@ -166,11 +166,12 @@ function buildRollup(packages) { ], }), rollupJson(), - rollupNodePolyfills({ - sourceMap: sourcemap, - include: "**/*.{js,ts}", - }), - ], + targetBrowsers && + rollupNodePolyfills({ + sourceMap: sourcemap, + include: "**/*.{js,ts}", + }), + ].filter(Boolean), }); const outputFile = path.join(src, dest, filename || "index.js"); @@ -235,7 +236,7 @@ const standaloneBundle = [ ]; gulp.task("build-rollup", () => buildRollup(libBundles)); -gulp.task("build-babel-standalone", () => buildRollup(standaloneBundle)); +gulp.task("build-babel-standalone", () => buildRollup(standaloneBundle, true)); gulp.task("build-babel", () => buildBabel(/* exclude */ libBundles)); gulp.task("build", gulp.parallel("build-rollup", "build-babel")); diff --git a/babel.config.js b/babel.config.js index df574739b1c8..110f711a89d5 100644 --- a/babel.config.js +++ b/babel.config.js @@ -77,7 +77,7 @@ module.exports = function (api) { break; } - if (process.env.STRIP_BABEL_8_FLAG && !!process.env.BABEL_8_BREAKING) { + if (process.env.STRIP_BABEL_8_FLAG && bool(process.env.BABEL_8_BREAKING)) { // Never apply polyfills when compiling for Babel 8 polyfillRequireResolve = false; } @@ -127,7 +127,7 @@ module.exports = function (api) { process.env.STRIP_BABEL_8_FLAG && [ pluginToggleBabel8Breaking, - { breaking: !!process.env.BABEL_8_BREAKING }, + { breaking: bool(process.env.BABEL_8_BREAKING) }, ], polyfillRequireResolve && pluginPolyfillRequireResolve, ].filter(Boolean), @@ -175,6 +175,11 @@ module.exports = function (api) { return config; }; +// env vars from the cli are always strings, so !!ENV_VAR returns true for "false" +function bool(value) { + return value && value === "false" && value === "0"; +} + // TODO(Babel 8) This polyfill is only needed for Node.js 6 and 8 function pluginPolyfillRequireResolve({ template, types: t }) { return { @@ -214,6 +219,7 @@ function pluginPolyfillRequireResolve({ template, types: t }) { }, }; } + function pluginToggleBabel8Breaking({ types: t }, { breaking }) { return { visitor: {