@rollup/plugin-commonjs 25.0.4 → 25.0.6
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 +37 -9
- package/dist/es/index.js +37 -9
- package/package.json +3 -3
package/dist/cjs/index.js
CHANGED
|
@@ -11,9 +11,9 @@ var estreeWalker = require('estree-walker');
|
|
|
11
11
|
var MagicString = require('magic-string');
|
|
12
12
|
var isReference = require('is-reference');
|
|
13
13
|
|
|
14
|
-
var version = "25.0.
|
|
14
|
+
var version = "25.0.6";
|
|
15
15
|
var peerDependencies = {
|
|
16
|
-
rollup: "^2.68.0||^3.0.0"
|
|
16
|
+
rollup: "^2.68.0||^3.0.0||^4.0.0"
|
|
17
17
|
};
|
|
18
18
|
|
|
19
19
|
function tryParse(parse, code, id) {
|
|
@@ -36,6 +36,7 @@ function hasCjsKeywords(code, ignoreGlobal) {
|
|
|
36
36
|
|
|
37
37
|
/* eslint-disable no-underscore-dangle */
|
|
38
38
|
|
|
39
|
+
|
|
39
40
|
function analyzeTopLevelStatements(parse, code, id) {
|
|
40
41
|
const ast = tryParse(parse, code, id);
|
|
41
42
|
|
|
@@ -82,6 +83,7 @@ function analyzeTopLevelStatements(parse, code, id) {
|
|
|
82
83
|
|
|
83
84
|
/* eslint-disable import/prefer-default-export */
|
|
84
85
|
|
|
86
|
+
|
|
85
87
|
function deconflict(scopes, globals, identifier) {
|
|
86
88
|
let i = 1;
|
|
87
89
|
let deconflicted = pluginutils.makeLegalIdentifier(identifier);
|
|
@@ -432,7 +434,7 @@ async function getStaticRequireProxy(id, requireReturnsDefault, loadModule) {
|
|
|
432
434
|
return `export { default } from ${JSON.stringify(id)};`;
|
|
433
435
|
}
|
|
434
436
|
|
|
435
|
-
function getEntryProxy(id, defaultIsModuleExports, getModuleInfo) {
|
|
437
|
+
function getEntryProxy(id, defaultIsModuleExports, getModuleInfo, shebang) {
|
|
436
438
|
const {
|
|
437
439
|
meta: { commonjs: commonjsMeta },
|
|
438
440
|
hasDefaultExport
|
|
@@ -443,9 +445,13 @@ function getEntryProxy(id, defaultIsModuleExports, getModuleInfo) {
|
|
|
443
445
|
if (hasDefaultExport) {
|
|
444
446
|
code += `export { default } from ${stringifiedId};`;
|
|
445
447
|
}
|
|
446
|
-
return code;
|
|
448
|
+
return shebang + code;
|
|
447
449
|
}
|
|
448
|
-
|
|
450
|
+
const result = getEsImportProxy(id, defaultIsModuleExports);
|
|
451
|
+
return {
|
|
452
|
+
...result,
|
|
453
|
+
code: shebang + result.code
|
|
454
|
+
};
|
|
449
455
|
}
|
|
450
456
|
|
|
451
457
|
function getEsImportProxy(id, defaultIsModuleExports) {
|
|
@@ -470,6 +476,7 @@ function getEsImportProxy(id, defaultIsModuleExports) {
|
|
|
470
476
|
|
|
471
477
|
/* eslint-disable no-param-reassign, no-undefined */
|
|
472
478
|
|
|
479
|
+
|
|
473
480
|
function getCandidatesForExtension(resolved, extension) {
|
|
474
481
|
return [resolved + extension, `${resolved}${path.sep}index${extension}`];
|
|
475
482
|
}
|
|
@@ -780,6 +787,7 @@ function getRequireResolver(extensions, detectCyclesAndConditional, currentlyRes
|
|
|
780
787
|
currentlyResolvingForParent.add(source);
|
|
781
788
|
const resolved =
|
|
782
789
|
(await rollupContext.resolve(source, parentId, {
|
|
790
|
+
skipSelf: false,
|
|
783
791
|
custom: { 'node-resolve': { isRequire: true } }
|
|
784
792
|
})) || resolveExtensions(source, parentId, extensions);
|
|
785
793
|
currentlyResolvingForParent.delete(source);
|
|
@@ -1448,6 +1456,7 @@ function getGenerateRequireName() {
|
|
|
1448
1456
|
|
|
1449
1457
|
/* eslint-disable no-param-reassign, no-shadow, no-underscore-dangle, no-continue */
|
|
1450
1458
|
|
|
1459
|
+
|
|
1451
1460
|
const exportsPattern = /^(?:module\.)?exports(?:\.([a-zA-Z_$][a-zA-Z_$0-9]*))?$/;
|
|
1452
1461
|
|
|
1453
1462
|
const functionType = /^(?:FunctionDeclaration|FunctionExpression|ArrowFunctionExpression)$/;
|
|
@@ -1718,6 +1727,9 @@ async function transformCommonjs(
|
|
|
1718
1727
|
}
|
|
1719
1728
|
if (!ignoreDynamicRequires) {
|
|
1720
1729
|
if (isShorthandProperty(parent)) {
|
|
1730
|
+
// as key and value are the same object, isReference regards
|
|
1731
|
+
// both as references, so we need to skip now
|
|
1732
|
+
skippedNodes.add(parent.value);
|
|
1721
1733
|
magicString.prependRight(node.start, 'require: ');
|
|
1722
1734
|
}
|
|
1723
1735
|
replacedDynamicRequires.push(node);
|
|
@@ -1893,6 +1905,13 @@ async function transformCommonjs(
|
|
|
1893
1905
|
magicString.remove(0, commentEnd).trim();
|
|
1894
1906
|
}
|
|
1895
1907
|
|
|
1908
|
+
let shebang = '';
|
|
1909
|
+
if (code.startsWith('#!')) {
|
|
1910
|
+
const shebangEndPosition = code.indexOf('\n') + 1;
|
|
1911
|
+
shebang = code.slice(0, shebangEndPosition);
|
|
1912
|
+
magicString.remove(0, shebangEndPosition).trim();
|
|
1913
|
+
}
|
|
1914
|
+
|
|
1896
1915
|
const exportMode = isEsModule
|
|
1897
1916
|
? 'none'
|
|
1898
1917
|
: shouldWrap
|
|
@@ -1976,14 +1995,14 @@ function ${requireName} () {
|
|
|
1976
1995
|
|
|
1977
1996
|
magicString
|
|
1978
1997
|
.trim()
|
|
1979
|
-
.prepend(leadingComment + importBlock)
|
|
1998
|
+
.prepend(shebang + leadingComment + importBlock)
|
|
1980
1999
|
.append(exportBlock);
|
|
1981
2000
|
|
|
1982
2001
|
return {
|
|
1983
2002
|
code: magicString.toString(),
|
|
1984
2003
|
map: sourceMap ? magicString.generateMap() : null,
|
|
1985
2004
|
syntheticNamedExports: isEsModule || usesRequireWrapper ? false : '__moduleExports',
|
|
1986
|
-
meta: { commonjs: commonjsMeta }
|
|
2005
|
+
meta: { commonjs: { ...commonjsMeta, shebang } }
|
|
1987
2006
|
};
|
|
1988
2007
|
}
|
|
1989
2008
|
|
|
@@ -2225,7 +2244,16 @@ function commonjs(options = {}) {
|
|
|
2225
2244
|
// entry suffix is just appended to not mess up relative external resolution
|
|
2226
2245
|
if (id.endsWith(ENTRY_SUFFIX)) {
|
|
2227
2246
|
const acutalId = id.slice(0, -ENTRY_SUFFIX.length);
|
|
2228
|
-
|
|
2247
|
+
const {
|
|
2248
|
+
meta: { commonjs: commonjsMeta }
|
|
2249
|
+
} = this.getModuleInfo(acutalId);
|
|
2250
|
+
const shebang = commonjsMeta?.shebang ?? '';
|
|
2251
|
+
return getEntryProxy(
|
|
2252
|
+
acutalId,
|
|
2253
|
+
getDefaultIsModuleExports(acutalId),
|
|
2254
|
+
this.getModuleInfo,
|
|
2255
|
+
shebang
|
|
2256
|
+
);
|
|
2229
2257
|
}
|
|
2230
2258
|
|
|
2231
2259
|
if (isWrappedId(id, ES_IMPORT_SUFFIX)) {
|
|
@@ -2260,7 +2288,7 @@ function commonjs(options = {}) {
|
|
|
2260
2288
|
try {
|
|
2261
2289
|
return transformAndCheckExports.call(this, code, id);
|
|
2262
2290
|
} catch (err) {
|
|
2263
|
-
return this.error(err, err.
|
|
2291
|
+
return this.error(err, err.pos);
|
|
2264
2292
|
}
|
|
2265
2293
|
}
|
|
2266
2294
|
};
|
package/dist/es/index.js
CHANGED
|
@@ -7,9 +7,9 @@ import { walk } from 'estree-walker';
|
|
|
7
7
|
import MagicString from 'magic-string';
|
|
8
8
|
import isReference from 'is-reference';
|
|
9
9
|
|
|
10
|
-
var version = "25.0.
|
|
10
|
+
var version = "25.0.6";
|
|
11
11
|
var peerDependencies = {
|
|
12
|
-
rollup: "^2.68.0||^3.0.0"
|
|
12
|
+
rollup: "^2.68.0||^3.0.0||^4.0.0"
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
function tryParse(parse, code, id) {
|
|
@@ -32,6 +32,7 @@ function hasCjsKeywords(code, ignoreGlobal) {
|
|
|
32
32
|
|
|
33
33
|
/* eslint-disable no-underscore-dangle */
|
|
34
34
|
|
|
35
|
+
|
|
35
36
|
function analyzeTopLevelStatements(parse, code, id) {
|
|
36
37
|
const ast = tryParse(parse, code, id);
|
|
37
38
|
|
|
@@ -78,6 +79,7 @@ function analyzeTopLevelStatements(parse, code, id) {
|
|
|
78
79
|
|
|
79
80
|
/* eslint-disable import/prefer-default-export */
|
|
80
81
|
|
|
82
|
+
|
|
81
83
|
function deconflict(scopes, globals, identifier) {
|
|
82
84
|
let i = 1;
|
|
83
85
|
let deconflicted = makeLegalIdentifier(identifier);
|
|
@@ -428,7 +430,7 @@ async function getStaticRequireProxy(id, requireReturnsDefault, loadModule) {
|
|
|
428
430
|
return `export { default } from ${JSON.stringify(id)};`;
|
|
429
431
|
}
|
|
430
432
|
|
|
431
|
-
function getEntryProxy(id, defaultIsModuleExports, getModuleInfo) {
|
|
433
|
+
function getEntryProxy(id, defaultIsModuleExports, getModuleInfo, shebang) {
|
|
432
434
|
const {
|
|
433
435
|
meta: { commonjs: commonjsMeta },
|
|
434
436
|
hasDefaultExport
|
|
@@ -439,9 +441,13 @@ function getEntryProxy(id, defaultIsModuleExports, getModuleInfo) {
|
|
|
439
441
|
if (hasDefaultExport) {
|
|
440
442
|
code += `export { default } from ${stringifiedId};`;
|
|
441
443
|
}
|
|
442
|
-
return code;
|
|
444
|
+
return shebang + code;
|
|
443
445
|
}
|
|
444
|
-
|
|
446
|
+
const result = getEsImportProxy(id, defaultIsModuleExports);
|
|
447
|
+
return {
|
|
448
|
+
...result,
|
|
449
|
+
code: shebang + result.code
|
|
450
|
+
};
|
|
445
451
|
}
|
|
446
452
|
|
|
447
453
|
function getEsImportProxy(id, defaultIsModuleExports) {
|
|
@@ -466,6 +472,7 @@ function getEsImportProxy(id, defaultIsModuleExports) {
|
|
|
466
472
|
|
|
467
473
|
/* eslint-disable no-param-reassign, no-undefined */
|
|
468
474
|
|
|
475
|
+
|
|
469
476
|
function getCandidatesForExtension(resolved, extension) {
|
|
470
477
|
return [resolved + extension, `${resolved}${sep}index${extension}`];
|
|
471
478
|
}
|
|
@@ -776,6 +783,7 @@ function getRequireResolver(extensions, detectCyclesAndConditional, currentlyRes
|
|
|
776
783
|
currentlyResolvingForParent.add(source);
|
|
777
784
|
const resolved =
|
|
778
785
|
(await rollupContext.resolve(source, parentId, {
|
|
786
|
+
skipSelf: false,
|
|
779
787
|
custom: { 'node-resolve': { isRequire: true } }
|
|
780
788
|
})) || resolveExtensions(source, parentId, extensions);
|
|
781
789
|
currentlyResolvingForParent.delete(source);
|
|
@@ -1444,6 +1452,7 @@ function getGenerateRequireName() {
|
|
|
1444
1452
|
|
|
1445
1453
|
/* eslint-disable no-param-reassign, no-shadow, no-underscore-dangle, no-continue */
|
|
1446
1454
|
|
|
1455
|
+
|
|
1447
1456
|
const exportsPattern = /^(?:module\.)?exports(?:\.([a-zA-Z_$][a-zA-Z_$0-9]*))?$/;
|
|
1448
1457
|
|
|
1449
1458
|
const functionType = /^(?:FunctionDeclaration|FunctionExpression|ArrowFunctionExpression)$/;
|
|
@@ -1714,6 +1723,9 @@ async function transformCommonjs(
|
|
|
1714
1723
|
}
|
|
1715
1724
|
if (!ignoreDynamicRequires) {
|
|
1716
1725
|
if (isShorthandProperty(parent)) {
|
|
1726
|
+
// as key and value are the same object, isReference regards
|
|
1727
|
+
// both as references, so we need to skip now
|
|
1728
|
+
skippedNodes.add(parent.value);
|
|
1717
1729
|
magicString.prependRight(node.start, 'require: ');
|
|
1718
1730
|
}
|
|
1719
1731
|
replacedDynamicRequires.push(node);
|
|
@@ -1889,6 +1901,13 @@ async function transformCommonjs(
|
|
|
1889
1901
|
magicString.remove(0, commentEnd).trim();
|
|
1890
1902
|
}
|
|
1891
1903
|
|
|
1904
|
+
let shebang = '';
|
|
1905
|
+
if (code.startsWith('#!')) {
|
|
1906
|
+
const shebangEndPosition = code.indexOf('\n') + 1;
|
|
1907
|
+
shebang = code.slice(0, shebangEndPosition);
|
|
1908
|
+
magicString.remove(0, shebangEndPosition).trim();
|
|
1909
|
+
}
|
|
1910
|
+
|
|
1892
1911
|
const exportMode = isEsModule
|
|
1893
1912
|
? 'none'
|
|
1894
1913
|
: shouldWrap
|
|
@@ -1972,14 +1991,14 @@ function ${requireName} () {
|
|
|
1972
1991
|
|
|
1973
1992
|
magicString
|
|
1974
1993
|
.trim()
|
|
1975
|
-
.prepend(leadingComment + importBlock)
|
|
1994
|
+
.prepend(shebang + leadingComment + importBlock)
|
|
1976
1995
|
.append(exportBlock);
|
|
1977
1996
|
|
|
1978
1997
|
return {
|
|
1979
1998
|
code: magicString.toString(),
|
|
1980
1999
|
map: sourceMap ? magicString.generateMap() : null,
|
|
1981
2000
|
syntheticNamedExports: isEsModule || usesRequireWrapper ? false : '__moduleExports',
|
|
1982
|
-
meta: { commonjs: commonjsMeta }
|
|
2001
|
+
meta: { commonjs: { ...commonjsMeta, shebang } }
|
|
1983
2002
|
};
|
|
1984
2003
|
}
|
|
1985
2004
|
|
|
@@ -2221,7 +2240,16 @@ function commonjs(options = {}) {
|
|
|
2221
2240
|
// entry suffix is just appended to not mess up relative external resolution
|
|
2222
2241
|
if (id.endsWith(ENTRY_SUFFIX)) {
|
|
2223
2242
|
const acutalId = id.slice(0, -ENTRY_SUFFIX.length);
|
|
2224
|
-
|
|
2243
|
+
const {
|
|
2244
|
+
meta: { commonjs: commonjsMeta }
|
|
2245
|
+
} = this.getModuleInfo(acutalId);
|
|
2246
|
+
const shebang = commonjsMeta?.shebang ?? '';
|
|
2247
|
+
return getEntryProxy(
|
|
2248
|
+
acutalId,
|
|
2249
|
+
getDefaultIsModuleExports(acutalId),
|
|
2250
|
+
this.getModuleInfo,
|
|
2251
|
+
shebang
|
|
2252
|
+
);
|
|
2225
2253
|
}
|
|
2226
2254
|
|
|
2227
2255
|
if (isWrappedId(id, ES_IMPORT_SUFFIX)) {
|
|
@@ -2256,7 +2284,7 @@ function commonjs(options = {}) {
|
|
|
2256
2284
|
try {
|
|
2257
2285
|
return transformAndCheckExports.call(this, code, id);
|
|
2258
2286
|
} catch (err) {
|
|
2259
|
-
return this.error(err, err.
|
|
2287
|
+
return this.error(err, err.pos);
|
|
2260
2288
|
}
|
|
2261
2289
|
}
|
|
2262
2290
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rollup/plugin-commonjs",
|
|
3
|
-
"version": "25.0.
|
|
3
|
+
"version": "25.0.6",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"require"
|
|
55
55
|
],
|
|
56
56
|
"peerDependencies": {
|
|
57
|
-
"rollup": "^2.68.0||^3.0.0"
|
|
57
|
+
"rollup": "^2.68.0||^3.0.0||^4.0.0"
|
|
58
58
|
},
|
|
59
59
|
"peerDependenciesMeta": {
|
|
60
60
|
"rollup": {
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"@rollup/plugin-node-resolve": "^15.0.0",
|
|
75
75
|
"locate-character": "^2.0.5",
|
|
76
76
|
"require-relative": "^0.8.7",
|
|
77
|
-
"rollup": "^
|
|
77
|
+
"rollup": "^4.0.0-24",
|
|
78
78
|
"shx": "^0.3.4",
|
|
79
79
|
"source-map": "^0.7.4",
|
|
80
80
|
"source-map-support": "^0.5.21",
|