Skip to content

Commit

Permalink
Prepare @babel/core for asynchronicity (#10507)
Browse files Browse the repository at this point in the history
* Prepare @babel/core for asynchronicity

* Include regenerator-runtime in standalone build

* Fix rollup build
  • Loading branch information
nicolo-ribaudo committed Jan 10, 2020
1 parent 9fec528 commit 282f81b
Show file tree
Hide file tree
Showing 46 changed files with 1,357 additions and 642 deletions.
1 change: 1 addition & 0 deletions Gulpfile.js
Expand Up @@ -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",
Expand Down
28 changes: 23 additions & 5 deletions babel.config.js
Expand Up @@ -14,6 +14,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
Expand All @@ -29,19 +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;
// 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.
Expand All @@ -62,6 +66,16 @@ 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,
};
}

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,
Expand Down Expand Up @@ -119,6 +133,10 @@ module.exports = function(api) {
test: unambiguousSources,
sourceType: "unambiguous",
},
includeRegeneratorRuntime && {
exclude: /regenerator-runtime/,
plugins: [["@babel/transform-runtime", transformRuntimeOptions]],
},
].filter(Boolean),
};

Expand Down
1 change: 1 addition & 0 deletions lib/third-party-libs.js.flow
Expand Up @@ -4,6 +4,7 @@

declare module "resolve" {
declare export default {
(string, {| basedir: string |}, (err: ?Error, res: string) => void): void;
sync: (string, {| basedir: string |}) => string;
};
}
Expand Down
1 change: 1 addition & 0 deletions packages/babel-core/package.json
Expand Up @@ -49,6 +49,7 @@
"@babel/types": "^7.7.4",
"convert-source-map": "^1.7.0",
"debug": "^4.1.0",
"gensync": "^1.0.0-beta.1",
"json5": "^2.1.0",
"lodash": "^4.17.13",
"resolve": "^1.3.2",
Expand Down

0 comments on commit 282f81b

Please sign in to comment.