Make sure that Rollup's dynamicRequireTargets are included (#12839)
* Make sure that Rollup's `dynamicRequireTargets` are included * Update packages/babel-standalone/src/dynamic-require-entrypoint.cjs Co-authored-by: Brian Ng <bng412@gmail.com>
This commit is contained in:
parent
507ad63140
commit
8e7a164490
15
.yarn/patches/@rollup__plugin-commonjs.patch
Normal file
15
.yarn/patches/@rollup__plugin-commonjs.patch
Normal file
@ -0,0 +1,15 @@
|
||||
See packages/babel-standalone/src/dynamic-require-entrypoint.cjs for the reason for this diff.
|
||||
|
||||
diff --git a/dist/index.js b/dist/index.js
|
||||
index 712f6a7d81b115d468a764b4139caa00d6cfc358..73fbf004217f3d44b6420d3082a0846b53e00f4c 100644
|
||||
--- a/dist/index.js
|
||||
+++ b/dist/index.js
|
||||
@@ -1626,7 +1626,7 @@ function commonjs(options = {}) {
|
||||
const sourceMap = options.sourceMap !== false;
|
||||
|
||||
function transformAndCheckExports(code, id) {
|
||||
- if (isDynamicRequireModulesEnabled && this.getModuleInfo(id).isEntry) {
|
||||
+ if (isDynamicRequireModulesEnabled && (this.getModuleInfo(id).isEntry || id.endsWith("/dynamic-require-entrypoint.cjs"))) {
|
||||
code =
|
||||
getDynamicPackagesEntryIntro(dynamicRequireModuleDirPaths, dynamicRequireModuleSet) + code;
|
||||
}
|
||||
@ -245,8 +245,8 @@ function resolveChain(baseUrl, ...packages) {
|
||||
|
||||
return packages.reduce(
|
||||
(base, pkg) =>
|
||||
require.resolve(pkg + "/package.json", { paths: [path.dirname(base)] }),
|
||||
fileURLToPath(baseUrl)
|
||||
path.dirname(require.resolve(pkg + "/package.json", { paths: [base] })),
|
||||
path.dirname(fileURLToPath(baseUrl))
|
||||
);
|
||||
}
|
||||
|
||||
@ -304,6 +304,8 @@ function buildRollup(packages, targetBrowsers) {
|
||||
// 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",
|
||||
],
|
||||
dynamicRequireTargets: [
|
||||
// https://github.com/mathiasbynens/regexpu-core/blob/ffd8fff2e31f4597f6fdfee75d5ac1c5c8111ec3/rewrite-pattern.js#L48
|
||||
@ -312,7 +314,7 @@ function buildRollup(packages, targetBrowsers) {
|
||||
"./packages/babel-helper-create-regexp-features-plugin",
|
||||
"regexpu-core",
|
||||
"regenerate-unicode-properties"
|
||||
) + "/../**",
|
||||
) + "/**/*.js",
|
||||
],
|
||||
}),
|
||||
rollupBabel({
|
||||
|
||||
@ -32,7 +32,7 @@
|
||||
"@babel/register": "^7.12.0",
|
||||
"@babel/runtime": "^7.12.0",
|
||||
"@rollup/plugin-babel": "^5.2.0",
|
||||
"@rollup/plugin-commonjs": "^17.1.0",
|
||||
"@rollup/plugin-commonjs": "patch:@rollup/plugin-commonjs@^17.1.0#./.yarn/patches/@rollup__plugin-commonjs.patch",
|
||||
"@rollup/plugin-json": "^4.1.0",
|
||||
"@rollup/plugin-node-resolve": "^9.0.0",
|
||||
"@rollup/plugin-replace": "^2.3.3",
|
||||
|
||||
13
packages/babel-standalone/src/dynamic-require-entrypoint.cjs
Normal file
13
packages/babel-standalone/src/dynamic-require-entrypoint.cjs
Normal file
@ -0,0 +1,13 @@
|
||||
/*
|
||||
We bundle @babel/standalone using the dynamicRequireTargets option.
|
||||
This option needs to inject require() calls to all the modules that
|
||||
could be dynamically required later.
|
||||
|
||||
By default it injects them in the entrypoint, but when rollup loads the
|
||||
entrypoint it finds syntax that it doesn't support (because
|
||||
@rollup/plugin-commonjs must run before @rollup/plugin-babel).
|
||||
|
||||
We use "yarn patch" to modify the @rollup/plugin-commonjs package, so
|
||||
that it injects those "preload" require() calls in this file rather
|
||||
than in the entrypoint.
|
||||
*/
|
||||
@ -10,6 +10,9 @@
|
||||
/* global VERSION */
|
||||
/* eslint-disable max-len */
|
||||
|
||||
// $FlowIgnore
|
||||
import "./dynamic-require-entrypoint.cjs";
|
||||
|
||||
import {
|
||||
transformFromAst as babelTransformFromAst,
|
||||
transform as babelTransform,
|
||||
|
||||
21
yarn.lock
21
yarn.lock
@ -3729,7 +3729,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@rollup/plugin-commonjs@npm:^17.1.0":
|
||||
"@rollup/plugin-commonjs@^17.1.0":
|
||||
version: 17.1.0
|
||||
resolution: "@rollup/plugin-commonjs@npm:17.1.0"
|
||||
dependencies:
|
||||
@ -3746,6 +3746,23 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@rollup/plugin-commonjs@patch:@rollup/plugin-commonjs@^17.1.0#./.yarn/patches/@rollup__plugin-commonjs.patch::locator=babel%40workspace%3A.":
|
||||
version: 17.1.0
|
||||
resolution: "@rollup/plugin-commonjs@patch:@rollup/plugin-commonjs@npm%3A17.1.0#./.yarn/patches/@rollup__plugin-commonjs.patch::version=17.1.0&hash=a0d076&locator=babel%40workspace%3A."
|
||||
dependencies:
|
||||
"@rollup/pluginutils": ^3.1.0
|
||||
commondir: ^1.0.1
|
||||
estree-walker: ^2.0.1
|
||||
glob: ^7.1.6
|
||||
is-reference: ^1.2.1
|
||||
magic-string: ^0.25.7
|
||||
resolve: ^1.17.0
|
||||
peerDependencies:
|
||||
rollup: ^2.30.0
|
||||
checksum: ccf44f300b5b7b9fcc72e22c414bd86ce461e412a0980fb2f73d6d2b562466409ecaae270a54028c4584650c7d1a0718a6af0d15c5a5b41d6cd20a2159ba34fb
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@rollup/plugin-json@npm:^4.1.0":
|
||||
version: 4.1.0
|
||||
resolution: "@rollup/plugin-json@npm:4.1.0"
|
||||
@ -4883,7 +4900,7 @@ __metadata:
|
||||
"@babel/register": ^7.12.0
|
||||
"@babel/runtime": ^7.12.0
|
||||
"@rollup/plugin-babel": ^5.2.0
|
||||
"@rollup/plugin-commonjs": ^17.1.0
|
||||
"@rollup/plugin-commonjs": "patch:@rollup/plugin-commonjs@^17.1.0#./.yarn/patches/@rollup__plugin-commonjs.patch"
|
||||
"@rollup/plugin-json": ^4.1.0
|
||||
"@rollup/plugin-node-resolve": ^9.0.0
|
||||
"@rollup/plugin-replace": ^2.3.3
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user