From 02760d0f70c76833010918b5c23502ae061bbae9 Mon Sep 17 00:00:00 2001 From: Logan Smyth Date: Sun, 29 Jul 2018 16:52:11 -0700 Subject: [PATCH] Run transform-runtime on the standalone bundle so it stays ES5-compatible. (#8024) --- babel.config.js | 33 ++++++++++++++++++++++++++++++++- package.json | 2 ++ yarn.lock | 18 ++++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/babel.config.js b/babel.config.js index d68eb3172f..ce4eb1d565 100644 --- a/babel.config.js +++ b/babel.config.js @@ -13,13 +13,18 @@ module.exports = function(api) { let convertESM = true; let ignoreLib = true; + let includeRuntime = false; switch (env) { // Configs used during bundling builds. case "babel-parser": + convertESM = false; + ignoreLib = false; + break; case "standalone": convertESM = false; ignoreLib = false; + includeRuntime = true; break; case "production": // Config during builds before publish. @@ -41,6 +46,10 @@ module.exports = function(api) { } 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, + // and then mark actual modules as modules farther down. + sourceType: "script", comments: false, ignore: [ // These may not be strictly necessary with the newly-limited scope of @@ -84,7 +93,29 @@ module.exports = function(api) { convertESM ? "@babel/transform-modules-commonjs" : null, ].filter(Boolean), }, - ], + { + // The vast majority of our src files are modules, but we use + // unambiguous to keep things simple until we get around to renaming + // the modules to be more easily distinguished from CommonJS + test: [ + "packages/*/src", + "packages/*/test", + "codemods/*/src", + "codemods/*/test", + ], + sourceType: "unambiguous", + }, + { + // The runtime transform shouldn't process its own runtime or core-js. + exclude: [ + "packages/babel-runtime", + /[\\/]node_modules[\\/](?:@babel\/runtime|babel-runtime|core-js)[\\/]/, + ], + plugins: [includeRuntime ? "@babel/transform-runtime" : null].filter( + Boolean + ), + }, + ].filter(Boolean), }; // we need to do this as long as we do not test everything from source diff --git a/package.json b/package.json index c717e80c56..baf8672322 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "devDependencies": { "@babel/cli": "7.0.0-beta.52", "@babel/core": "7.0.0-beta.52", + "@babel/plugin-transform-runtime": "7.0.0-beta.52", "@babel/plugin-proposal-class-properties": "7.0.0-beta.52", "@babel/plugin-proposal-export-namespace-from": "7.0.0-beta.52", "@babel/plugin-proposal-numeric-separator": "7.0.0-beta.52", @@ -19,6 +20,7 @@ "@babel/preset-env": "7.0.0-beta.52", "@babel/preset-flow": "7.0.0-beta.52", "@babel/register": "7.0.0-beta.52", + "@babel/runtime": "7.0.0-beta.52", "babel-core": "^7.0.0-0", "babel-eslint": "^8.2.6", "babel-jest": "^23.4.0", diff --git a/yarn.lock b/yarn.lock index 2866cc42e3..c5eadd513f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -553,6 +553,13 @@ dependencies: regenerator-transform "^0.13.3" +"@babel/plugin-transform-runtime@7.0.0-beta.52": + version "7.0.0-beta.52" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-runtime/-/plugin-transform-runtime-7.0.0-beta.52.tgz#12c509000a6e3a8f7cc3cedd15a4dac0653e60a4" + dependencies: + "@babel/helper-module-imports" "7.0.0-beta.52" + "@babel/helper-plugin-utils" "7.0.0-beta.52" + "@babel/plugin-transform-shorthand-properties@7.0.0-beta.52": version "7.0.0-beta.52" resolved "https://registry.yarnpkg.com/@babel/plugin-transform-shorthand-properties/-/plugin-transform-shorthand-properties-7.0.0-beta.52.tgz#f3cd777643d66878842a1bad5b95b4cc0b5ecb97" @@ -657,6 +664,13 @@ pirates "^3.0.1" source-map-support "^0.4.2" +"@babel/runtime@7.0.0-beta.52": + version "7.0.0-beta.52" + resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.0.0-beta.52.tgz#3f3b42b82b92b4e1a283fc78df1bb2fd4ba8d0c7" + dependencies: + core-js "^2.5.7" + regenerator-runtime "^0.12.0" + "@babel/template@7.0.0-beta.40": version "7.0.0-beta.40" resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.0.0-beta.40.tgz#034988c6424eb5c3268fe6a608626de1f4410fc8" @@ -6965,6 +6979,10 @@ regenerator-runtime@^0.11.0: version "0.11.1" resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz#be05ad7f9bf7d22e056f9726cee5017fbf19e2e9" +regenerator-runtime@^0.12.0: + version "0.12.0" + resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.12.0.tgz#8052ac952d85b10f3425192cd0c53f45cf65c6cb" + regenerator-transform@^0.13.3: version "0.13.3" resolved "https://registry.yarnpkg.com/regenerator-transform/-/regenerator-transform-0.13.3.tgz#264bd9ff38a8ce24b06e0636496b2c856b57bcbb"