@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/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-11";
10
+ var version = "22.0.0-12";
11
11
  var peerDependencies = {
12
- rollup: "^2.67.0"
12
+ rollup: "^2.68.0"
13
13
  };
14
14
 
15
15
  function tryParse(parse, code, id) {
@@ -453,8 +453,7 @@ function getEsImportProxy(id, defaultIsModuleExports) {
453
453
  }
454
454
  return {
455
455
  code,
456
- syntheticNamedExports: '__moduleExports',
457
- meta: { commonjs: { isCommonJS: false } }
456
+ syntheticNamedExports: '__moduleExports'
458
457
  };
459
458
  }
460
459
 
@@ -562,7 +561,7 @@ function getResolveId(extensions) {
562
561
  meta: { commonjs: commonjsMeta }
563
562
  } = moduleInfo;
564
563
  if (commonjsMeta && commonjsMeta.isCommonJS === IS_WRAPPED_COMMONJS) {
565
- return wrapId(resolved.id, ES_IMPORT_SUFFIX);
564
+ return { id: wrapId(resolved.id, ES_IMPORT_SUFFIX), meta: { commonjs: { resolved } } };
566
565
  }
567
566
  return resolved;
568
567
  };
@@ -588,7 +587,7 @@ function getRequireResolver(extensions, detectCyclesAndConditional) {
588
587
  return false;
589
588
  };
590
589
 
591
- // Once a module is listed here, its type (wrapped or not) is fixed any may
590
+ // Once a module is listed here, its type (wrapped or not) is fixed and may
592
591
  // not change for the rest of the current build, to not break already
593
592
  // transformed modules.
594
593
  const fullyAnalyzedModules = Object.create(null);
@@ -637,42 +636,77 @@ function getRequireResolver(extensions, detectCyclesAndConditional) {
637
636
  }
638
637
  };
639
638
 
639
+ const getTypeForImportedModule = async (resolved, loadModule) => {
640
+ if (resolved.id in knownCjsModuleTypes) {
641
+ // This handles cyclic ES dependencies
642
+ return knownCjsModuleTypes[resolved.id];
643
+ }
644
+ const {
645
+ meta: { commonjs }
646
+ } = await loadModule(resolved);
647
+ return (commonjs && commonjs.isCommonJS) || false;
648
+ };
649
+
640
650
  return {
641
651
  getWrappedIds: () =>
642
652
  Object.keys(knownCjsModuleTypes).filter(
643
653
  (id) => knownCjsModuleTypes[id] === IS_WRAPPED_COMMONJS
644
654
  ),
645
655
  isRequiredId: (id) => requiredIds[id],
646
- async shouldTransformCachedModule({ id: parentId, meta: { commonjs: parentMeta } }) {
647
- // Ignore modules that did not pass through the original transformer in a previous build
648
- if (!(parentMeta && parentMeta.requires)) {
649
- return false;
650
- }
651
- setInitialParentType(parentId, parentMeta.initialCommonJSType);
652
- await Promise.all(
653
- parentMeta.requires.map(({ resolved, isConditional }) =>
654
- analyzeRequiredModule(parentId, resolved, isConditional, this.load)
655
- )
656
- );
657
- if (getTypeForFullyAnalyzedModule(parentId) !== parentMeta.isCommonJS) {
658
- return true;
659
- }
660
- for (const {
661
- resolved: { id }
662
- } of parentMeta.requires) {
663
- if (getTypeForFullyAnalyzedModule(id) !== parentMeta.isRequiredCommonJS[id]) {
656
+ async shouldTransformCachedModule({
657
+ id: parentId,
658
+ resolvedSources,
659
+ meta: { commonjs: parentMeta }
660
+ }) {
661
+ // We explicitly track ES modules to handle ciruclar imports
662
+ if (!(parentMeta && parentMeta.isCommonJS)) knownCjsModuleTypes[parentId] = false;
663
+ if (isWrappedId(parentId, ES_IMPORT_SUFFIX)) return false;
664
+ const parentRequires = parentMeta && parentMeta.requires;
665
+ if (parentRequires) {
666
+ setInitialParentType(parentId, parentMeta.initialCommonJSType);
667
+ await Promise.all(
668
+ parentRequires.map(({ resolved, isConditional }) =>
669
+ analyzeRequiredModule(parentId, resolved, isConditional, this.load)
670
+ )
671
+ );
672
+ if (getTypeForFullyAnalyzedModule(parentId) !== parentMeta.isCommonJS) {
664
673
  return true;
665
674
  }
675
+ for (const {
676
+ resolved: { id }
677
+ } of parentRequires) {
678
+ if (getTypeForFullyAnalyzedModule(id) !== parentMeta.isRequiredCommonJS[id]) {
679
+ return true;
680
+ }
681
+ }
682
+ // Now that we decided to go with the cached copy, neither the parent
683
+ // module nor any of its children may change types anymore
684
+ fullyAnalyzedModules[parentId] = true;
685
+ for (const {
686
+ resolved: { id }
687
+ } of parentRequires) {
688
+ fullyAnalyzedModules[id] = true;
689
+ }
666
690
  }
667
- // Now that we decided to go with the cached copy, neither the parent
668
- // module nor any of its children may change types anymore
669
- fullyAnalyzedModules[parentId] = true;
670
- for (const {
671
- resolved: { id }
672
- } of parentMeta.requires) {
673
- fullyAnalyzedModules[id] = true;
674
- }
675
- return false;
691
+ const parentRequireSet = new Set((parentRequires || []).map(({ resolved: { id } }) => id));
692
+ return (
693
+ await Promise.all(
694
+ Object.keys(resolvedSources)
695
+ .map((source) => resolvedSources[source])
696
+ .filter(({ id }) => !parentRequireSet.has(id))
697
+ .map(async (resolved) => {
698
+ if (isWrappedId(resolved.id, ES_IMPORT_SUFFIX)) {
699
+ return (
700
+ (await getTypeForImportedModule(
701
+ (await this.load({ id: resolved.id })).meta.commonjs.resolved,
702
+ this.load
703
+ )) !== IS_WRAPPED_COMMONJS
704
+ );
705
+ }
706
+ return (await getTypeForImportedModule(resolved, this.load)) === IS_WRAPPED_COMMONJS;
707
+ })
708
+ )
709
+ ).some((shouldTransform) => shouldTransform);
676
710
  },
677
711
  /* eslint-disable no-param-reassign */
678
712
  resolveRequireSourcesAndUpdateMeta: (rollupContext) => async (
@@ -1755,7 +1789,9 @@ async function transformCommonjs(
1755
1789
  magicString.remove(0, commentEnd).trim();
1756
1790
  }
1757
1791
 
1758
- const exportMode = shouldWrap
1792
+ const exportMode = isEsModule
1793
+ ? 'none'
1794
+ : shouldWrap
1759
1795
  ? uses.module
1760
1796
  ? 'module'
1761
1797
  : 'exports'