Skip to content
Permalink
Browse files

Prepare @babel/core for asynchronicity (#10507)

* 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 282f81bd676d09c1d8c48b08a7254b961eb41bed
Showing with 1,357 additions and 642 deletions.
  1. +1 βˆ’0 Gulpfile.js
  2. +23 βˆ’5 babel.config.js
  3. +1 βˆ’0 lib/third-party-libs.js.flow
  4. +1 βˆ’0 packages/babel-core/package.json
  5. +253 βˆ’76 packages/babel-core/src/config/caching.js
  6. +84 βˆ’60 packages/babel-core/src/config/config-chain.js
  7. +7 βˆ’7 packages/babel-core/src/config/config-descriptors.js
  8. +100 βˆ’92 packages/babel-core/src/config/files/configuration.js
  9. +16 βˆ’9 packages/babel-core/src/config/files/index-browser.js
  10. +3 βˆ’2 packages/babel-core/src/config/files/package.js
  11. +16 βˆ’8 packages/babel-core/src/config/files/utils.js
  12. +111 βˆ’102 packages/babel-core/src/config/full.js
  13. +24 βˆ’6 packages/babel-core/src/config/index.js
  14. +20 βˆ’12 packages/babel-core/src/config/partial.js
  15. +11 βˆ’0 packages/babel-core/src/config/util.js
  16. +110 βˆ’0 packages/babel-core/src/gensync-utils/async.js
  17. +21 βˆ’0 packages/babel-core/src/gensync-utils/fs.js
  18. +9 βˆ’0 packages/babel-core/src/gensync-utils/resolve.js
  19. +8 βˆ’1 packages/babel-core/src/index.js
  20. +18 βˆ’49 packages/babel-core/src/parse.js
  21. +4 βˆ’2 packages/babel-core/src/parser/index.js
  22. +22 βˆ’47 packages/babel-core/src/transform-ast.js
  23. +24 βˆ’71 packages/babel-core/src/transform-file.js
  24. +18 βˆ’41 packages/babel-core/src/transform.js
  25. +1 βˆ’1 packages/babel-core/src/transformation/block-hoist-plugin.js
  26. +8 βˆ’23 packages/babel-core/src/transformation/index.js
  27. +4 βˆ’3 packages/babel-core/src/transformation/normalize-file.js
  28. +214 βˆ’0 packages/babel-core/test/async.js
  29. +78 βˆ’20 packages/babel-core/test/caching-api.js
  30. +3 βˆ’1 packages/babel-core/test/config-loading.js
  31. +12 βˆ’0 packages/babel-core/test/fixtures/async/config-cache/babel.config.js
  32. +9 βˆ’0 packages/babel-core/test/fixtures/async/config-cache/plugin.js
  33. +11 βˆ’0 packages/babel-core/test/fixtures/async/config-file-async-function/babel.config.js
  34. +9 βˆ’0 packages/babel-core/test/fixtures/async/config-file-async-function/plugin.js
  35. +5 βˆ’0 packages/babel-core/test/fixtures/async/config-file-promise/babel.config.js
  36. +9 βˆ’0 packages/babel-core/test/fixtures/async/config-file-promise/plugin.js
  37. +3 βˆ’0 packages/babel-core/test/fixtures/async/plugin-inherits/babel.config.js
  38. +10 βˆ’0 packages/babel-core/test/fixtures/async/plugin-inherits/plugin.js
  39. +13 βˆ’0 packages/babel-core/test/fixtures/async/plugin-inherits/plugin2.js
  40. +3 βˆ’0 packages/babel-core/test/fixtures/async/plugin-post/babel.config.js
  41. +15 βˆ’0 packages/babel-core/test/fixtures/async/plugin-post/plugin.js
  42. +3 βˆ’0 packages/babel-core/test/fixtures/async/plugin-pre/babel.config.js
  43. +15 βˆ’0 packages/babel-core/test/fixtures/async/plugin-pre/plugin.js
  44. +3 βˆ’0 packages/babel-core/test/fixtures/async/plugin/babel.config.js
  45. +13 βˆ’0 packages/babel-core/test/fixtures/async/plugin/plugin.js
  46. +11 βˆ’4 scripts/rollup-plugin-babel-source.js
@@ -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",
@@ -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
@@ -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.
@@ -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,
@@ -119,6 +133,10 @@ module.exports = function(api) {
test: unambiguousSources,
sourceType: "unambiguous",
},
includeRegeneratorRuntime && {
exclude: /regenerator-runtime/,
plugins: [["@babel/transform-runtime", transformRuntimeOptions]],
},
].filter(Boolean),
};

@@ -4,6 +4,7 @@

declare module "resolve" {
declare export default {
(string, {| basedir: string |}, (err: ?Error, res: string) => void): void;
sync: (string, {| basedir: string |}) => string;
};
}
@@ -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",

0 comments on commit 282f81b

Please sign in to comment.
You can’t perform that action at this time.