@rollup/plugin-commonjs 22.0.0-11 → 22.0.0-12

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-11";
19
+ var version = "22.0.0-12";
20
20
  var peerDependencies = {
21
- rollup: "^2.67.0"
21
+ rollup: "^2.68.0"
22
22
  };
23
23
 
24
24
  function tryParse(parse, code, id) {
@@ -462,8 +462,7 @@ function getEsImportProxy(id, defaultIsModuleExports) {
462
462
  }
463
463
  return {
464
464
  code,
465
- syntheticNamedExports: '__moduleExports',
466
- meta: { commonjs: { isCommonJS: false } }
465
+ syntheticNamedExports: '__moduleExports'
467
466
  };
468
467
  }
469
468
 
@@ -571,7 +570,7 @@ function getResolveId(extensions) {
571
570
  meta: { commonjs: commonjsMeta }
572
571
  } = moduleInfo;
573
572
  if (commonjsMeta && commonjsMeta.isCommonJS === IS_WRAPPED_COMMONJS) {
574
- return wrapId(resolved.id, ES_IMPORT_SUFFIX);
573
+ return { id: wrapId(resolved.id, ES_IMPORT_SUFFIX), meta: { commonjs: { resolved } } };
575
574
  }
576
575
  return resolved;
577
576
  };
@@ -597,7 +596,7 @@ function getRequireResolver(extensions, detectCyclesAndConditional) {
597
596
  return false;
598
597
  };
599
598
 
600
- // Once a module is listed here, its type (wrapped or not) is fixed any may
599
+ // Once a module is listed here, its type (wrapped or not) is fixed and may
601
600
  // not change for the rest of the current build, to not break already
602
601
  // transformed modules.
603
602
  const fullyAnalyzedModules = Object.create(null);
@@ -646,42 +645,77 @@ function getRequireResolver(extensions, detectCyclesAndConditional) {
646
645
  }
647
646
  };
648
647
 
648
+ const getTypeForImportedModule = async (resolved, loadModule) => {
649
+ if (resolved.id in knownCjsModuleTypes) {
650
+ // This handles cyclic ES dependencies
651
+ return knownCjsModuleTypes[resolved.id];
652
+ }
653
+ const {
654
+ meta: { commonjs }
655
+ } = await loadModule(resolved);
656
+ return (commonjs && commonjs.isCommonJS) || false;
657
+ };
658
+
649
659
  return {
650
660
  getWrappedIds: () =>
651
661
  Object.keys(knownCjsModuleTypes).filter(
652
662
  (id) => knownCjsModuleTypes[id] === IS_WRAPPED_COMMONJS
653
663
  ),
654
664
  isRequiredId: (id) => requiredIds[id],
655
- async shouldTransformCachedModule({ id: parentId, meta: { commonjs: parentMeta } }) {
656
- // Ignore modules that did not pass through the original transformer in a previous build
657
- if (!(parentMeta && parentMeta.requires)) {
658
- return false;
659
- }
660
- setInitialParentType(parentId, parentMeta.initialCommonJSType);
661
- await Promise.all(
662
- parentMeta.requires.map(({ resolved, isConditional }) =>
663
- analyzeRequiredModule(parentId, resolved, isConditional, this.load)
664
- )
665
- );
666
- if (getTypeForFullyAnalyzedModule(parentId) !== parentMeta.isCommonJS) {
667
- return true;
668
- }
669
- for (const {
670
- resolved: { id }
671
- } of parentMeta.requires) {
672
- if (getTypeForFullyAnalyzedModule(id) !== parentMeta.isRequiredCommonJS[id]) {
665
+ async shouldTransformCachedModule({
666
+ id: parentId,
667
+ resolvedSources,
668
+ meta: { commonjs: parentMeta }
669
+ }) {
670
+ // We explicitly track ES modules to handle ciruclar imports
671
+ if (!(parentMeta && parentMeta.isCommonJS)) knownCjsModuleTypes[parentId] = false;
672
+ if (isWrappedId(parentId, ES_IMPORT_SUFFIX)) return false;
673
+ const parentRequires = parentMeta && parentMeta.requires;
674
+ if (parentRequires) {
675
+ setInitialParentType(parentId, parentMeta.initialCommonJSType);
676
+ await Promise.all(
677
+ parentRequires.map(({ resolved, isConditional }) =>
678
+ analyzeRequiredModule(parentId, resolved, isConditional, this.load)
679
+ )
680
+ );
681
+ if (getTypeForFullyAnalyzedModule(parentId) !== parentMeta.isCommonJS) {
673
682
  return true;
674
683
  }
684
+ for (const {
685
+ resolved: { id }
686
+ } of parentRequires) {
687
+ if (getTypeForFullyAnalyzedModule(id) !== parentMeta.isRequiredCommonJS[id]) {
688
+ return true;
689
+ }
690
+ }
691
+ // Now that we decided to go with the cached copy, neither the parent
692
+ // module nor any of its children may change types anymore
693
+ fullyAnalyzedModules[parentId] = true;
694
+ for (const {
695
+ resolved: { id }
696
+ } of parentRequires) {
697
+ fullyAnalyzedModules[id] = true;
698
+ }
675
699
  }
676
- // Now that we decided to go with the cached copy, neither the parent
677
- // module nor any of its children may change types anymore
678
- fullyAnalyzedModules[parentId] = true;
679
- for (const {
680
- resolved: { id }
681
- } of parentMeta.requires) {
682
- fullyAnalyzedModules[id] = true;
683
- }
684
- return false;
700
+ const parentRequireSet = new Set((parentRequires || []).map(({ resolved: { id } }) => id));
701
+ return (
702
+ await Promise.all(
703
+ Object.keys(resolvedSources)
704
+ .map((source) => resolvedSources[source])
705
+ .filter(({ id }) => !parentRequireSet.has(id))
706
+ .map(async (resolved) => {
707
+ if (isWrappedId(resolved.id, ES_IMPORT_SUFFIX)) {
708
+ return (
709
+ (await getTypeForImportedModule(
710
+ (await this.load({ id: resolved.id })).meta.commonjs.resolved,
711
+ this.load
712
+ )) !== IS_WRAPPED_COMMONJS
713
+ );
714
+ }
715
+ return (await getTypeForImportedModule(resolved, this.load)) === IS_WRAPPED_COMMONJS;
716
+ })
717
+ )
718
+ ).some((shouldTransform) => shouldTransform);
685
719
  },
686
720
  /* eslint-disable no-param-reassign */
687
721
  resolveRequireSourcesAndUpdateMeta: (rollupContext) => async (
@@ -1764,7 +1798,9 @@ async function transformCommonjs(
1764
1798
  magicString.remove(0, commentEnd).trim();
1765
1799
  }
1766
1800
 
1767
- const exportMode = shouldWrap
1801
+ const exportMode = isEsModule
1802
+ ? 'none'
1803
+ : shouldWrap
1768
1804
  ? uses.module
1769
1805
  ? 'module'
1770
1806
  : 'exports'