@rollup/plugin-commonjs 28.0.5 → 28.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +33 -4
- package/dist/es/index.js +33 -4
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -11,7 +11,7 @@ var estreeWalker = require('estree-walker');
|
|
|
11
11
|
var MagicString = require('magic-string');
|
|
12
12
|
var isReference = require('is-reference');
|
|
13
13
|
|
|
14
|
-
var version = "28.0.
|
|
14
|
+
var version = "28.0.7";
|
|
15
15
|
var peerDependencies = {
|
|
16
16
|
rollup: "^2.68.0||^3.0.0||^4.0.0"
|
|
17
17
|
};
|
|
@@ -494,6 +494,19 @@ function getEsImportProxy(id, defaultIsModuleExports, moduleSideEffects) {
|
|
|
494
494
|
};
|
|
495
495
|
}
|
|
496
496
|
|
|
497
|
+
// For external Node built-ins required from wrapped CommonJS modules, we must not
|
|
498
|
+
// hoist an ESM import of the built-in (which would eagerly load it). Instead,
|
|
499
|
+
// expose a lazy `__require()` that resolves the built-in at runtime via
|
|
500
|
+
// `createRequire(import.meta.url)`.
|
|
501
|
+
function getExternalBuiltinRequireProxy(id) {
|
|
502
|
+
const stringifiedId = JSON.stringify(id);
|
|
503
|
+
return (
|
|
504
|
+
`import { createRequire } from 'node:module';\n` +
|
|
505
|
+
`const require = createRequire(import.meta.url);\n` +
|
|
506
|
+
`export function __require() { return require(${stringifiedId}); }`
|
|
507
|
+
);
|
|
508
|
+
}
|
|
509
|
+
|
|
497
510
|
/* eslint-disable no-param-reassign, no-undefined */
|
|
498
511
|
|
|
499
512
|
|
|
@@ -774,7 +787,7 @@ function getRequireResolver(extensions, detectCyclesAndConditional, currentlyRes
|
|
|
774
787
|
return (
|
|
775
788
|
(await getTypeForImportedModule(
|
|
776
789
|
(
|
|
777
|
-
await this.load(
|
|
790
|
+
await this.load(resolved)
|
|
778
791
|
).meta.commonjs.resolved,
|
|
779
792
|
this.load
|
|
780
793
|
)) !== IS_WRAPPED_COMMONJS
|
|
@@ -823,8 +836,21 @@ function getRequireResolver(extensions, detectCyclesAndConditional, currentlyRes
|
|
|
823
836
|
fullyAnalyzedModules[parentId] = true;
|
|
824
837
|
return requireTargets.map(({ id: dependencyId, allowProxy }, index) => {
|
|
825
838
|
// eslint-disable-next-line no-multi-assign
|
|
826
|
-
|
|
839
|
+
let isCommonJS = (parentMeta.isRequiredCommonJS[dependencyId] =
|
|
827
840
|
getTypeForFullyAnalyzedModule(dependencyId));
|
|
841
|
+
// Special-case external Node built-ins to be handled via a lazy __require
|
|
842
|
+
// helper instead of hoisted ESM imports when strict wrapping is used.
|
|
843
|
+
if (
|
|
844
|
+
parentMeta.initialCommonJSType === IS_WRAPPED_COMMONJS &&
|
|
845
|
+
!allowProxy &&
|
|
846
|
+
isWrappedId(dependencyId, EXTERNAL_SUFFIX)
|
|
847
|
+
) {
|
|
848
|
+
const actualId = unwrapId(dependencyId, EXTERNAL_SUFFIX);
|
|
849
|
+
const isNodeBuiltin = actualId.startsWith('node:');
|
|
850
|
+
if (isNodeBuiltin) {
|
|
851
|
+
isCommonJS = IS_WRAPPED_COMMONJS;
|
|
852
|
+
}
|
|
853
|
+
}
|
|
828
854
|
const isWrappedCommonJS = isCommonJS === IS_WRAPPED_COMMONJS;
|
|
829
855
|
fullyAnalyzedModules[dependencyId] = true;
|
|
830
856
|
return {
|
|
@@ -1814,7 +1840,7 @@ async function transformCommonjs(
|
|
|
1814
1840
|
}
|
|
1815
1841
|
return;
|
|
1816
1842
|
case 'ThisExpression':
|
|
1817
|
-
// rewrite top-level `this` as `
|
|
1843
|
+
// rewrite top-level `this` as `exportsName`
|
|
1818
1844
|
if (lexicalDepth === 0 && !classBodyDepth) {
|
|
1819
1845
|
uses.global = true;
|
|
1820
1846
|
if (!ignoreGlobal) {
|
|
@@ -2267,6 +2293,9 @@ function commonjs(options = {}) {
|
|
|
2267
2293
|
|
|
2268
2294
|
if (isWrappedId(id, EXTERNAL_SUFFIX)) {
|
|
2269
2295
|
const actualId = unwrapId(id, EXTERNAL_SUFFIX);
|
|
2296
|
+
if (actualId.startsWith('node:')) {
|
|
2297
|
+
return getExternalBuiltinRequireProxy(actualId);
|
|
2298
|
+
}
|
|
2270
2299
|
return getUnknownRequireProxy(
|
|
2271
2300
|
actualId,
|
|
2272
2301
|
isEsmExternal(actualId) ? getRequireReturnsDefault(actualId) : true
|
package/dist/es/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import { walk } from 'estree-walker';
|
|
|
7
7
|
import MagicString from 'magic-string';
|
|
8
8
|
import isReference from 'is-reference';
|
|
9
9
|
|
|
10
|
-
var version = "28.0.
|
|
10
|
+
var version = "28.0.7";
|
|
11
11
|
var peerDependencies = {
|
|
12
12
|
rollup: "^2.68.0||^3.0.0||^4.0.0"
|
|
13
13
|
};
|
|
@@ -490,6 +490,19 @@ function getEsImportProxy(id, defaultIsModuleExports, moduleSideEffects) {
|
|
|
490
490
|
};
|
|
491
491
|
}
|
|
492
492
|
|
|
493
|
+
// For external Node built-ins required from wrapped CommonJS modules, we must not
|
|
494
|
+
// hoist an ESM import of the built-in (which would eagerly load it). Instead,
|
|
495
|
+
// expose a lazy `__require()` that resolves the built-in at runtime via
|
|
496
|
+
// `createRequire(import.meta.url)`.
|
|
497
|
+
function getExternalBuiltinRequireProxy(id) {
|
|
498
|
+
const stringifiedId = JSON.stringify(id);
|
|
499
|
+
return (
|
|
500
|
+
`import { createRequire } from 'node:module';\n` +
|
|
501
|
+
`const require = createRequire(import.meta.url);\n` +
|
|
502
|
+
`export function __require() { return require(${stringifiedId}); }`
|
|
503
|
+
);
|
|
504
|
+
}
|
|
505
|
+
|
|
493
506
|
/* eslint-disable no-param-reassign, no-undefined */
|
|
494
507
|
|
|
495
508
|
|
|
@@ -770,7 +783,7 @@ function getRequireResolver(extensions, detectCyclesAndConditional, currentlyRes
|
|
|
770
783
|
return (
|
|
771
784
|
(await getTypeForImportedModule(
|
|
772
785
|
(
|
|
773
|
-
await this.load(
|
|
786
|
+
await this.load(resolved)
|
|
774
787
|
).meta.commonjs.resolved,
|
|
775
788
|
this.load
|
|
776
789
|
)) !== IS_WRAPPED_COMMONJS
|
|
@@ -819,8 +832,21 @@ function getRequireResolver(extensions, detectCyclesAndConditional, currentlyRes
|
|
|
819
832
|
fullyAnalyzedModules[parentId] = true;
|
|
820
833
|
return requireTargets.map(({ id: dependencyId, allowProxy }, index) => {
|
|
821
834
|
// eslint-disable-next-line no-multi-assign
|
|
822
|
-
|
|
835
|
+
let isCommonJS = (parentMeta.isRequiredCommonJS[dependencyId] =
|
|
823
836
|
getTypeForFullyAnalyzedModule(dependencyId));
|
|
837
|
+
// Special-case external Node built-ins to be handled via a lazy __require
|
|
838
|
+
// helper instead of hoisted ESM imports when strict wrapping is used.
|
|
839
|
+
if (
|
|
840
|
+
parentMeta.initialCommonJSType === IS_WRAPPED_COMMONJS &&
|
|
841
|
+
!allowProxy &&
|
|
842
|
+
isWrappedId(dependencyId, EXTERNAL_SUFFIX)
|
|
843
|
+
) {
|
|
844
|
+
const actualId = unwrapId(dependencyId, EXTERNAL_SUFFIX);
|
|
845
|
+
const isNodeBuiltin = actualId.startsWith('node:');
|
|
846
|
+
if (isNodeBuiltin) {
|
|
847
|
+
isCommonJS = IS_WRAPPED_COMMONJS;
|
|
848
|
+
}
|
|
849
|
+
}
|
|
824
850
|
const isWrappedCommonJS = isCommonJS === IS_WRAPPED_COMMONJS;
|
|
825
851
|
fullyAnalyzedModules[dependencyId] = true;
|
|
826
852
|
return {
|
|
@@ -1810,7 +1836,7 @@ async function transformCommonjs(
|
|
|
1810
1836
|
}
|
|
1811
1837
|
return;
|
|
1812
1838
|
case 'ThisExpression':
|
|
1813
|
-
// rewrite top-level `this` as `
|
|
1839
|
+
// rewrite top-level `this` as `exportsName`
|
|
1814
1840
|
if (lexicalDepth === 0 && !classBodyDepth) {
|
|
1815
1841
|
uses.global = true;
|
|
1816
1842
|
if (!ignoreGlobal) {
|
|
@@ -2263,6 +2289,9 @@ function commonjs(options = {}) {
|
|
|
2263
2289
|
|
|
2264
2290
|
if (isWrappedId(id, EXTERNAL_SUFFIX)) {
|
|
2265
2291
|
const actualId = unwrapId(id, EXTERNAL_SUFFIX);
|
|
2292
|
+
if (actualId.startsWith('node:')) {
|
|
2293
|
+
return getExternalBuiltinRequireProxy(actualId);
|
|
2294
|
+
}
|
|
2266
2295
|
return getUnknownRequireProxy(
|
|
2267
2296
|
actualId,
|
|
2268
2297
|
isEsmExternal(actualId) ? getRequireReturnsDefault(actualId) : true
|