Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare @babel/core for asynchronicity #10507

Merged
merged 3 commits into from Jan 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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