@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 CHANGED
@@ -16,9 +16,9 @@ var glob__default = /*#__PURE__*/_interopDefaultLegacy(glob);
16
16
  var MagicString__default = /*#__PURE__*/_interopDefaultLegacy(MagicString);
17
17
  var isReference__default = /*#__PURE__*/_interopDefaultLegacy(isReference);
18
18
 
19
- var version = "22.0.0-5";
19
+ var version = "22.0.0-9";
20
20
  var peerDependencies = {
21
- rollup: "^2.64.0"
21
+ rollup: "^2.67.0"
22
22
  };
23
23
 
24
24
  function tryParse(parse, code, id) {
@@ -337,7 +337,8 @@ const WRAPPED_SUFFIX = '?commonjs-wrapped';
337
337
  const EXTERNAL_SUFFIX = '?commonjs-external';
338
338
  const EXPORTS_SUFFIX = '?commonjs-exports';
339
339
  const MODULE_SUFFIX = '?commonjs-module';
340
- const ES_IMPORT_SUFFIX = '?es-import';
340
+ const ENTRY_SUFFIX = '?commonjs-entry';
341
+ const ES_IMPORT_SUFFIX = '?commonjs-es-import';
341
342
 
342
343
  const DYNAMIC_MODULES_ID = '\0commonjs-dynamic-modules';
343
344
  const HELPERS_ID = '\0commonjsHelpers.js';
@@ -429,6 +430,22 @@ async function getStaticRequireProxy(id, requireReturnsDefault, loadModule) {
429
430
  return `export { default } from ${JSON.stringify(id)};`;
430
431
  }
431
432
 
433
+ function getEntryProxy(id, defaultIsModuleExports, getModuleInfo) {
434
+ const {
435
+ meta: { commonjs: commonjsMeta },
436
+ hasDefaultExport
437
+ } = getModuleInfo(id);
438
+ if (!commonjsMeta || commonjsMeta.isCommonJS !== IS_WRAPPED_COMMONJS) {
439
+ const stringifiedId = JSON.stringify(id);
440
+ let code = `export * from ${stringifiedId};`;
441
+ if (hasDefaultExport) {
442
+ code += `export { default } from ${stringifiedId};`;
443
+ }
444
+ return code;
445
+ }
446
+ return getEsImportProxy(id, defaultIsModuleExports);
447
+ }
448
+
432
449
  function getEsImportProxy(id, defaultIsModuleExports) {
433
450
  const name = getName(id);
434
451
  const exportsName = `${name}Exports`;
@@ -485,11 +502,8 @@ function resolveExtensions(importee, importer, extensions) {
485
502
  function getResolveId(extensions) {
486
503
  return async function resolveId(importee, importer, resolveOptions) {
487
504
  // We assume that all requires are pre-resolved
488
- if (
489
- resolveOptions.custom &&
490
- resolveOptions.custom['node-resolve'] &&
491
- resolveOptions.custom['node-resolve'].isRequire
492
- ) {
505
+ const customOptions = resolveOptions.custom;
506
+ if (customOptions && customOptions['node-resolve'] && customOptions['node-resolve'].isRequire) {
493
507
  return null;
494
508
  }
495
509
  if (isWrappedId(importee, WRAPPED_SUFFIX)) {
@@ -497,6 +511,7 @@ function getResolveId(extensions) {
497
511
  }
498
512
 
499
513
  if (
514
+ importee.endsWith(ENTRY_SUFFIX) ||
500
515
  isWrappedId(importee, MODULE_SUFFIX) ||
501
516
  isWrappedId(importee, EXPORTS_SUFFIX) ||
502
517
  isWrappedId(importee, PROXY_SUFFIX) ||
@@ -513,7 +528,8 @@ function getResolveId(extensions) {
513
528
  importer === DYNAMIC_MODULES_ID ||
514
529
  // Proxies are only importing resolved ids, no need to resolve again
515
530
  isWrappedId(importer, PROXY_SUFFIX) ||
516
- isWrappedId(importer, ES_IMPORT_SUFFIX)
531
+ isWrappedId(importer, ES_IMPORT_SUFFIX) ||
532
+ importer.endsWith(ENTRY_SUFFIX)
517
533
  ) {
518
534
  return importee;
519
535
  }
@@ -533,22 +549,27 @@ function getResolveId(extensions) {
533
549
 
534
550
  // If this is an entry point or ESM import, we need to figure out if the importee is wrapped and
535
551
  // if that is the case, we need to add a proxy.
536
- const customOptions = resolveOptions.custom;
537
-
538
- // If this is a require, we do not need a proxy
539
- if (customOptions && customOptions['node-resolve'] && customOptions['node-resolve'].isRequire) {
540
- return null;
541
- }
542
-
543
552
  const resolved =
544
553
  (await this.resolve(importee, importer, Object.assign({ skipSelf: true }, resolveOptions))) ||
545
554
  resolveExtensions(importee, importer, extensions);
546
- if (!resolved || resolved.external) {
555
+ // Make sure that even if other plugins resolve again, we ignore our own proxies
556
+ if (
557
+ !resolved ||
558
+ resolved.external ||
559
+ resolved.id.endsWith(ENTRY_SUFFIX) ||
560
+ isWrappedId(resolved.id, ES_IMPORT_SUFFIX)
561
+ ) {
547
562
  return resolved;
548
563
  }
564
+ const moduleInfo = await this.load(resolved);
565
+ if (resolveOptions.isEntry) {
566
+ moduleInfo.moduleSideEffects = true;
567
+ // We must not precede entry proxies with a `\0` as that will mess up relative external resolution
568
+ return resolved.id + ENTRY_SUFFIX;
569
+ }
549
570
  const {
550
571
  meta: { commonjs: commonjsMeta }
551
- } = await this.load(resolved);
572
+ } = moduleInfo;
552
573
  if (commonjsMeta && commonjsMeta.isCommonJS === IS_WRAPPED_COMMONJS) {
553
574
  return wrapId(resolved.id, ES_IMPORT_SUFFIX);
554
575
  }
@@ -1807,6 +1828,8 @@ function ${requireName} () {
1807
1828
  };
1808
1829
  }
1809
1830
 
1831
+ const PLUGIN_NAME = 'commonjs';
1832
+
1810
1833
  function commonjs(options = {}) {
1811
1834
  const {
1812
1835
  ignoreGlobal,
@@ -1942,7 +1965,7 @@ function commonjs(options = {}) {
1942
1965
  }
1943
1966
 
1944
1967
  return {
1945
- name: 'commonjs',
1968
+ name: PLUGIN_NAME,
1946
1969
 
1947
1970
  version,
1948
1971
 
@@ -1950,7 +1973,7 @@ function commonjs(options = {}) {
1950
1973
  // We inject the resolver in the beginning so that "catch-all-resolver" like node-resolver
1951
1974
  // do not prevent our plugin from resolving entry points ot proxies.
1952
1975
  const plugins = Array.isArray(rawOptions.plugins)
1953
- ? rawOptions.plugins
1976
+ ? [...rawOptions.plugins]
1954
1977
  : rawOptions.plugins
1955
1978
  ? [rawOptions.plugins]
1956
1979
  : [];
@@ -2026,6 +2049,15 @@ function commonjs(options = {}) {
2026
2049
  );
2027
2050
  }
2028
2051
 
2052
+ // entry suffix is just appended to not mess up relative external resolution
2053
+ if (id.endsWith(ENTRY_SUFFIX)) {
2054
+ return getEntryProxy(
2055
+ id.slice(0, -ENTRY_SUFFIX.length),
2056
+ defaultIsModuleExports,
2057
+ this.getModuleInfo
2058
+ );
2059
+ }
2060
+
2029
2061
  if (isWrappedId(id, ES_IMPORT_SUFFIX)) {
2030
2062
  return getEsImportProxy(unwrapId(id, ES_IMPORT_SUFFIX), defaultIsModuleExports);
2031
2063
  }