Skip to content

Commit

Permalink
Bring back deferred require() calls in core and cli (#14028)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Dec 6, 2021
1 parent 2a3b0b9 commit 3a85ddf
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
31 changes: 17 additions & 14 deletions babel.config.js
Expand Up @@ -73,6 +73,12 @@ module.exports = function (api) {
"eslint/*/test",
];

const lazyRequireSources = [
"./packages/babel-cli",
"./packages/babel-core",
"./packages/babel-preset-env/src/available-plugins.js",
];

switch (env) {
// Configs used during bundling builds.
case "standalone":
Expand Down Expand Up @@ -191,20 +197,6 @@ module.exports = function (api) {
test: ["packages/babel-generator"].map(normalize),
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 && {
test: ["./packages/babel-node/src"].map(normalize),
// Used to conditionally import kexec
Expand All @@ -215,8 +207,19 @@ module.exports = function (api) {
assumptions: sourceAssumptions,
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 && {
test: sources.map(normalize),
exclude: lazyRequireSources.map(normalize),
plugins: [
[
"@babel/transform-modules-commonjs",
Expand Down
@@ -1,5 +1,6 @@
import { parseSync, traverse } from "@babel/core";
import { shouldTransform } from "../lib/util.js";
import babel from "@babel/core";
const { parseSync, traverse } = babel;

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

function getPath(input, parserOpts = {}) {
let targetPath;
Expand Down
@@ -1,5 +1,6 @@
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) {
let targetPath;
Expand Down

0 comments on commit 3a85ddf

Please sign in to comment.