Skip to content

Commit 3a85ddf

Browse files
Bring back deferred require() calls in core and cli (#14028)
1 parent 2a3b0b9 commit 3a85ddf

4 files changed

Lines changed: 23 additions & 17 deletions

File tree

babel.config.js

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ module.exports = function (api) {
7373
"eslint/*/test",
7474
];
7575

76+
const lazyRequireSources = [
77+
"./packages/babel-cli",
78+
"./packages/babel-core",
79+
"./packages/babel-preset-env/src/available-plugins.js",
80+
];
81+
7682
switch (env) {
7783
// Configs used during bundling builds.
7884
case "standalone":
@@ -191,20 +197,6 @@ module.exports = function (api) {
191197
test: ["packages/babel-generator"].map(normalize),
192198
plugins: ["babel-plugin-transform-charcodes"],
193199
},
194-
convertESM && {
195-
test: [
196-
"./packages/babel-cli",
197-
"./packages/babel-core",
198-
"./packages/babel-preset-env/src/available-plugins.js",
199-
].map(normalize),
200-
plugins: [
201-
// Explicitly use the lazy version of CommonJS modules.
202-
[
203-
"@babel/transform-modules-commonjs",
204-
{ importInterop: importInteropSrc, lazy: true },
205-
],
206-
],
207-
},
208200
convertESM && {
209201
test: ["./packages/babel-node/src"].map(normalize),
210202
// Used to conditionally import kexec
@@ -215,8 +207,19 @@ module.exports = function (api) {
215207
assumptions: sourceAssumptions,
216208
plugins: [transformNamedBabelTypesImportToDestructuring],
217209
},
210+
convertESM && {
211+
test: lazyRequireSources.map(normalize),
212+
plugins: [
213+
// Explicitly use the lazy version of CommonJS modules.
214+
[
215+
"@babel/transform-modules-commonjs",
216+
{ importInterop: importInteropSrc, lazy: true },
217+
],
218+
],
219+
},
218220
convertESM && {
219221
test: sources.map(normalize),
222+
exclude: lazyRequireSources.map(normalize),
220223
plugins: [
221224
[
222225
"@babel/transform-modules-commonjs",

packages/babel-plugin-bugfix-safari-id-destructuring-collision-in-function-expression/test/util.skip-bundled.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { parseSync, traverse } from "@babel/core";
21
import { shouldTransform } from "../lib/util.js";
2+
import babel from "@babel/core";
3+
const { parseSync, traverse } = babel;
34

45
function getPath(input, parserOpts = {}) {
56
let targetPath;

packages/babel-plugin-bugfix-v8-spread-parameters-in-optional-chaining/test/util.skip-bundled.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { parseSync, traverse } from "@babel/core";
21
import { shouldTransform } from "../lib/util.js";
2+
import babel from "@babel/core";
3+
const { parseSync, traverse } = babel;
34

45
function getPath(input, parserOpts = {}) {
56
let targetPath;

packages/babel-plugin-proposal-optional-chaining/test/util.skip-bundled.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { willPathCastToBoolean } from "../lib/util.js";
2-
import { parseSync, traverse } from "@babel/core";
2+
import babel from "@babel/core";
3+
const { parseSync, traverse } = babel;
34

45
function getPath(input, parserOpts) {
56
let targetPath;

0 commit comments

Comments
 (0)