@rollup/plugin-commonjs 18.0.0 → 18.1.0
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/CHANGELOG.md +12 -0
- package/README.md +43 -0
- package/dist/index.es.js +42 -25
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +42 -25
- package/dist/index.js.map +1 -1
- package/package.json +6 -7
package/dist/index.js
CHANGED
|
@@ -460,9 +460,7 @@ function getDynamicRequirePaths(patterns) {
|
|
|
460
460
|
return { dynamicRequireModuleSet, dynamicRequireModuleDirPaths };
|
|
461
461
|
}
|
|
462
462
|
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
function getIsCjsPromise(id) {
|
|
463
|
+
function getIsCjsPromise(isCjsPromises, id) {
|
|
466
464
|
let isCjsPromise = isCjsPromises.get(id);
|
|
467
465
|
if (isCjsPromise) return isCjsPromise.promise;
|
|
468
466
|
|
|
@@ -478,7 +476,7 @@ function getIsCjsPromise(id) {
|
|
|
478
476
|
return promise;
|
|
479
477
|
}
|
|
480
478
|
|
|
481
|
-
function setIsCjsPromise(id, resolution) {
|
|
479
|
+
function setIsCjsPromise(isCjsPromises, id, resolution) {
|
|
482
480
|
const isCjsPromise = isCjsPromises.get(id);
|
|
483
481
|
if (isCjsPromise) {
|
|
484
482
|
if (isCjsPromise.resolve) {
|
|
@@ -532,10 +530,11 @@ async function getStaticRequireProxy(
|
|
|
532
530
|
id,
|
|
533
531
|
requireReturnsDefault,
|
|
534
532
|
esModulesWithDefaultExport,
|
|
535
|
-
esModulesWithNamedExports
|
|
533
|
+
esModulesWithNamedExports,
|
|
534
|
+
isCjsPromises
|
|
536
535
|
) {
|
|
537
536
|
const name = getName(id);
|
|
538
|
-
const isCjs = await getIsCjsPromise(id);
|
|
537
|
+
const isCjs = await getIsCjsPromise(isCjsPromises, id);
|
|
539
538
|
if (isCjs) {
|
|
540
539
|
return `import { __moduleExports } from ${JSON.stringify(id)}; export default __moduleExports;`;
|
|
541
540
|
} else if (isCjs === null) {
|
|
@@ -809,7 +808,8 @@ function rewriteExportsAndGetExportsBlock(
|
|
|
809
808
|
isRestorableCompiledEsm,
|
|
810
809
|
code,
|
|
811
810
|
uses,
|
|
812
|
-
HELPERS_NAME
|
|
811
|
+
HELPERS_NAME,
|
|
812
|
+
defaultIsModuleExports
|
|
813
813
|
) {
|
|
814
814
|
const namedExportDeclarations = [`export { ${moduleName} as __moduleExports };`];
|
|
815
815
|
const moduleExportsPropertyAssignments = [];
|
|
@@ -864,19 +864,29 @@ function rewriteExportsAndGetExportsBlock(
|
|
|
864
864
|
|
|
865
865
|
// Generate default export
|
|
866
866
|
const defaultExport = [];
|
|
867
|
-
if (
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
867
|
+
if (defaultIsModuleExports === 'auto') {
|
|
868
|
+
if (isRestorableCompiledEsm) {
|
|
869
|
+
defaultExport.push(`export default ${deconflictedDefaultExportName || moduleName};`);
|
|
870
|
+
} else if (
|
|
871
|
+
(wrapped || deconflictedDefaultExportName) &&
|
|
872
|
+
(defineCompiledEsmExpressions.length > 0 || code.includes('__esModule'))
|
|
873
|
+
) {
|
|
874
|
+
// eslint-disable-next-line no-param-reassign
|
|
875
|
+
uses.commonjsHelpers = true;
|
|
876
|
+
defaultExport.push(
|
|
877
|
+
`export default /*@__PURE__*/${HELPERS_NAME}.getDefaultExportFromCjs(${moduleName});`
|
|
878
|
+
);
|
|
879
|
+
} else {
|
|
880
|
+
defaultExport.push(`export default ${moduleName};`);
|
|
881
|
+
}
|
|
882
|
+
} else if (defaultIsModuleExports === true) {
|
|
879
883
|
defaultExport.push(`export default ${moduleName};`);
|
|
884
|
+
} else if (defaultIsModuleExports === false) {
|
|
885
|
+
if (deconflictedDefaultExportName) {
|
|
886
|
+
defaultExport.push(`export default ${deconflictedDefaultExportName};`);
|
|
887
|
+
} else {
|
|
888
|
+
defaultExport.push(`export default ${moduleName}.default;`);
|
|
889
|
+
}
|
|
880
890
|
}
|
|
881
891
|
|
|
882
892
|
return `\n\n${defaultExport
|
|
@@ -1131,7 +1141,8 @@ function transformCommonjs(
|
|
|
1131
1141
|
dynamicRequireModuleSet,
|
|
1132
1142
|
disableWrap,
|
|
1133
1143
|
commonDir,
|
|
1134
|
-
astCache
|
|
1144
|
+
astCache,
|
|
1145
|
+
defaultIsModuleExports
|
|
1135
1146
|
) {
|
|
1136
1147
|
const ast = astCache || tryParse(parse, code, id);
|
|
1137
1148
|
const magicString = new MagicString__default['default'](code);
|
|
@@ -1548,7 +1559,8 @@ function transformCommonjs(
|
|
|
1548
1559
|
isRestorableCompiledEsm,
|
|
1549
1560
|
code,
|
|
1550
1561
|
uses,
|
|
1551
|
-
HELPERS_NAME
|
|
1562
|
+
HELPERS_NAME,
|
|
1563
|
+
defaultIsModuleExports
|
|
1552
1564
|
);
|
|
1553
1565
|
|
|
1554
1566
|
const importBlock = rewriteRequireExpressionsAndGetImportBlock(
|
|
@@ -1597,6 +1609,8 @@ function commonjs(options = {}) {
|
|
|
1597
1609
|
: Array.isArray(esmExternals)
|
|
1598
1610
|
? ((esmExternalIds = new Set(esmExternals)), (id) => esmExternalIds.has(id))
|
|
1599
1611
|
: () => esmExternals;
|
|
1612
|
+
const defaultIsModuleExports =
|
|
1613
|
+
typeof options.defaultIsModuleExports === 'boolean' ? options.defaultIsModuleExports : 'auto';
|
|
1600
1614
|
|
|
1601
1615
|
const { dynamicRequireModuleSet, dynamicRequireModuleDirPaths } = getDynamicRequirePaths(
|
|
1602
1616
|
options.dynamicRequireTargets
|
|
@@ -1608,6 +1622,7 @@ function commonjs(options = {}) {
|
|
|
1608
1622
|
|
|
1609
1623
|
const esModulesWithDefaultExport = new Set();
|
|
1610
1624
|
const esModulesWithNamedExports = new Set();
|
|
1625
|
+
const isCjsPromises = new Map();
|
|
1611
1626
|
|
|
1612
1627
|
const ignoreRequire =
|
|
1613
1628
|
typeof options.ignore === 'function'
|
|
@@ -1683,7 +1698,8 @@ function commonjs(options = {}) {
|
|
|
1683
1698
|
dynamicRequireModuleSet,
|
|
1684
1699
|
disableWrap,
|
|
1685
1700
|
commonDir,
|
|
1686
|
-
ast
|
|
1701
|
+
ast,
|
|
1702
|
+
defaultIsModuleExports
|
|
1687
1703
|
);
|
|
1688
1704
|
}
|
|
1689
1705
|
|
|
@@ -1743,7 +1759,8 @@ function commonjs(options = {}) {
|
|
|
1743
1759
|
actualId,
|
|
1744
1760
|
getRequireReturnsDefault(actualId),
|
|
1745
1761
|
esModulesWithDefaultExport,
|
|
1746
|
-
esModulesWithNamedExports
|
|
1762
|
+
esModulesWithNamedExports,
|
|
1763
|
+
isCjsPromises
|
|
1747
1764
|
);
|
|
1748
1765
|
}
|
|
1749
1766
|
|
|
@@ -1779,11 +1796,11 @@ function commonjs(options = {}) {
|
|
|
1779
1796
|
if (commonjs) {
|
|
1780
1797
|
const isCjs = commonjs.isCommonJS;
|
|
1781
1798
|
if (isCjs != null) {
|
|
1782
|
-
setIsCjsPromise(id, isCjs);
|
|
1799
|
+
setIsCjsPromise(isCjsPromises, id, isCjs);
|
|
1783
1800
|
return;
|
|
1784
1801
|
}
|
|
1785
1802
|
}
|
|
1786
|
-
setIsCjsPromise(id, null);
|
|
1803
|
+
setIsCjsPromise(isCjsPromises, id, null);
|
|
1787
1804
|
}
|
|
1788
1805
|
};
|
|
1789
1806
|
}
|