@rollup/plugin-commonjs 22.0.1 → 23.0.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/README.md +5 -5
- package/dist/cjs/index.js +75 -74
- package/dist/es/index.js +67 -62
- package/package.json +26 -22
- package/types/index.d.ts +4 -4
- package/dist/cjs/index.js.map +0 -1
- package/dist/es/index.js.map +0 -1
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
|
|
14
14
|
## Requirements
|
|
15
15
|
|
|
16
|
-
This plugin requires an [LTS](https://github.com/nodejs/Release) Node version (
|
|
16
|
+
This plugin requires an [LTS](https://github.com/nodejs/Release) Node version (v14.0.0+) and Rollup v2.68.0+. If you are using [`@rollup/plugin-node-resolve`](https://github.com/rollup/plugins/tree/master/packages/node-resolve), it should be v13.0.6+.
|
|
17
17
|
|
|
18
18
|
## Install
|
|
19
19
|
|
|
@@ -59,9 +59,9 @@ The default value of `"auto"` will only wrap CommonJS files when they are part o
|
|
|
59
59
|
|
|
60
60
|
`false` will entirely prevent wrapping and hoist all files. This may still work depending on the nature of cyclic dependencies but will often cause problems.
|
|
61
61
|
|
|
62
|
-
You can also provide a [
|
|
62
|
+
You can also provide a [picomatch pattern](https://github.com/micromatch/picomatch), or array of patterns, to only specify a subset of files which should be wrapped in functions for proper `require` semantics.
|
|
63
63
|
|
|
64
|
-
`"debug"` works like `"auto"` but after bundling, it will display a warning containing a list of ids that have been wrapped which can be used as
|
|
64
|
+
`"debug"` works like `"auto"` but after bundling, it will display a warning containing a list of ids that have been wrapped which can be used as picomatch pattern for fine-tuning or to avoid the potential race conditions mentioned for `"auto"`.
|
|
65
65
|
|
|
66
66
|
### `dynamicRequireTargets`
|
|
67
67
|
|
|
@@ -104,14 +104,14 @@ To avoid long paths when using the `dynamicRequireTargets` option, you can use t
|
|
|
104
104
|
Type: `string | string[]`<br>
|
|
105
105
|
Default: `null`
|
|
106
106
|
|
|
107
|
-
A [
|
|
107
|
+
A [picomatch pattern](https://github.com/micromatch/picomatch), or array of patterns, which specifies the files in the build the plugin should _ignore_. By default, all files with extensions other than those in `extensions` or `".cjs"` are ignored, but you can exclude additional files. See also the `include` option.
|
|
108
108
|
|
|
109
109
|
### `include`
|
|
110
110
|
|
|
111
111
|
Type: `string | string[]`<br>
|
|
112
112
|
Default: `null`
|
|
113
113
|
|
|
114
|
-
A [
|
|
114
|
+
A [picomatch pattern](https://github.com/micromatch/picomatch), or array of patterns, which specifies the files in the build the plugin should operate on. By default, all files with extension `".cjs"` or those in `extensions` are included, but you can narrow this list by only including specific files. These files will be analyzed and transpiled if either the analysis does not find ES module specific statements or `transformMixedEsModules` is `true`.
|
|
115
115
|
|
|
116
116
|
### `extensions`
|
|
117
117
|
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
3
5
|
var path = require('path');
|
|
4
6
|
var pluginutils = require('@rollup/pluginutils');
|
|
5
7
|
var fs = require('fs');
|
|
@@ -9,16 +11,9 @@ var estreeWalker = require('estree-walker');
|
|
|
9
11
|
var MagicString = require('magic-string');
|
|
10
12
|
var isReference = require('is-reference');
|
|
11
13
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
var getCommonDir__default = /*#__PURE__*/_interopDefaultLegacy(getCommonDir);
|
|
15
|
-
var glob__default = /*#__PURE__*/_interopDefaultLegacy(glob);
|
|
16
|
-
var MagicString__default = /*#__PURE__*/_interopDefaultLegacy(MagicString);
|
|
17
|
-
var isReference__default = /*#__PURE__*/_interopDefaultLegacy(isReference);
|
|
18
|
-
|
|
19
|
-
var version = "22.0.1";
|
|
14
|
+
var version = "23.0.0";
|
|
20
15
|
var peerDependencies = {
|
|
21
|
-
rollup: "^2.68.0"
|
|
16
|
+
rollup: "^2.68.0||^3.0.0"
|
|
22
17
|
};
|
|
23
18
|
|
|
24
19
|
function tryParse(parse, code, id) {
|
|
@@ -181,7 +176,7 @@ function getDynamicRequireModules(patterns, dynamicRequireRoot) {
|
|
|
181
176
|
isNegated
|
|
182
177
|
? dynamicRequireModules.delete(targetPath)
|
|
183
178
|
: dynamicRequireModules.set(targetPath, resolvedPath);
|
|
184
|
-
for (const path$1 of
|
|
179
|
+
for (const path$1 of glob.sync(isNegated ? pattern.substr(1) : pattern)) {
|
|
185
180
|
const resolvedPath = path.resolve(path$1);
|
|
186
181
|
const requirePath = normalizePathSlashes(resolvedPath);
|
|
187
182
|
if (isDirectory(resolvedPath)) {
|
|
@@ -196,7 +191,7 @@ function getDynamicRequireModules(patterns, dynamicRequireRoot) {
|
|
|
196
191
|
}
|
|
197
192
|
}
|
|
198
193
|
return {
|
|
199
|
-
commonDir: dirNames.size ?
|
|
194
|
+
commonDir: dirNames.size ? getCommonDir([...dirNames, dynamicRequireRoot]) : null,
|
|
200
195
|
dynamicRequireModules
|
|
201
196
|
};
|
|
202
197
|
}
|
|
@@ -748,7 +743,9 @@ function getRequireResolver(extensions, detectCyclesAndConditional, currentlyRes
|
|
|
748
743
|
if (isWrappedId(resolved.id, ES_IMPORT_SUFFIX)) {
|
|
749
744
|
return (
|
|
750
745
|
(await getTypeForImportedModule(
|
|
751
|
-
(
|
|
746
|
+
(
|
|
747
|
+
await this.load({ id: resolved.id })
|
|
748
|
+
).meta.commonjs.resolved,
|
|
752
749
|
this.load
|
|
753
750
|
)) !== IS_WRAPPED_COMMONJS
|
|
754
751
|
);
|
|
@@ -759,61 +756,56 @@ function getRequireResolver(extensions, detectCyclesAndConditional, currentlyRes
|
|
|
759
756
|
).some((shouldTransform) => shouldTransform);
|
|
760
757
|
},
|
|
761
758
|
/* eslint-disable no-param-reassign */
|
|
762
|
-
resolveRequireSourcesAndUpdateMeta:
|
|
763
|
-
parentId,
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
}
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
return { id:
|
|
792
|
-
}
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
})
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
: dependencyId,
|
|
813
|
-
isCommonJS
|
|
814
|
-
};
|
|
815
|
-
});
|
|
816
|
-
},
|
|
759
|
+
resolveRequireSourcesAndUpdateMeta:
|
|
760
|
+
(rollupContext) => async (parentId, isParentCommonJS, parentMeta, sources) => {
|
|
761
|
+
parentMeta.initialCommonJSType = isParentCommonJS;
|
|
762
|
+
parentMeta.requires = [];
|
|
763
|
+
parentMeta.isRequiredCommonJS = Object.create(null);
|
|
764
|
+
setInitialParentType(parentId, isParentCommonJS);
|
|
765
|
+
const currentlyResolvingForParent = currentlyResolving.get(parentId) || new Set();
|
|
766
|
+
currentlyResolving.set(parentId, currentlyResolvingForParent);
|
|
767
|
+
const requireTargets = await Promise.all(
|
|
768
|
+
sources.map(async ({ source, isConditional }) => {
|
|
769
|
+
// Never analyze or proxy internal modules
|
|
770
|
+
if (source.startsWith('\0')) {
|
|
771
|
+
return { id: source, allowProxy: false };
|
|
772
|
+
}
|
|
773
|
+
currentlyResolvingForParent.add(source);
|
|
774
|
+
const resolved =
|
|
775
|
+
(await rollupContext.resolve(source, parentId, {
|
|
776
|
+
custom: { 'node-resolve': { isRequire: true } }
|
|
777
|
+
})) || resolveExtensions(source, parentId, extensions);
|
|
778
|
+
currentlyResolvingForParent.delete(source);
|
|
779
|
+
if (!resolved) {
|
|
780
|
+
return { id: wrapId(source, EXTERNAL_SUFFIX), allowProxy: false };
|
|
781
|
+
}
|
|
782
|
+
const childId = resolved.id;
|
|
783
|
+
if (resolved.external) {
|
|
784
|
+
return { id: wrapId(childId, EXTERNAL_SUFFIX), allowProxy: false };
|
|
785
|
+
}
|
|
786
|
+
parentMeta.requires.push({ resolved, isConditional });
|
|
787
|
+
await analyzeRequiredModule(parentId, resolved, isConditional, rollupContext.load);
|
|
788
|
+
return { id: childId, allowProxy: true };
|
|
789
|
+
})
|
|
790
|
+
);
|
|
791
|
+
parentMeta.isCommonJS = getTypeForFullyAnalyzedModule(parentId);
|
|
792
|
+
fullyAnalyzedModules[parentId] = true;
|
|
793
|
+
return requireTargets.map(({ id: dependencyId, allowProxy }, index) => {
|
|
794
|
+
// eslint-disable-next-line no-multi-assign
|
|
795
|
+
const isCommonJS = (parentMeta.isRequiredCommonJS[dependencyId] =
|
|
796
|
+
getTypeForFullyAnalyzedModule(dependencyId));
|
|
797
|
+
fullyAnalyzedModules[dependencyId] = true;
|
|
798
|
+
return {
|
|
799
|
+
source: sources[index].source,
|
|
800
|
+
id: allowProxy
|
|
801
|
+
? isCommonJS === IS_WRAPPED_COMMONJS
|
|
802
|
+
? wrapId(dependencyId, WRAPPED_SUFFIX)
|
|
803
|
+
: wrapId(dependencyId, PROXY_SUFFIX)
|
|
804
|
+
: dependencyId,
|
|
805
|
+
isCommonJS
|
|
806
|
+
};
|
|
807
|
+
});
|
|
808
|
+
},
|
|
817
809
|
isCurrentlyResolving(source, parentId) {
|
|
818
810
|
const currentlyResolvingForParent = currentlyResolving.get(parentId);
|
|
819
811
|
return currentlyResolvingForParent && currentlyResolvingForParent.has(source);
|
|
@@ -974,7 +966,7 @@ function hasDefineEsmProperty(node) {
|
|
|
974
966
|
});
|
|
975
967
|
}
|
|
976
968
|
|
|
977
|
-
function wrapCode(magicString, uses, moduleName, exportsName) {
|
|
969
|
+
function wrapCode(magicString, uses, moduleName, exportsName, indentExclusionRanges) {
|
|
978
970
|
const args = [];
|
|
979
971
|
const passedArgs = [];
|
|
980
972
|
if (uses.module) {
|
|
@@ -987,7 +979,7 @@ function wrapCode(magicString, uses, moduleName, exportsName) {
|
|
|
987
979
|
}
|
|
988
980
|
magicString
|
|
989
981
|
.trim()
|
|
990
|
-
.indent('\t')
|
|
982
|
+
.indent('\t', { exclude: indentExclusionRanges })
|
|
991
983
|
.prepend(`(function (${args.join(', ')}) {\n`)
|
|
992
984
|
.append(`\n} (${passedArgs.join(', ')}));`);
|
|
993
985
|
}
|
|
@@ -1445,7 +1437,7 @@ async function transformCommonjs(
|
|
|
1445
1437
|
commonjsMeta
|
|
1446
1438
|
) {
|
|
1447
1439
|
const ast = astCache || tryParse(parse, code, id);
|
|
1448
|
-
const magicString = new
|
|
1440
|
+
const magicString = new MagicString(code);
|
|
1449
1441
|
const uses = {
|
|
1450
1442
|
module: false,
|
|
1451
1443
|
exports: false,
|
|
@@ -1485,6 +1477,7 @@ async function transformCommonjs(
|
|
|
1485
1477
|
const replacedGlobal = [];
|
|
1486
1478
|
const replacedDynamicRequires = [];
|
|
1487
1479
|
const importedVariables = new Set();
|
|
1480
|
+
const indentExclusionRanges = [];
|
|
1488
1481
|
|
|
1489
1482
|
estreeWalker.walk(ast, {
|
|
1490
1483
|
enter(node, parent) {
|
|
@@ -1677,7 +1670,7 @@ async function transformCommonjs(
|
|
|
1677
1670
|
return;
|
|
1678
1671
|
case 'Identifier': {
|
|
1679
1672
|
const { name } = node;
|
|
1680
|
-
if (!
|
|
1673
|
+
if (!isReference(node, parent) || scope.contains(name)) return;
|
|
1681
1674
|
switch (name) {
|
|
1682
1675
|
case 'require':
|
|
1683
1676
|
uses.require = true;
|
|
@@ -1783,6 +1776,11 @@ async function transformCommonjs(
|
|
|
1783
1776
|
if (!scope.parent) {
|
|
1784
1777
|
topLevelDeclarations.push(node);
|
|
1785
1778
|
}
|
|
1779
|
+
return;
|
|
1780
|
+
case 'TemplateElement':
|
|
1781
|
+
if (node.value.raw.includes('\n')) {
|
|
1782
|
+
indentExclusionRanges.push([node.start, node.end]);
|
|
1783
|
+
}
|
|
1786
1784
|
}
|
|
1787
1785
|
},
|
|
1788
1786
|
|
|
@@ -1915,11 +1913,13 @@ async function transformCommonjs(
|
|
|
1915
1913
|
);
|
|
1916
1914
|
|
|
1917
1915
|
if (shouldWrap) {
|
|
1918
|
-
wrapCode(magicString, uses, moduleName, exportsName);
|
|
1916
|
+
wrapCode(magicString, uses, moduleName, exportsName, indentExclusionRanges);
|
|
1919
1917
|
}
|
|
1920
1918
|
|
|
1921
1919
|
if (usesRequireWrapper) {
|
|
1922
|
-
magicString.trim().indent('\t'
|
|
1920
|
+
magicString.trim().indent('\t', {
|
|
1921
|
+
exclude: indentExclusionRanges
|
|
1922
|
+
});
|
|
1923
1923
|
magicString.prepend(
|
|
1924
1924
|
`var ${isRequiredName};
|
|
1925
1925
|
|
|
@@ -2226,5 +2226,6 @@ function commonjs(options = {}) {
|
|
|
2226
2226
|
};
|
|
2227
2227
|
}
|
|
2228
2228
|
|
|
2229
|
-
|
|
2229
|
+
exports.default = commonjs;
|
|
2230
|
+
module.exports = Object.assign(exports.default, exports);
|
|
2230
2231
|
//# sourceMappingURL=index.js.map
|
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 = "
|
|
10
|
+
var version = "23.0.0";
|
|
11
11
|
var peerDependencies = {
|
|
12
|
-
rollup: "^2.68.0"
|
|
12
|
+
rollup: "^2.68.0||^3.0.0"
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
function tryParse(parse, code, id) {
|
|
@@ -739,7 +739,9 @@ function getRequireResolver(extensions, detectCyclesAndConditional, currentlyRes
|
|
|
739
739
|
if (isWrappedId(resolved.id, ES_IMPORT_SUFFIX)) {
|
|
740
740
|
return (
|
|
741
741
|
(await getTypeForImportedModule(
|
|
742
|
-
(
|
|
742
|
+
(
|
|
743
|
+
await this.load({ id: resolved.id })
|
|
744
|
+
).meta.commonjs.resolved,
|
|
743
745
|
this.load
|
|
744
746
|
)) !== IS_WRAPPED_COMMONJS
|
|
745
747
|
);
|
|
@@ -750,61 +752,56 @@ function getRequireResolver(extensions, detectCyclesAndConditional, currentlyRes
|
|
|
750
752
|
).some((shouldTransform) => shouldTransform);
|
|
751
753
|
},
|
|
752
754
|
/* eslint-disable no-param-reassign */
|
|
753
|
-
resolveRequireSourcesAndUpdateMeta:
|
|
754
|
-
parentId,
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
}
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
return { id:
|
|
783
|
-
}
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
})
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
: dependencyId,
|
|
804
|
-
isCommonJS
|
|
805
|
-
};
|
|
806
|
-
});
|
|
807
|
-
},
|
|
755
|
+
resolveRequireSourcesAndUpdateMeta:
|
|
756
|
+
(rollupContext) => async (parentId, isParentCommonJS, parentMeta, sources) => {
|
|
757
|
+
parentMeta.initialCommonJSType = isParentCommonJS;
|
|
758
|
+
parentMeta.requires = [];
|
|
759
|
+
parentMeta.isRequiredCommonJS = Object.create(null);
|
|
760
|
+
setInitialParentType(parentId, isParentCommonJS);
|
|
761
|
+
const currentlyResolvingForParent = currentlyResolving.get(parentId) || new Set();
|
|
762
|
+
currentlyResolving.set(parentId, currentlyResolvingForParent);
|
|
763
|
+
const requireTargets = await Promise.all(
|
|
764
|
+
sources.map(async ({ source, isConditional }) => {
|
|
765
|
+
// Never analyze or proxy internal modules
|
|
766
|
+
if (source.startsWith('\0')) {
|
|
767
|
+
return { id: source, allowProxy: false };
|
|
768
|
+
}
|
|
769
|
+
currentlyResolvingForParent.add(source);
|
|
770
|
+
const resolved =
|
|
771
|
+
(await rollupContext.resolve(source, parentId, {
|
|
772
|
+
custom: { 'node-resolve': { isRequire: true } }
|
|
773
|
+
})) || resolveExtensions(source, parentId, extensions);
|
|
774
|
+
currentlyResolvingForParent.delete(source);
|
|
775
|
+
if (!resolved) {
|
|
776
|
+
return { id: wrapId(source, EXTERNAL_SUFFIX), allowProxy: false };
|
|
777
|
+
}
|
|
778
|
+
const childId = resolved.id;
|
|
779
|
+
if (resolved.external) {
|
|
780
|
+
return { id: wrapId(childId, EXTERNAL_SUFFIX), allowProxy: false };
|
|
781
|
+
}
|
|
782
|
+
parentMeta.requires.push({ resolved, isConditional });
|
|
783
|
+
await analyzeRequiredModule(parentId, resolved, isConditional, rollupContext.load);
|
|
784
|
+
return { id: childId, allowProxy: true };
|
|
785
|
+
})
|
|
786
|
+
);
|
|
787
|
+
parentMeta.isCommonJS = getTypeForFullyAnalyzedModule(parentId);
|
|
788
|
+
fullyAnalyzedModules[parentId] = true;
|
|
789
|
+
return requireTargets.map(({ id: dependencyId, allowProxy }, index) => {
|
|
790
|
+
// eslint-disable-next-line no-multi-assign
|
|
791
|
+
const isCommonJS = (parentMeta.isRequiredCommonJS[dependencyId] =
|
|
792
|
+
getTypeForFullyAnalyzedModule(dependencyId));
|
|
793
|
+
fullyAnalyzedModules[dependencyId] = true;
|
|
794
|
+
return {
|
|
795
|
+
source: sources[index].source,
|
|
796
|
+
id: allowProxy
|
|
797
|
+
? isCommonJS === IS_WRAPPED_COMMONJS
|
|
798
|
+
? wrapId(dependencyId, WRAPPED_SUFFIX)
|
|
799
|
+
: wrapId(dependencyId, PROXY_SUFFIX)
|
|
800
|
+
: dependencyId,
|
|
801
|
+
isCommonJS
|
|
802
|
+
};
|
|
803
|
+
});
|
|
804
|
+
},
|
|
808
805
|
isCurrentlyResolving(source, parentId) {
|
|
809
806
|
const currentlyResolvingForParent = currentlyResolving.get(parentId);
|
|
810
807
|
return currentlyResolvingForParent && currentlyResolvingForParent.has(source);
|
|
@@ -965,7 +962,7 @@ function hasDefineEsmProperty(node) {
|
|
|
965
962
|
});
|
|
966
963
|
}
|
|
967
964
|
|
|
968
|
-
function wrapCode(magicString, uses, moduleName, exportsName) {
|
|
965
|
+
function wrapCode(magicString, uses, moduleName, exportsName, indentExclusionRanges) {
|
|
969
966
|
const args = [];
|
|
970
967
|
const passedArgs = [];
|
|
971
968
|
if (uses.module) {
|
|
@@ -978,7 +975,7 @@ function wrapCode(magicString, uses, moduleName, exportsName) {
|
|
|
978
975
|
}
|
|
979
976
|
magicString
|
|
980
977
|
.trim()
|
|
981
|
-
.indent('\t')
|
|
978
|
+
.indent('\t', { exclude: indentExclusionRanges })
|
|
982
979
|
.prepend(`(function (${args.join(', ')}) {\n`)
|
|
983
980
|
.append(`\n} (${passedArgs.join(', ')}));`);
|
|
984
981
|
}
|
|
@@ -1476,6 +1473,7 @@ async function transformCommonjs(
|
|
|
1476
1473
|
const replacedGlobal = [];
|
|
1477
1474
|
const replacedDynamicRequires = [];
|
|
1478
1475
|
const importedVariables = new Set();
|
|
1476
|
+
const indentExclusionRanges = [];
|
|
1479
1477
|
|
|
1480
1478
|
walk(ast, {
|
|
1481
1479
|
enter(node, parent) {
|
|
@@ -1774,6 +1772,11 @@ async function transformCommonjs(
|
|
|
1774
1772
|
if (!scope.parent) {
|
|
1775
1773
|
topLevelDeclarations.push(node);
|
|
1776
1774
|
}
|
|
1775
|
+
return;
|
|
1776
|
+
case 'TemplateElement':
|
|
1777
|
+
if (node.value.raw.includes('\n')) {
|
|
1778
|
+
indentExclusionRanges.push([node.start, node.end]);
|
|
1779
|
+
}
|
|
1777
1780
|
}
|
|
1778
1781
|
},
|
|
1779
1782
|
|
|
@@ -1906,11 +1909,13 @@ async function transformCommonjs(
|
|
|
1906
1909
|
);
|
|
1907
1910
|
|
|
1908
1911
|
if (shouldWrap) {
|
|
1909
|
-
wrapCode(magicString, uses, moduleName, exportsName);
|
|
1912
|
+
wrapCode(magicString, uses, moduleName, exportsName, indentExclusionRanges);
|
|
1910
1913
|
}
|
|
1911
1914
|
|
|
1912
1915
|
if (usesRequireWrapper) {
|
|
1913
|
-
magicString.trim().indent('\t'
|
|
1916
|
+
magicString.trim().indent('\t', {
|
|
1917
|
+
exclude: indentExclusionRanges
|
|
1918
|
+
});
|
|
1914
1919
|
magicString.prepend(
|
|
1915
1920
|
`var ${isRequiredName};
|
|
1916
1921
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rollup/plugin-commonjs",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "23.0.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -16,11 +16,12 @@
|
|
|
16
16
|
"main": "./dist/cjs/index.js",
|
|
17
17
|
"module": "./dist/es/index.js",
|
|
18
18
|
"exports": {
|
|
19
|
-
"
|
|
20
|
-
"
|
|
19
|
+
"import": "./dist/es/index.js",
|
|
20
|
+
"types": "./types/index.d.ts",
|
|
21
|
+
"default": "./dist/cjs/index.js"
|
|
21
22
|
},
|
|
22
23
|
"engines": {
|
|
23
|
-
"node": ">=
|
|
24
|
+
"node": ">=14.0.0"
|
|
24
25
|
},
|
|
25
26
|
"scripts": {
|
|
26
27
|
"build": "rollup -c",
|
|
@@ -33,12 +34,13 @@
|
|
|
33
34
|
"prepublishOnly": "pnpm build",
|
|
34
35
|
"prerelease": "pnpm build",
|
|
35
36
|
"pretest": "pnpm build",
|
|
36
|
-
"release": "pnpm
|
|
37
|
+
"release": "pnpm --workspace-root plugin:release --pkg $npm_package_name",
|
|
37
38
|
"test": "ava",
|
|
38
39
|
"test:ts": "tsc types/index.d.ts test/types.ts --noEmit"
|
|
39
40
|
},
|
|
40
41
|
"files": [
|
|
41
42
|
"dist",
|
|
43
|
+
"!dist/**/*.map",
|
|
42
44
|
"types",
|
|
43
45
|
"README.md",
|
|
44
46
|
"LICENSE"
|
|
@@ -52,33 +54,35 @@
|
|
|
52
54
|
"require"
|
|
53
55
|
],
|
|
54
56
|
"peerDependencies": {
|
|
55
|
-
"rollup": "^2.68.0"
|
|
57
|
+
"rollup": "^2.68.0||^3.0.0"
|
|
58
|
+
},
|
|
59
|
+
"peerDependenciesMeta": {
|
|
60
|
+
"rollup": {
|
|
61
|
+
"optional": true
|
|
62
|
+
}
|
|
56
63
|
},
|
|
57
64
|
"dependencies": {
|
|
58
|
-
"@rollup/pluginutils": "^
|
|
65
|
+
"@rollup/pluginutils": "^4.2.1",
|
|
59
66
|
"commondir": "^1.0.1",
|
|
60
|
-
"estree-walker": "^2.0.
|
|
61
|
-
"glob": "^
|
|
62
|
-
"is-reference": "
|
|
63
|
-
"magic-string": "^0.
|
|
64
|
-
"resolve": "^1.17.0"
|
|
67
|
+
"estree-walker": "^2.0.2",
|
|
68
|
+
"glob": "^8.0.3",
|
|
69
|
+
"is-reference": "1.2.1",
|
|
70
|
+
"magic-string": "^0.26.4"
|
|
65
71
|
},
|
|
66
72
|
"devDependencies": {
|
|
67
73
|
"@rollup/plugin-json": "^4.1.0",
|
|
68
|
-
"@rollup/plugin-node-resolve": "^
|
|
74
|
+
"@rollup/plugin-node-resolve": "^14.1.0",
|
|
69
75
|
"locate-character": "^2.0.5",
|
|
70
76
|
"require-relative": "^0.8.7",
|
|
71
|
-
"rollup": "
|
|
72
|
-
"shx": "^0.3.
|
|
73
|
-
"source-map": "^0.7.
|
|
74
|
-
"source-map-support": "^0.5.
|
|
75
|
-
"typescript": "^
|
|
77
|
+
"rollup": "3.0.0-7",
|
|
78
|
+
"shx": "^0.3.4",
|
|
79
|
+
"source-map": "^0.7.4",
|
|
80
|
+
"source-map-support": "^0.5.21",
|
|
81
|
+
"typescript": "^4.8.3"
|
|
76
82
|
},
|
|
77
|
-
"types": "types/index.d.ts",
|
|
83
|
+
"types": "./types/index.d.ts",
|
|
78
84
|
"ava": {
|
|
79
|
-
"
|
|
80
|
-
"compileEnhancements": false
|
|
81
|
-
},
|
|
85
|
+
"workerThreads": false,
|
|
82
86
|
"files": [
|
|
83
87
|
"!**/fixtures/**",
|
|
84
88
|
"!**/helpers/**",
|
package/types/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ type DefaultIsModuleExportsOption = boolean | 'auto';
|
|
|
6
6
|
|
|
7
7
|
interface RollupCommonJSOptions {
|
|
8
8
|
/**
|
|
9
|
-
* A
|
|
9
|
+
* A picomatch pattern, or array of patterns, which specifies the files in
|
|
10
10
|
* the build the plugin should operate on. By default, all files with
|
|
11
11
|
* extension `".cjs"` or those in `extensions` are included, but you can
|
|
12
12
|
* narrow this list by only including specific files. These files will be
|
|
@@ -16,7 +16,7 @@ interface RollupCommonJSOptions {
|
|
|
16
16
|
*/
|
|
17
17
|
include?: FilterPattern;
|
|
18
18
|
/**
|
|
19
|
-
* A
|
|
19
|
+
* A picomatch pattern, or array of patterns, which specifies the files in
|
|
20
20
|
* the build the plugin should _ignore_. By default, all files with
|
|
21
21
|
* extensions other than those in `extensions` or `".cjs"` are ignored, but you
|
|
22
22
|
* can exclude additional files. See also the `include` option.
|
|
@@ -88,13 +88,13 @@ interface RollupCommonJSOptions {
|
|
|
88
88
|
* work depending on the nature of cyclic dependencies but will often cause
|
|
89
89
|
* problems.
|
|
90
90
|
*
|
|
91
|
-
* You can also provide a
|
|
91
|
+
* You can also provide a picomatch pattern, or array of patterns, to only
|
|
92
92
|
* specify a subset of files which should be wrapped in functions for proper
|
|
93
93
|
* `require` semantics.
|
|
94
94
|
*
|
|
95
95
|
* `"debug"` works like `"auto"` but after bundling, it will display a warning
|
|
96
96
|
* containing a list of ids that have been wrapped which can be used as
|
|
97
|
-
*
|
|
97
|
+
* picomatch pattern for fine-tuning.
|
|
98
98
|
* @default "auto"
|
|
99
99
|
*/
|
|
100
100
|
strictRequires?: boolean | FilterPattern;
|