@rollup/plugin-commonjs 22.0.0-0 → 22.0.0-1

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/index.js CHANGED
@@ -16,7 +16,7 @@ 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-0";
19
+ var version = "22.0.0-1";
20
20
  var peerDependencies = {
21
21
  rollup: "^2.60.0"
22
22
  };
@@ -487,6 +487,13 @@ function resolveExtensions(importee, importer, extensions) {
487
487
 
488
488
  function getResolveId(extensions) {
489
489
  return async function resolveId(importee, importer, resolveOptions) {
490
+ if (
491
+ resolveOptions.custom &&
492
+ resolveOptions.custom.commonjs &&
493
+ resolveOptions.custom.commonjs.skipResolver
494
+ ) {
495
+ return null;
496
+ }
490
497
  if (isWrappedId(importee, WRAPPED_SUFFIX)) {
491
498
  return unwrapId(importee, WRAPPED_SUFFIX);
492
499
  }
@@ -506,7 +513,7 @@ function getResolveId(extensions) {
506
513
  if (importer) {
507
514
  if (
508
515
  importer === DYNAMIC_MODULES_ID ||
509
- // Except for exports, proxies are only importing resolved ids, no need to resolve again
516
+ // Proxies are only importing resolved ids, no need to resolve again
510
517
  isWrappedId(importer, PROXY_SUFFIX) ||
511
518
  isWrappedId(importer, ES_IMPORT_SUFFIX)
512
519
  ) {
@@ -555,9 +562,10 @@ function getResolveRequireSourcesAndGetMeta(extensions, detectCyclesAndCondition
555
562
  const knownCjsModuleTypes = Object.create(null);
556
563
  const requiredIds = Object.create(null);
557
564
  const unconditionallyRequiredIds = Object.create(null);
558
- const dependentModules = Object.create(null);
559
- const getDependentModules = (id) =>
560
- dependentModules[id] || (dependentModules[id] = Object.create(null));
565
+ const parentModules = Object.create(null);
566
+ const childModules = Object.create(null);
567
+ const getParentModules = (id) => parentModules[id] || (parentModules[id] = Object.create(null));
568
+ const getChildModules = (id) => childModules[id] || (childModules[id] = Object.create(null));
561
569
 
562
570
  return {
563
571
  getWrappedIds: () =>
@@ -587,7 +595,8 @@ function getResolveRequireSourcesAndGetMeta(extensions, detectCyclesAndCondition
587
595
  const resolved =
588
596
  (await rollupContext.resolve(source, parentId, {
589
597
  custom: {
590
- 'node-resolve': { isRequire: true }
598
+ 'node-resolve': { isRequire: true },
599
+ commonjs: { skipResolver: true }
591
600
  }
592
601
  })) || resolveExtensions(source, parentId, extensions);
593
602
  if (!resolved) {
@@ -606,20 +615,38 @@ function getResolveRequireSourcesAndGetMeta(extensions, detectCyclesAndCondition
606
615
  ) {
607
616
  unconditionallyRequiredIds[childId] = true;
608
617
  }
609
- const parentDependentModules = getDependentModules(parentId);
610
- const childDependentModules = getDependentModules(childId);
611
- childDependentModules[parentId] = true;
618
+ const parentDependentModules = getParentModules(parentId);
619
+ const childDependentModules = getParentModules(childId);
620
+
621
+ // Copy the parents of the current parent to the child
612
622
  for (const dependentId of Object.keys(parentDependentModules)) {
613
623
  childDependentModules[dependentId] = true;
614
624
  }
625
+
626
+ // Add the current parent to the child as well. If the child module already has known
627
+ // dependencies because it has already been loaded, add the current parent module to their
628
+ // parent modules
629
+ childDependentModules[parentId] = true;
630
+ const dependenciesToUpdate = new Set(Object.keys(getChildModules(childId)));
631
+ for (const dependencyId of dependenciesToUpdate) {
632
+ getParentModules(dependencyId)[parentId] = true;
633
+ for (const subDependencyId of Object.keys(getChildModules(dependencyId))) {
634
+ dependenciesToUpdate.add(subDependencyId);
635
+ }
636
+ }
637
+
638
+ // Add the child as a dependency to the parent
639
+ getChildModules(parentId)[childId] = true;
640
+
641
+ // If we depend on one of our dependencies, we have a cycle. Then all modules that
642
+ // we depend on that also depend on the same module are part of a cycle as well. Trying
643
+ // to wait for loading this module would lead to a deadlock.
615
644
  if (parentDependentModules[childId]) {
616
- // If we depend on one of our dependencies, we have a cycle. Then all modules that
617
- // we depend on that also depend on the same module are part of a cycle as well.
618
645
  if (detectCyclesAndConditional && isParentCommonJS) {
619
646
  knownCjsModuleTypes[parentId] = IS_WRAPPED_COMMONJS;
620
647
  knownCjsModuleTypes[childId] = IS_WRAPPED_COMMONJS;
621
648
  for (const dependentId of Object.keys(parentDependentModules)) {
622
- if (getDependentModules(dependentId)[childId]) {
649
+ if (getParentModules(dependentId)[childId]) {
623
650
  knownCjsModuleTypes[dependentId] = IS_WRAPPED_COMMONJS;
624
651
  }
625
652
  }