@rollup/plugin-commonjs 22.0.0-5 → 22.0.0-9
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 +52 -20
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/index.js +52 -20
- package/dist/es/index.js.map +1 -1
- package/package.json +3 -3
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 = "22.0.0-
|
|
10
|
+
var version = "22.0.0-9";
|
|
11
11
|
var peerDependencies = {
|
|
12
|
-
rollup: "^2.
|
|
12
|
+
rollup: "^2.67.0"
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
function tryParse(parse, code, id) {
|
|
@@ -328,7 +328,8 @@ const WRAPPED_SUFFIX = '?commonjs-wrapped';
|
|
|
328
328
|
const EXTERNAL_SUFFIX = '?commonjs-external';
|
|
329
329
|
const EXPORTS_SUFFIX = '?commonjs-exports';
|
|
330
330
|
const MODULE_SUFFIX = '?commonjs-module';
|
|
331
|
-
const
|
|
331
|
+
const ENTRY_SUFFIX = '?commonjs-entry';
|
|
332
|
+
const ES_IMPORT_SUFFIX = '?commonjs-es-import';
|
|
332
333
|
|
|
333
334
|
const DYNAMIC_MODULES_ID = '\0commonjs-dynamic-modules';
|
|
334
335
|
const HELPERS_ID = '\0commonjsHelpers.js';
|
|
@@ -420,6 +421,22 @@ async function getStaticRequireProxy(id, requireReturnsDefault, loadModule) {
|
|
|
420
421
|
return `export { default } from ${JSON.stringify(id)};`;
|
|
421
422
|
}
|
|
422
423
|
|
|
424
|
+
function getEntryProxy(id, defaultIsModuleExports, getModuleInfo) {
|
|
425
|
+
const {
|
|
426
|
+
meta: { commonjs: commonjsMeta },
|
|
427
|
+
hasDefaultExport
|
|
428
|
+
} = getModuleInfo(id);
|
|
429
|
+
if (!commonjsMeta || commonjsMeta.isCommonJS !== IS_WRAPPED_COMMONJS) {
|
|
430
|
+
const stringifiedId = JSON.stringify(id);
|
|
431
|
+
let code = `export * from ${stringifiedId};`;
|
|
432
|
+
if (hasDefaultExport) {
|
|
433
|
+
code += `export { default } from ${stringifiedId};`;
|
|
434
|
+
}
|
|
435
|
+
return code;
|
|
436
|
+
}
|
|
437
|
+
return getEsImportProxy(id, defaultIsModuleExports);
|
|
438
|
+
}
|
|
439
|
+
|
|
423
440
|
function getEsImportProxy(id, defaultIsModuleExports) {
|
|
424
441
|
const name = getName(id);
|
|
425
442
|
const exportsName = `${name}Exports`;
|
|
@@ -476,11 +493,8 @@ function resolveExtensions(importee, importer, extensions) {
|
|
|
476
493
|
function getResolveId(extensions) {
|
|
477
494
|
return async function resolveId(importee, importer, resolveOptions) {
|
|
478
495
|
// We assume that all requires are pre-resolved
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
resolveOptions.custom['node-resolve'] &&
|
|
482
|
-
resolveOptions.custom['node-resolve'].isRequire
|
|
483
|
-
) {
|
|
496
|
+
const customOptions = resolveOptions.custom;
|
|
497
|
+
if (customOptions && customOptions['node-resolve'] && customOptions['node-resolve'].isRequire) {
|
|
484
498
|
return null;
|
|
485
499
|
}
|
|
486
500
|
if (isWrappedId(importee, WRAPPED_SUFFIX)) {
|
|
@@ -488,6 +502,7 @@ function getResolveId(extensions) {
|
|
|
488
502
|
}
|
|
489
503
|
|
|
490
504
|
if (
|
|
505
|
+
importee.endsWith(ENTRY_SUFFIX) ||
|
|
491
506
|
isWrappedId(importee, MODULE_SUFFIX) ||
|
|
492
507
|
isWrappedId(importee, EXPORTS_SUFFIX) ||
|
|
493
508
|
isWrappedId(importee, PROXY_SUFFIX) ||
|
|
@@ -504,7 +519,8 @@ function getResolveId(extensions) {
|
|
|
504
519
|
importer === DYNAMIC_MODULES_ID ||
|
|
505
520
|
// Proxies are only importing resolved ids, no need to resolve again
|
|
506
521
|
isWrappedId(importer, PROXY_SUFFIX) ||
|
|
507
|
-
isWrappedId(importer, ES_IMPORT_SUFFIX)
|
|
522
|
+
isWrappedId(importer, ES_IMPORT_SUFFIX) ||
|
|
523
|
+
importer.endsWith(ENTRY_SUFFIX)
|
|
508
524
|
) {
|
|
509
525
|
return importee;
|
|
510
526
|
}
|
|
@@ -524,22 +540,27 @@ function getResolveId(extensions) {
|
|
|
524
540
|
|
|
525
541
|
// If this is an entry point or ESM import, we need to figure out if the importee is wrapped and
|
|
526
542
|
// if that is the case, we need to add a proxy.
|
|
527
|
-
const customOptions = resolveOptions.custom;
|
|
528
|
-
|
|
529
|
-
// If this is a require, we do not need a proxy
|
|
530
|
-
if (customOptions && customOptions['node-resolve'] && customOptions['node-resolve'].isRequire) {
|
|
531
|
-
return null;
|
|
532
|
-
}
|
|
533
|
-
|
|
534
543
|
const resolved =
|
|
535
544
|
(await this.resolve(importee, importer, Object.assign({ skipSelf: true }, resolveOptions))) ||
|
|
536
545
|
resolveExtensions(importee, importer, extensions);
|
|
537
|
-
if
|
|
546
|
+
// Make sure that even if other plugins resolve again, we ignore our own proxies
|
|
547
|
+
if (
|
|
548
|
+
!resolved ||
|
|
549
|
+
resolved.external ||
|
|
550
|
+
resolved.id.endsWith(ENTRY_SUFFIX) ||
|
|
551
|
+
isWrappedId(resolved.id, ES_IMPORT_SUFFIX)
|
|
552
|
+
) {
|
|
538
553
|
return resolved;
|
|
539
554
|
}
|
|
555
|
+
const moduleInfo = await this.load(resolved);
|
|
556
|
+
if (resolveOptions.isEntry) {
|
|
557
|
+
moduleInfo.moduleSideEffects = true;
|
|
558
|
+
// We must not precede entry proxies with a `\0` as that will mess up relative external resolution
|
|
559
|
+
return resolved.id + ENTRY_SUFFIX;
|
|
560
|
+
}
|
|
540
561
|
const {
|
|
541
562
|
meta: { commonjs: commonjsMeta }
|
|
542
|
-
} =
|
|
563
|
+
} = moduleInfo;
|
|
543
564
|
if (commonjsMeta && commonjsMeta.isCommonJS === IS_WRAPPED_COMMONJS) {
|
|
544
565
|
return wrapId(resolved.id, ES_IMPORT_SUFFIX);
|
|
545
566
|
}
|
|
@@ -1798,6 +1819,8 @@ function ${requireName} () {
|
|
|
1798
1819
|
};
|
|
1799
1820
|
}
|
|
1800
1821
|
|
|
1822
|
+
const PLUGIN_NAME = 'commonjs';
|
|
1823
|
+
|
|
1801
1824
|
function commonjs(options = {}) {
|
|
1802
1825
|
const {
|
|
1803
1826
|
ignoreGlobal,
|
|
@@ -1933,7 +1956,7 @@ function commonjs(options = {}) {
|
|
|
1933
1956
|
}
|
|
1934
1957
|
|
|
1935
1958
|
return {
|
|
1936
|
-
name:
|
|
1959
|
+
name: PLUGIN_NAME,
|
|
1937
1960
|
|
|
1938
1961
|
version,
|
|
1939
1962
|
|
|
@@ -1941,7 +1964,7 @@ function commonjs(options = {}) {
|
|
|
1941
1964
|
// We inject the resolver in the beginning so that "catch-all-resolver" like node-resolver
|
|
1942
1965
|
// do not prevent our plugin from resolving entry points ot proxies.
|
|
1943
1966
|
const plugins = Array.isArray(rawOptions.plugins)
|
|
1944
|
-
? rawOptions.plugins
|
|
1967
|
+
? [...rawOptions.plugins]
|
|
1945
1968
|
: rawOptions.plugins
|
|
1946
1969
|
? [rawOptions.plugins]
|
|
1947
1970
|
: [];
|
|
@@ -2017,6 +2040,15 @@ function commonjs(options = {}) {
|
|
|
2017
2040
|
);
|
|
2018
2041
|
}
|
|
2019
2042
|
|
|
2043
|
+
// entry suffix is just appended to not mess up relative external resolution
|
|
2044
|
+
if (id.endsWith(ENTRY_SUFFIX)) {
|
|
2045
|
+
return getEntryProxy(
|
|
2046
|
+
id.slice(0, -ENTRY_SUFFIX.length),
|
|
2047
|
+
defaultIsModuleExports,
|
|
2048
|
+
this.getModuleInfo
|
|
2049
|
+
);
|
|
2050
|
+
}
|
|
2051
|
+
|
|
2020
2052
|
if (isWrappedId(id, ES_IMPORT_SUFFIX)) {
|
|
2021
2053
|
return getEsImportProxy(unwrapId(id, ES_IMPORT_SUFFIX), defaultIsModuleExports);
|
|
2022
2054
|
}
|