Skip to content

Commit

Permalink
add @babel/compat-data sub exports to external
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Jan 24, 2022
1 parent 8f946da commit 077018c
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions Gulpfile.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ if (process.env.CIRCLE_PR_NUMBER) {

const babelVersion =
require("./packages/babel-core/package.json").version + versionSuffix;
function buildRollup(packages, targetBrowsers) {
function buildRollup(packages, buildStandalone) {
const sourcemap = process.env.NODE_ENV === "production";
return Promise.all(
packages.map(
Expand All @@ -298,6 +298,12 @@ function buildRollup(packages, targetBrowsers) {
const external = [
...Object.keys(dependencies),
...Object.keys(peerDependencies),
// @babel/compat-data sub exports
"@babel/compat-data/overlapping-plugins",
"@babel/compat-data/plugins",
"@babel/compat-data/plugin-bugfixes",
"@babel/compat-data/native-modules",
"@babel/compat-data/corejs2-built-ins",
// Ideally they should be constructed from package.json exports
// required by modules-commonjs
"babel-plugin-dynamic-import-node/utils",
Expand All @@ -314,6 +320,8 @@ function buildRollup(packages, targetBrowsers) {
const bundle = await rollup({
input,
external,
// all node modules are resolved as if they were placed in the n_m folder of package root
preserveSymlinks: true,
onwarn(warning, warn) {
if (warning.code === "CIRCULAR_DEPENDENCY") return;
if (warning.code === "UNUSED_EXTERNAL_IMPORT") {
Expand Down Expand Up @@ -357,15 +365,16 @@ function buildRollup(packages, targetBrowsers) {
}),
rollupCommonJs({
include: [
/node_modules/,
// Only bundle node modules when building standalone
buildStandalone ? /node_modules/ : "./node_modules/*/*.js",
"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",
"packages/*/src/**/*.cjs",
// See the comment in this file for the reason to include it
"packages/babel-standalone/src/dynamic-require-entrypoint.cjs",
],
].filter(Boolean),
dynamicRequireTargets: [
// https://github.com/mathiasbynens/regexpu-core/blob/ffd8fff2e31f4597f6fdfee75d5ac1c5c8111ec3/rewrite-pattern.js#L48
resolveChain(
Expand All @@ -389,14 +398,14 @@ function buildRollup(packages, targetBrowsers) {
}),
rollupNodeResolve({
extensions: [".ts", ".js", ".mjs", ".cjs", ".json"],
browser: targetBrowsers,
exportConditions: targetBrowsers ? ["browser"] : [],
browser: buildStandalone,
exportConditions: buildStandalone ? ["browser"] : [],
// It needs to be set to 'false' when using rollupNodePolyfills
// https://github.com/rollup/plugins/issues/772
preferBuiltins: !targetBrowsers,
preferBuiltins: !buildStandalone,
}),
rollupJson(),
targetBrowsers &&
buildStandalone &&
rollupNodePolyfills({
sourceMap: sourcemap,
include: "**/*.{js,cjs,ts}",
Expand Down Expand Up @@ -438,7 +447,7 @@ function buildRollup(packages, targetBrowsers) {
});

// Only minify @babel/standalone
if (src !== "packages/babel-standalone") {
if (!buildStandalone) {
return;
}

Expand Down Expand Up @@ -572,7 +581,7 @@ function* libBundlesIterator() {
}

let libBundles;
if (process.env.BABEL_8_BREAKING) {
if (process.env.B_ALL) {
libBundles = [...libBundlesIterator()];
} else {
libBundles = [
Expand Down

0 comments on commit 077018c

Please sign in to comment.