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

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,7 +7,7 @@ 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";
10
+ var version = "22.0.0-11";
11
11
  var peerDependencies = {
12
12
  rollup: "^2.67.0"
13
13
  };
@@ -588,6 +588,9 @@ function getRequireResolver(extensions, detectCyclesAndConditional) {
588
588
  return false;
589
589
  };
590
590
 
591
+ // Once a module is listed here, its type (wrapped or not) is fixed any may
592
+ // not change for the rest of the current build, to not break already
593
+ // transformed modules.
591
594
  const fullyAnalyzedModules = Object.create(null);
592
595
 
593
596
  const getTypeForFullyAnalyzedModule = (id) => {
@@ -595,7 +598,6 @@ function getRequireResolver(extensions, detectCyclesAndConditional) {
595
598
  if (knownType !== true || !detectCyclesAndConditional || fullyAnalyzedModules[id]) {
596
599
  return knownType;
597
600
  }
598
- fullyAnalyzedModules[id] = true;
599
601
  if (isCyclic(id)) {
600
602
  return (knownCjsModuleTypes[id] = IS_WRAPPED_COMMONJS);
601
603
  }
@@ -603,13 +605,11 @@ function getRequireResolver(extensions, detectCyclesAndConditional) {
603
605
  };
604
606
 
605
607
  const setInitialParentType = (id, initialCommonJSType) => {
606
- // It is possible a transformed module is already fully analyzed when using
607
- // the cache and one dependency introduces a new cycle. Then transform is
608
- // run for a fully analzyed module again. Fully analyzed modules may never
609
- // change their type as importers already trust their type.
610
- knownCjsModuleTypes[id] = fullyAnalyzedModules[id]
611
- ? knownCjsModuleTypes[id]
612
- : initialCommonJSType;
608
+ // Fully analyzed modules may never change type
609
+ if (fullyAnalyzedModules[id]) {
610
+ return;
611
+ }
612
+ knownCjsModuleTypes[id] = initialCommonJSType;
613
613
  if (
614
614
  detectCyclesAndConditional &&
615
615
  knownCjsModuleTypes[id] === true &&
@@ -620,7 +620,7 @@ function getRequireResolver(extensions, detectCyclesAndConditional) {
620
620
  }
621
621
  };
622
622
 
623
- const setTypesForRequiredModules = async (parentId, resolved, isConditional, loadModule) => {
623
+ const analyzeRequiredModule = async (parentId, resolved, isConditional, loadModule) => {
624
624
  const childId = resolved.id;
625
625
  requiredIds[childId] = true;
626
626
  if (!(isConditional || knownCjsModuleTypes[parentId] === IS_WRAPPED_COMMONJS)) {
@@ -629,9 +629,10 @@ function getRequireResolver(extensions, detectCyclesAndConditional) {
629
629
 
630
630
  getDependencies(parentId).add(childId);
631
631
  if (!isCyclic(childId)) {
632
- // This makes sure the current transform handler waits for all direct dependencies to be
633
- // loaded and transformed and therefore for all transitive CommonJS dependencies to be
634
- // loaded as well so that all cycles have been found and knownCjsModuleTypes is reliable.
632
+ // This makes sure the current transform handler waits for all direct
633
+ // dependencies to be loaded and transformed and therefore for all
634
+ // transitive CommonJS dependencies to be loaded as well so that all
635
+ // cycles have been found and knownCjsModuleTypes is reliable.
635
636
  await loadModule(resolved);
636
637
  }
637
638
  };
@@ -650,7 +651,7 @@ function getRequireResolver(extensions, detectCyclesAndConditional) {
650
651
  setInitialParentType(parentId, parentMeta.initialCommonJSType);
651
652
  await Promise.all(
652
653
  parentMeta.requires.map(({ resolved, isConditional }) =>
653
- setTypesForRequiredModules(parentId, resolved, isConditional, this.load)
654
+ analyzeRequiredModule(parentId, resolved, isConditional, this.load)
654
655
  )
655
656
  );
656
657
  if (getTypeForFullyAnalyzedModule(parentId) !== parentMeta.isCommonJS) {
@@ -663,6 +664,14 @@ function getRequireResolver(extensions, detectCyclesAndConditional) {
663
664
  return true;
664
665
  }
665
666
  }
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
+ }
666
675
  return false;
667
676
  },
668
677
  /* eslint-disable no-param-reassign */
@@ -694,16 +703,18 @@ function getRequireResolver(extensions, detectCyclesAndConditional) {
694
703
  return { id: wrapId(childId, EXTERNAL_SUFFIX), allowProxy: false };
695
704
  }
696
705
  parentMeta.requires.push({ resolved, isConditional });
697
- await setTypesForRequiredModules(parentId, resolved, isConditional, rollupContext.load);
706
+ await analyzeRequiredModule(parentId, resolved, isConditional, rollupContext.load);
698
707
  return { id: childId, allowProxy: true };
699
708
  })
700
709
  );
701
710
  parentMeta.isCommonJS = getTypeForFullyAnalyzedModule(parentId);
711
+ fullyAnalyzedModules[parentId] = true;
702
712
  return requireTargets.map(({ id: dependencyId, allowProxy }, index) => {
703
713
  // eslint-disable-next-line no-multi-assign
704
714
  const isCommonJS = (parentMeta.isRequiredCommonJS[
705
715
  dependencyId
706
716
  ] = getTypeForFullyAnalyzedModule(dependencyId));
717
+ fullyAnalyzedModules[dependencyId] = true;
707
718
  return {
708
719
  source: sources[index].source,
709
720
  id: allowProxy