@rollup/plugin-commonjs 22.0.0-3 → 22.0.0-4
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/index.es.js +67 -47
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +67 -47
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -16,9 +16,9 @@ var glob__default = /*#__PURE__*/_interopDefaultLegacy(glob);
|
|
|
16
16
|
var MagicString__default = /*#__PURE__*/_interopDefaultLegacy(MagicString);
|
|
17
17
|
var isReference__default = /*#__PURE__*/_interopDefaultLegacy(isReference);
|
|
18
18
|
|
|
19
|
-
var version = "
|
|
19
|
+
var version = "22.0.0-4";
|
|
20
20
|
var peerDependencies = {
|
|
21
|
-
rollup: "^2.
|
|
21
|
+
rollup: "^2.61.1"
|
|
22
22
|
};
|
|
23
23
|
|
|
24
24
|
function tryParse(parse, code, id) {
|
|
@@ -203,6 +203,9 @@ function getDynamicRequireModules(patterns, dynamicRequireRoot) {
|
|
|
203
203
|
|
|
204
204
|
const FAILED_REQUIRE_ERROR = `throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');`;
|
|
205
205
|
|
|
206
|
+
const COMMONJS_REQUIRE_EXPORT = 'commonjsRequire';
|
|
207
|
+
const CREATE_COMMONJS_REQUIRE_EXPORT = 'createCommonjsRequire';
|
|
208
|
+
|
|
206
209
|
function getDynamicModuleRegistry(
|
|
207
210
|
isDynamicRequireModulesEnabled,
|
|
208
211
|
dynamicRequireModules,
|
|
@@ -210,7 +213,7 @@ function getDynamicModuleRegistry(
|
|
|
210
213
|
ignoreDynamicRequires
|
|
211
214
|
) {
|
|
212
215
|
if (!isDynamicRequireModulesEnabled) {
|
|
213
|
-
return `export function
|
|
216
|
+
return `export function ${COMMONJS_REQUIRE_EXPORT}(path) {
|
|
214
217
|
${FAILED_REQUIRE_ERROR}
|
|
215
218
|
}`;
|
|
216
219
|
}
|
|
@@ -240,25 +243,25 @@ ${dynamicModuleProps}
|
|
|
240
243
|
});
|
|
241
244
|
}
|
|
242
245
|
|
|
243
|
-
export function
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
246
|
+
export function ${CREATE_COMMONJS_REQUIRE_EXPORT}(originalModuleDir) {
|
|
247
|
+
function handleRequire(path) {
|
|
248
|
+
var resolvedPath = commonjsResolve(path, originalModuleDir);
|
|
249
|
+
if (resolvedPath !== null) {
|
|
250
|
+
return getDynamicModules()[resolvedPath]();
|
|
251
|
+
}
|
|
252
|
+
${ignoreDynamicRequires ? 'return require(path);' : FAILED_REQUIRE_ERROR}
|
|
247
253
|
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
return resolvedPath;
|
|
254
|
+
handleRequire.resolve = function (path) {
|
|
255
|
+
var resolvedPath = commonjsResolve(path, originalModuleDir);
|
|
256
|
+
if (resolvedPath !== null) {
|
|
257
|
+
return resolvedPath;
|
|
258
|
+
}
|
|
259
|
+
return require.resolve(path);
|
|
255
260
|
}
|
|
256
|
-
return
|
|
261
|
+
return handleRequire;
|
|
257
262
|
}
|
|
258
263
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
function commonjsResolveImpl (path, originalModuleDir) {
|
|
264
|
+
function commonjsResolve (path, originalModuleDir) {
|
|
262
265
|
var shouldTryNodeModules = isPossibleNodeModulesPath(path);
|
|
263
266
|
path = normalize(path);
|
|
264
267
|
var relPath;
|
|
@@ -670,23 +673,33 @@ function getResolveRequireSourcesAndGetMeta(extensions, detectCyclesAndCondition
|
|
|
670
673
|
};
|
|
671
674
|
}
|
|
672
675
|
|
|
673
|
-
function
|
|
674
|
-
const
|
|
675
|
-
const versionRegexp = /\^(\d+\.\d+)\.\d+/g;
|
|
676
|
+
function validateVersion(actualVersion, peerDependencyVersion, name) {
|
|
677
|
+
const versionRegexp = /\^(\d+\.\d+\.\d+)/g;
|
|
676
678
|
let minMajor = Infinity;
|
|
677
679
|
let minMinor = Infinity;
|
|
680
|
+
let minPatch = Infinity;
|
|
678
681
|
let foundVersion;
|
|
679
682
|
// eslint-disable-next-line no-cond-assign
|
|
680
683
|
while ((foundVersion = versionRegexp.exec(peerDependencyVersion))) {
|
|
681
|
-
const [foundMajor, foundMinor] = foundVersion[1].split('.').map(Number);
|
|
684
|
+
const [foundMajor, foundMinor, foundPatch] = foundVersion[1].split('.').map(Number);
|
|
682
685
|
if (foundMajor < minMajor) {
|
|
683
686
|
minMajor = foundMajor;
|
|
684
687
|
minMinor = foundMinor;
|
|
688
|
+
minPatch = foundPatch;
|
|
685
689
|
}
|
|
686
690
|
}
|
|
687
|
-
if (
|
|
691
|
+
if (!actualVersion) {
|
|
692
|
+
throw new Error(
|
|
693
|
+
`Insufficient ${name} version: "@rollup/plugin-commonjs" requires at least ${name}@${minMajor}.${minMinor}.${minPatch}.`
|
|
694
|
+
);
|
|
695
|
+
}
|
|
696
|
+
const [major, minor, patch] = actualVersion.split('.').map(Number);
|
|
697
|
+
if (
|
|
698
|
+
major < minMajor ||
|
|
699
|
+
(major === minMajor && (minor < minMinor || (minor === minMinor && patch < minPatch)))
|
|
700
|
+
) {
|
|
688
701
|
throw new Error(
|
|
689
|
-
`Insufficient
|
|
702
|
+
`Insufficient ${name} version: "@rollup/plugin-commonjs" requires at least ${name}@${minMajor}.${minMinor}.${minPatch} but found ${name}@${actualVersion}.`
|
|
690
703
|
);
|
|
691
704
|
}
|
|
692
705
|
}
|
|
@@ -1132,14 +1145,16 @@ function getRequireHandlers() {
|
|
|
1132
1145
|
resolveRequireSourcesAndGetMeta,
|
|
1133
1146
|
needsRequireWrapper,
|
|
1134
1147
|
isEsModule,
|
|
1135
|
-
|
|
1148
|
+
isDynamicRequireModulesEnabled,
|
|
1136
1149
|
getIgnoreTryCatchRequireStatementMode
|
|
1137
1150
|
) {
|
|
1138
1151
|
const imports = [];
|
|
1139
1152
|
imports.push(`import * as ${helpersName} from "${HELPERS_ID}";`);
|
|
1140
|
-
if (
|
|
1153
|
+
if (dynamicRequireName) {
|
|
1141
1154
|
imports.push(
|
|
1142
|
-
`import {
|
|
1155
|
+
`import { ${
|
|
1156
|
+
isDynamicRequireModulesEnabled ? CREATE_COMMONJS_REQUIRE_EXPORT : COMMONJS_REQUIRE_EXPORT
|
|
1157
|
+
} as ${dynamicRequireName} } from "${DYNAMIC_MODULES_ID}";`
|
|
1143
1158
|
);
|
|
1144
1159
|
}
|
|
1145
1160
|
if (exportMode === 'module') {
|
|
@@ -1428,12 +1443,6 @@ async function transformCommonjs(
|
|
|
1428
1443
|
checkDynamicRequire(node.start);
|
|
1429
1444
|
uses.require = true;
|
|
1430
1445
|
const requireNode = node.callee.object;
|
|
1431
|
-
magicString.appendLeft(
|
|
1432
|
-
node.end - 1,
|
|
1433
|
-
`,${JSON.stringify(
|
|
1434
|
-
path.dirname(id) === '.' ? null /* default behavior */ : virtualDynamicRequirePath
|
|
1435
|
-
)}`
|
|
1436
|
-
);
|
|
1437
1446
|
replacedDynamicRequires.push(requireNode);
|
|
1438
1447
|
return;
|
|
1439
1448
|
}
|
|
@@ -1448,12 +1457,6 @@ async function transformCommonjs(
|
|
|
1448
1457
|
if (hasDynamicArguments(node)) {
|
|
1449
1458
|
if (isDynamicRequireModulesEnabled) {
|
|
1450
1459
|
checkDynamicRequire(node.start);
|
|
1451
|
-
magicString.appendLeft(
|
|
1452
|
-
node.end - 1,
|
|
1453
|
-
`, ${JSON.stringify(
|
|
1454
|
-
path.dirname(id) === '.' ? null /* default behavior */ : virtualDynamicRequirePath
|
|
1455
|
-
)}`
|
|
1456
|
-
);
|
|
1457
1460
|
}
|
|
1458
1461
|
if (!ignoreDynamicRequires) {
|
|
1459
1462
|
replacedDynamicRequires.push(node.callee);
|
|
@@ -1627,7 +1630,13 @@ async function transformCommonjs(
|
|
|
1627
1630
|
const requireName = deconflict([scope], globals, `require${capitalize(nameBase)}`);
|
|
1628
1631
|
const isRequiredName = deconflict([scope], globals, `hasRequired${capitalize(nameBase)}`);
|
|
1629
1632
|
const helpersName = deconflict([scope], globals, 'commonjsHelpers');
|
|
1630
|
-
const dynamicRequireName =
|
|
1633
|
+
const dynamicRequireName =
|
|
1634
|
+
replacedDynamicRequires.length > 0 &&
|
|
1635
|
+
deconflict(
|
|
1636
|
+
[scope],
|
|
1637
|
+
globals,
|
|
1638
|
+
isDynamicRequireModulesEnabled ? CREATE_COMMONJS_REQUIRE_EXPORT : COMMONJS_REQUIRE_EXPORT
|
|
1639
|
+
);
|
|
1631
1640
|
const deconflictedExportNames = Object.create(null);
|
|
1632
1641
|
for (const [exportName, { scopes }] of exportsAssignmentsByName) {
|
|
1633
1642
|
deconflictedExportNames[exportName] = deconflict([...scopes], globals, exportName);
|
|
@@ -1639,10 +1648,17 @@ async function transformCommonjs(
|
|
|
1639
1648
|
});
|
|
1640
1649
|
}
|
|
1641
1650
|
for (const node of replacedDynamicRequires) {
|
|
1642
|
-
magicString.overwrite(
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1651
|
+
magicString.overwrite(
|
|
1652
|
+
node.start,
|
|
1653
|
+
node.end,
|
|
1654
|
+
isDynamicRequireModulesEnabled
|
|
1655
|
+
? `${dynamicRequireName}(${JSON.stringify(virtualDynamicRequirePath)})`
|
|
1656
|
+
: dynamicRequireName,
|
|
1657
|
+
{
|
|
1658
|
+
contentOnly: true,
|
|
1659
|
+
storeName: true
|
|
1660
|
+
}
|
|
1661
|
+
);
|
|
1646
1662
|
}
|
|
1647
1663
|
|
|
1648
1664
|
// We cannot wrap ES/mixed modules
|
|
@@ -1697,7 +1713,7 @@ async function transformCommonjs(
|
|
|
1697
1713
|
resolveRequireSourcesAndGetMeta,
|
|
1698
1714
|
needsRequireWrapper,
|
|
1699
1715
|
isEsModule,
|
|
1700
|
-
|
|
1716
|
+
isDynamicRequireModulesEnabled,
|
|
1701
1717
|
getIgnoreTryCatchRequireStatementMode
|
|
1702
1718
|
);
|
|
1703
1719
|
const exportBlock = isEsModule
|
|
@@ -1916,8 +1932,12 @@ function commonjs(options = {}) {
|
|
|
1916
1932
|
return { ...rawOptions, plugins };
|
|
1917
1933
|
},
|
|
1918
1934
|
|
|
1919
|
-
buildStart() {
|
|
1920
|
-
|
|
1935
|
+
buildStart({ plugins }) {
|
|
1936
|
+
validateVersion(this.meta.rollupVersion, peerDependencies.rollup, 'rollup');
|
|
1937
|
+
const nodeResolve = plugins.find(({ name }) => name === 'node-resolve');
|
|
1938
|
+
if (nodeResolve) {
|
|
1939
|
+
validateVersion(nodeResolve.version, '^13.0.6', '@rollup/plugin-node-resolve');
|
|
1940
|
+
}
|
|
1921
1941
|
if (options.namedExports != null) {
|
|
1922
1942
|
this.warn(
|
|
1923
1943
|
'The namedExports option from "@rollup/plugin-commonjs" is deprecated. Named exports are now handled automatically.'
|