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 1, 2020
1 parent 26eb891 commit 86d107e
Show file tree
Hide file tree
Showing 46 changed files with 1,361 additions and 651 deletions.
6 changes: 5 additions & 1 deletion Gulpfile.js
Expand Up @@ -181,7 +181,11 @@ function buildRollup(packages) {
},
}),
rollupCommonJs({
include: [/node_modules/, "packages/babel-preset-env/data/**"],
include: [
/node_modules/,
"packages/babel-preset-env/data/**",
"packages/babel-runtime/regenerator/**",
],
namedExports: {
"babel-plugin-dynamic-import-node/utils.js": [
"createDynamicImportTransform",
Expand Down
36 changes: 23 additions & 13 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 @@ -28,7 +32,10 @@ module.exports = function(api) {
];

switch (env) {
// Configs used during bundling builds.
case "standalone":
includeRegeneratorRuntime = true;
// Configs used during bundling builds.
unambiguousSources.push("packages/babel-runtime/regenerator");
case "rollup":
convertESM = false;
ignoreLib = false;
Expand All @@ -38,18 +45,7 @@ module.exports = function(api) {
// todo: remove this after it is rewritten into ESM
"packages/babel-preset-env/data"
);
envOpts.targets = {
node: nodeVersion,
};
break;
case "standalone":
convertESM = false;
ignoreLib = false;
unambiguousSources.push(
"**/node_modules",
"packages/babel-preset-env/data"
);
// targets to browserslists: defaults
if (env === "rollup") envOpts.targets = { node: nodeVersion };
break;
case "production":
// Config during builds before publish.
Expand All @@ -70,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 @@ -127,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 @@ -48,6 +48,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 86d107e

Please sign in to comment.