@rollup/plugin-commonjs 19.0.1 → 21.0.1
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 +32 -0
- package/README.md +4 -2
- package/dist/index.es.js +43 -10
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +45 -12
- package/dist/index.js.map +1 -1
- package/package.json +9 -8
package/dist/index.js
CHANGED
|
@@ -375,8 +375,7 @@ function getName(id) {
|
|
|
375
375
|
if (name !== 'index') {
|
|
376
376
|
return name;
|
|
377
377
|
}
|
|
378
|
-
|
|
379
|
-
return pluginutils.makeLegalIdentifier(segments[segments.length - 1]);
|
|
378
|
+
return pluginutils.makeLegalIdentifier(path.basename(path.dirname(id)));
|
|
380
379
|
}
|
|
381
380
|
|
|
382
381
|
function normalizePathSlashes(path) {
|
|
@@ -456,7 +455,7 @@ function getDynamicRequirePaths(patterns) {
|
|
|
456
455
|
for (const pattern of !patterns || Array.isArray(patterns) ? patterns || [] : [patterns]) {
|
|
457
456
|
const isNegated = pattern.startsWith('!');
|
|
458
457
|
const modifySet = Set.prototype[isNegated ? 'delete' : 'add'].bind(dynamicRequireModuleSet);
|
|
459
|
-
for (const path$1 of glob__default[
|
|
458
|
+
for (const path$1 of glob__default["default"].sync(isNegated ? pattern.substr(1) : pattern)) {
|
|
460
459
|
modifySet(normalizePathSlashes(path.resolve(path$1)));
|
|
461
460
|
if (isDirectory(path$1)) {
|
|
462
461
|
modifySet(normalizePathSlashes(path.resolve(path.join(path$1, getPackageEntryPoint(path$1)))));
|
|
@@ -596,7 +595,7 @@ function getResolveId(extensions) {
|
|
|
596
595
|
return undefined;
|
|
597
596
|
}
|
|
598
597
|
|
|
599
|
-
return function resolveId(importee, rawImporter) {
|
|
598
|
+
return function resolveId(importee, rawImporter, resolveOptions) {
|
|
600
599
|
if (isWrappedId(importee, MODULE_SUFFIX) || isWrappedId(importee, EXPORTS_SUFFIX)) {
|
|
601
600
|
return importee;
|
|
602
601
|
}
|
|
@@ -639,10 +638,16 @@ function getResolveId(extensions) {
|
|
|
639
638
|
return null;
|
|
640
639
|
}
|
|
641
640
|
|
|
642
|
-
return this.resolve(
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
641
|
+
return this.resolve(
|
|
642
|
+
importee,
|
|
643
|
+
importer,
|
|
644
|
+
Object.assign({}, resolveOptions, {
|
|
645
|
+
skipSelf: true,
|
|
646
|
+
custom: Object.assign({}, resolveOptions.custom, {
|
|
647
|
+
'node-resolve': { isRequire: isProxyModule || isRequiredModule }
|
|
648
|
+
})
|
|
649
|
+
})
|
|
650
|
+
).then((resolved) => {
|
|
646
651
|
if (!resolved) {
|
|
647
652
|
resolved = resolveExtensions(importee, importer);
|
|
648
653
|
}
|
|
@@ -788,6 +793,20 @@ function isShorthandProperty(parent) {
|
|
|
788
793
|
return parent && parent.type === 'Property' && parent.shorthand;
|
|
789
794
|
}
|
|
790
795
|
|
|
796
|
+
function hasDefineEsmProperty(node) {
|
|
797
|
+
return node.properties.some((property) => {
|
|
798
|
+
if (
|
|
799
|
+
property.type === 'Property' &&
|
|
800
|
+
property.key.type === 'Identifier' &&
|
|
801
|
+
property.key.name === '__esModule' &&
|
|
802
|
+
isTruthy(property.value)
|
|
803
|
+
) {
|
|
804
|
+
return true;
|
|
805
|
+
}
|
|
806
|
+
return false;
|
|
807
|
+
});
|
|
808
|
+
}
|
|
809
|
+
|
|
791
810
|
function wrapCode(magicString, uses, moduleName, exportsName) {
|
|
792
811
|
const args = [];
|
|
793
812
|
const passedArgs = [];
|
|
@@ -1174,7 +1193,7 @@ function transformCommonjs(
|
|
|
1174
1193
|
defaultIsModuleExports
|
|
1175
1194
|
) {
|
|
1176
1195
|
const ast = astCache || tryParse(parse, code, id);
|
|
1177
|
-
const magicString = new MagicString__default[
|
|
1196
|
+
const magicString = new MagicString__default["default"](code);
|
|
1178
1197
|
const uses = {
|
|
1179
1198
|
module: false,
|
|
1180
1199
|
exports: false,
|
|
@@ -1263,6 +1282,18 @@ function transformCommonjs(
|
|
|
1263
1282
|
} else if (!firstTopLevelModuleExportsAssignment) {
|
|
1264
1283
|
firstTopLevelModuleExportsAssignment = node;
|
|
1265
1284
|
}
|
|
1285
|
+
|
|
1286
|
+
if (defaultIsModuleExports === false) {
|
|
1287
|
+
shouldWrap = true;
|
|
1288
|
+
} else if (defaultIsModuleExports === 'auto') {
|
|
1289
|
+
if (node.right.type === 'ObjectExpression') {
|
|
1290
|
+
if (hasDefineEsmProperty(node.right)) {
|
|
1291
|
+
shouldWrap = true;
|
|
1292
|
+
}
|
|
1293
|
+
} else if (defaultIsModuleExports === false) {
|
|
1294
|
+
shouldWrap = true;
|
|
1295
|
+
}
|
|
1296
|
+
}
|
|
1266
1297
|
} else if (exportName === KEY_COMPILED_ESM) {
|
|
1267
1298
|
if (programDepth > 3) {
|
|
1268
1299
|
shouldWrap = true;
|
|
@@ -1421,7 +1452,7 @@ function transformCommonjs(
|
|
|
1421
1452
|
return;
|
|
1422
1453
|
case 'Identifier': {
|
|
1423
1454
|
const { name } = node;
|
|
1424
|
-
if (!(isReference__default[
|
|
1455
|
+
if (!(isReference__default["default"](node, parent) && !scope.contains(name))) return;
|
|
1425
1456
|
switch (name) {
|
|
1426
1457
|
case 'require':
|
|
1427
1458
|
if (isNodeRequirePropertyAccess(parent)) {
|
|
@@ -1667,7 +1698,7 @@ function commonjs(options = {}) {
|
|
|
1667
1698
|
);
|
|
1668
1699
|
const isDynamicRequireModulesEnabled = dynamicRequireModuleSet.size > 0;
|
|
1669
1700
|
const commonDir = isDynamicRequireModulesEnabled
|
|
1670
|
-
? getCommonDir__default[
|
|
1701
|
+
? getCommonDir__default["default"](null, Array.from(dynamicRequireModuleSet).concat(process.cwd()))
|
|
1671
1702
|
: null;
|
|
1672
1703
|
|
|
1673
1704
|
const esModulesWithDefaultExport = new Set();
|
|
@@ -1687,7 +1718,9 @@ function commonjs(options = {}) {
|
|
|
1687
1718
|
? options.ignoreTryCatch(id)
|
|
1688
1719
|
: Array.isArray(options.ignoreTryCatch)
|
|
1689
1720
|
? options.ignoreTryCatch.includes(id)
|
|
1690
|
-
: options.ignoreTryCatch
|
|
1721
|
+
: typeof options.ignoreTryCatch !== 'undefined'
|
|
1722
|
+
? options.ignoreTryCatch
|
|
1723
|
+
: true;
|
|
1691
1724
|
|
|
1692
1725
|
return {
|
|
1693
1726
|
canConvertRequire: mode !== 'remove' && mode !== true,
|