Bring back deferred require() calls in core and cli (#14028)

This commit is contained in:
Nicolò Ribaudo 2021-12-06 21:33:33 +01:00 committed by GitHub
parent 2a3b0b9601
commit 3a85ddfb1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 17 deletions

View File

@ -73,6 +73,12 @@ module.exports = function (api) {
"eslint/*/test", "eslint/*/test",
]; ];
const lazyRequireSources = [
"./packages/babel-cli",
"./packages/babel-core",
"./packages/babel-preset-env/src/available-plugins.js",
];
switch (env) { switch (env) {
// Configs used during bundling builds. // Configs used during bundling builds.
case "standalone": case "standalone":
@ -191,20 +197,6 @@ module.exports = function (api) {
test: ["packages/babel-generator"].map(normalize), test: ["packages/babel-generator"].map(normalize),
plugins: ["babel-plugin-transform-charcodes"], plugins: ["babel-plugin-transform-charcodes"],
}, },
convertESM && {
test: [
"./packages/babel-cli",
"./packages/babel-core",
"./packages/babel-preset-env/src/available-plugins.js",
].map(normalize),
plugins: [
// Explicitly use the lazy version of CommonJS modules.
[
"@babel/transform-modules-commonjs",
{ importInterop: importInteropSrc, lazy: true },
],
],
},
convertESM && { convertESM && {
test: ["./packages/babel-node/src"].map(normalize), test: ["./packages/babel-node/src"].map(normalize),
// Used to conditionally import kexec // Used to conditionally import kexec
@ -215,8 +207,19 @@ module.exports = function (api) {
assumptions: sourceAssumptions, assumptions: sourceAssumptions,
plugins: [transformNamedBabelTypesImportToDestructuring], plugins: [transformNamedBabelTypesImportToDestructuring],
}, },
convertESM && {
test: lazyRequireSources.map(normalize),
plugins: [
// Explicitly use the lazy version of CommonJS modules.
[
"@babel/transform-modules-commonjs",
{ importInterop: importInteropSrc, lazy: true },
],
],
},
convertESM && { convertESM && {
test: sources.map(normalize), test: sources.map(normalize),
exclude: lazyRequireSources.map(normalize),
plugins: [ plugins: [
[ [
"@babel/transform-modules-commonjs", "@babel/transform-modules-commonjs",

View File

@ -1,5 +1,6 @@
import { parseSync, traverse } from "@babel/core";
import { shouldTransform } from "../lib/util.js"; import { shouldTransform } from "../lib/util.js";
import babel from "@babel/core";
const { parseSync, traverse } = babel;
function getPath(input, parserOpts = {}) { function getPath(input, parserOpts = {}) {
let targetPath; let targetPath;

View File

@ -1,5 +1,6 @@
import { parseSync, traverse } from "@babel/core";
import { shouldTransform } from "../lib/util.js"; import { shouldTransform } from "../lib/util.js";
import babel from "@babel/core";
const { parseSync, traverse } = babel;
function getPath(input, parserOpts = {}) { function getPath(input, parserOpts = {}) {
let targetPath; let targetPath;

View File

@ -1,5 +1,6 @@
import { willPathCastToBoolean } from "../lib/util.js"; import { willPathCastToBoolean } from "../lib/util.js";
import { parseSync, traverse } from "@babel/core"; import babel from "@babel/core";
const { parseSync, traverse } = babel;
function getPath(input, parserOpts) { function getPath(input, parserOpts) {
let targetPath; let targetPath;