@antongolub/lockfile 0.0.0-snapshot.52 → 0.0.0-snapshot.53

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.
@@ -1329,6 +1329,14 @@ function resolutionPinUnresolvedDiagnostic(prefix, subject, depName, range) {
1329
1329
  message: `dependency ${depName}=${range} from ${subject} has no exact or semver-satisfying entry \u2014 likely a resolutions pin to a non-satisfying descriptor; pass ParseOptions.manifests so the override map can bridge it`
1330
1330
  };
1331
1331
  }
1332
+ function patchPreferredDiagnostic(prefix, subject, depName, range, patchId) {
1333
+ return {
1334
+ code: `${prefix}_PATCH_PREFERRED`,
1335
+ severity: "info",
1336
+ subject,
1337
+ message: `dependency ${depName}=${range} from ${subject} redirected to sibling patch node ${patchId} (lock-borne patchedDependencies preference); base left GC-able`
1338
+ };
1339
+ }
1332
1340
  function emitDropped(nodeId, feature, reason, onDiagnostic) {
1333
1341
  if (onDiagnostic === void 0) return;
1334
1342
  onDiagnostic({
@@ -1380,6 +1388,16 @@ function semverResolve(range, candidates) {
1380
1388
  if (top.length === 1) return { kind: "bound", id: top[0] };
1381
1389
  return { kind: "ambiguous", candidateIds: top };
1382
1390
  }
1391
+ function distTagResolve(range, candidates) {
1392
+ const tag = registryRangeOf(range);
1393
+ if (tag === void 0) return { kind: "none" };
1394
+ if (semver.validRange(tag) !== null) return { kind: "none" };
1395
+ const eligible = candidates.filter((c) => c.sourceType === "tarball");
1396
+ if (eligible.length === 0) return { kind: "none" };
1397
+ if (eligible.length === 1) return { kind: "bound", id: eligible[0].id };
1398
+ const ids = eligible.map((c) => c.id).sort(cmpStr2);
1399
+ return { kind: "ambiguous", candidateIds: ids };
1400
+ }
1383
1401
  function overrideTargetFor(depName, declaredRange, consumerPath, overrides) {
1384
1402
  let best;
1385
1403
  let bestScore = -1;
@@ -1412,6 +1430,15 @@ function parentPathMatches(parentPath, consumerPath) {
1412
1430
  }
1413
1431
  return true;
1414
1432
  }
1433
+ function patchPreferenceFor(_name, _version, patchSiblings, consumerLocator) {
1434
+ if (patchSiblings.length === 0) return void 0;
1435
+ if (patchSiblings.length === 1) return patchSiblings[0].id;
1436
+ if (consumerLocator !== void 0) {
1437
+ const matches = patchSiblings.filter((s) => s.locatorQualifier === consumerLocator);
1438
+ if (matches.length === 1) return matches[0].id;
1439
+ }
1440
+ return void 0;
1441
+ }
1415
1442
  var cmpStr2 = (a, b) => a < b ? -1 : a > b ? 1 : 0;
1416
1443
  function readInstalledManifest(workspaceRoot, parentName, consumerNodeId) {
1417
1444
  return readInstalledManifestFrom([workspaceRoot], parentName);
@@ -1552,6 +1579,7 @@ function parseFamily(input, options, config) {
1552
1579
  const specIndex = /* @__PURE__ */ new Map();
1553
1580
  const patchDescriptorIndex = /* @__PURE__ */ new Map();
1554
1581
  const semverCandidatesByName = /* @__PURE__ */ new Map();
1582
+ const patchSiblingsByBase = /* @__PURE__ */ new Map();
1555
1583
  const seenIds = /* @__PURE__ */ new Set();
1556
1584
  const entryIds = /* @__PURE__ */ new Map();
1557
1585
  for (const { key, value, specs } of entries) {
@@ -1617,6 +1645,13 @@ function parseFamily(input, options, config) {
1617
1645
  const candidateList = semverCandidatesByName.get(authoritativeName);
1618
1646
  if (candidateList === void 0) semverCandidatesByName.set(authoritativeName, [semverCandidate]);
1619
1647
  else candidateList.push(semverCandidate);
1648
+ if (effectivePatch !== void 0 && resolution !== void 0 && isNpmBasePatchResolution(resolution, authoritativeName)) {
1649
+ const sibling = { id, locatorQualifier: locatorQualifierOfPatchResolution(resolution) };
1650
+ const baseKey = `${authoritativeName}@${version}`;
1651
+ const siblings = patchSiblingsByBase.get(baseKey);
1652
+ if (siblings === void 0) patchSiblingsByBase.set(baseKey, [sibling]);
1653
+ else siblings.push(sibling);
1654
+ }
1620
1655
  const peerDependencies = stringRecordOfBlock(asMap(value["peerDependencies"]));
1621
1656
  if (peerDependencies !== void 0) {
1622
1657
  rawPeerDependencies.set(id, peerDependencies);
@@ -1680,6 +1715,7 @@ function parseFamily(input, options, config) {
1680
1715
  }
1681
1716
  const ladderCtx = {
1682
1717
  candidatesByName: semverCandidatesByName,
1718
+ patchSiblingsByBase,
1683
1719
  overrides: options.overrides ?? [],
1684
1720
  codePrefix: config.codePrefix,
1685
1721
  manifestsProvided: options.overrides !== void 0
@@ -2618,6 +2654,7 @@ function addEdgesFromBlock(builder, srcId, block, kind, index, patchDescriptorIn
2618
2654
  const normalizedRange = normalizedEdgeRange(kind, depRange);
2619
2655
  const lookup = `${depName}@${normalizedRange}`;
2620
2656
  let dstId = index.get(lookup);
2657
+ let boundViaOverride = false;
2621
2658
  if (dstId === void 0) {
2622
2659
  dstId = resolvePatchAndLinkFallbacks(
2623
2660
  lookup,
@@ -2647,7 +2684,10 @@ function addEdgesFromBlock(builder, srcId, block, kind, index, patchDescriptorIn
2647
2684
  );
2648
2685
  if (viaOverride === null) continue;
2649
2686
  }
2650
- if (viaOverride !== void 0) dstId = viaOverride;
2687
+ if (viaOverride !== void 0) {
2688
+ dstId = viaOverride;
2689
+ boundViaOverride = true;
2690
+ }
2651
2691
  }
2652
2692
  }
2653
2693
  if (dstId === void 0) {
@@ -2659,6 +2699,30 @@ function addEdgesFromBlock(builder, srcId, block, kind, index, patchDescriptorIn
2659
2699
  continue;
2660
2700
  }
2661
2701
  }
2702
+ if (dstId === void 0) {
2703
+ const result = distTagResolve(normalizedRange, ladder.candidatesByName.get(depName) ?? []);
2704
+ if (result.kind === "bound") {
2705
+ dstId = result.id;
2706
+ } else if (result.kind === "ambiguous") {
2707
+ diagnostics.push(ambiguousResolutionDiagnostic(ladder.codePrefix, srcId, depName, normalizedRange, result.candidateIds));
2708
+ if (!ladder.manifestsProvided) {
2709
+ diagnostics.push(resolutionPinUnresolvedDiagnostic(ladder.codePrefix, srcId, depName, normalizedRange));
2710
+ }
2711
+ continue;
2712
+ }
2713
+ }
2714
+ if (typeof dstId === "string" && !boundViaOverride && isRegistryRange(normalizedRange)) {
2715
+ const bound = nodeNameVersion(dstId);
2716
+ const siblings = bound === void 0 ? void 0 : ladder.patchSiblingsByBase.get(bound);
2717
+ if (siblings !== void 0 && siblings.length > 0) {
2718
+ const consumerLocator = srcResolution !== void 0 ? encodeURIComponent(srcResolution) : void 0;
2719
+ const patchId = patchPreferenceFor(depName, normalizedRange, siblings, consumerLocator);
2720
+ if (patchId !== void 0 && patchId !== dstId) {
2721
+ dstId = patchId;
2722
+ diagnostics.push(patchPreferredDiagnostic(ladder.codePrefix, srcId, depName, normalizedRange, patchId));
2723
+ }
2724
+ }
2725
+ }
2662
2726
  if (!dstId) {
2663
2727
  diagnostics.push({
2664
2728
  code: "YARN_BERRY_UNRESOLVED_DEP",
@@ -2681,6 +2745,16 @@ function normalizedEdgeRange(kind, range) {
2681
2745
  if (kind === "peer") return range;
2682
2746
  return hasExplicitProtocol(range) ? range : `npm:${range}`;
2683
2747
  }
2748
+ function nodeNameVersion(id) {
2749
+ const name = nameOf(id);
2750
+ if (name.length >= id.length) return void 0;
2751
+ let rest = id.slice(name.length + 1);
2752
+ const parenIdx = rest.indexOf("(");
2753
+ if (parenIdx >= 0) rest = rest.slice(0, parenIdx);
2754
+ const plusIdx = rest.indexOf("+");
2755
+ if (plusIdx >= 0) rest = rest.slice(0, plusIdx);
2756
+ return rest.length > 0 ? `${name}@${rest}` : void 0;
2757
+ }
2684
2758
  function hasExplicitProtocol(range) {
2685
2759
  const colonIdx = range.indexOf(":");
2686
2760
  if (colonIdx <= 0) return false;
@@ -2710,6 +2784,17 @@ function locatorQualifierOfPatchSpec(spec) {
2710
2784
  }
2711
2785
  return void 0;
2712
2786
  }
2787
+ function isNpmBasePatchResolution(resolution, name) {
2788
+ const locator = patchLocatorOfResolution(resolution);
2789
+ if (locator === void 0) return false;
2790
+ const base = baseSpecOfPatchLocator(locator);
2791
+ return base !== void 0 && base.startsWith(`${name}@npm:`);
2792
+ }
2793
+ function locatorQualifierOfPatchResolution(resolution) {
2794
+ const locator = patchLocatorOfResolution(resolution);
2795
+ if (locator === void 0 || !locator.startsWith("patch:")) return void 0;
2796
+ return locatorQualifierOfPatchSpec(locator.slice("patch:".length));
2797
+ }
2713
2798
  function resolvePatchDescriptor(candidates, srcResolution, srcId, lookup, diagnostics) {
2714
2799
  if (candidates === void 0 || candidates.length === 0) return void 0;
2715
2800
  if (candidates.length === 1) return candidates[0].id;
@@ -1329,6 +1329,14 @@ function resolutionPinUnresolvedDiagnostic(prefix, subject, depName, range) {
1329
1329
  message: `dependency ${depName}=${range} from ${subject} has no exact or semver-satisfying entry \u2014 likely a resolutions pin to a non-satisfying descriptor; pass ParseOptions.manifests so the override map can bridge it`
1330
1330
  };
1331
1331
  }
1332
+ function patchPreferredDiagnostic(prefix, subject, depName, range, patchId) {
1333
+ return {
1334
+ code: `${prefix}_PATCH_PREFERRED`,
1335
+ severity: "info",
1336
+ subject,
1337
+ message: `dependency ${depName}=${range} from ${subject} redirected to sibling patch node ${patchId} (lock-borne patchedDependencies preference); base left GC-able`
1338
+ };
1339
+ }
1332
1340
  function emitDropped(nodeId, feature, reason, onDiagnostic) {
1333
1341
  if (onDiagnostic === void 0) return;
1334
1342
  onDiagnostic({
@@ -1380,6 +1388,16 @@ function semverResolve(range, candidates) {
1380
1388
  if (top.length === 1) return { kind: "bound", id: top[0] };
1381
1389
  return { kind: "ambiguous", candidateIds: top };
1382
1390
  }
1391
+ function distTagResolve(range, candidates) {
1392
+ const tag = registryRangeOf(range);
1393
+ if (tag === void 0) return { kind: "none" };
1394
+ if (semver.validRange(tag) !== null) return { kind: "none" };
1395
+ const eligible = candidates.filter((c) => c.sourceType === "tarball");
1396
+ if (eligible.length === 0) return { kind: "none" };
1397
+ if (eligible.length === 1) return { kind: "bound", id: eligible[0].id };
1398
+ const ids = eligible.map((c) => c.id).sort(cmpStr2);
1399
+ return { kind: "ambiguous", candidateIds: ids };
1400
+ }
1383
1401
  function overrideTargetFor(depName, declaredRange, consumerPath, overrides) {
1384
1402
  let best;
1385
1403
  let bestScore = -1;
@@ -1412,6 +1430,15 @@ function parentPathMatches(parentPath, consumerPath) {
1412
1430
  }
1413
1431
  return true;
1414
1432
  }
1433
+ function patchPreferenceFor(_name, _version, patchSiblings, consumerLocator) {
1434
+ if (patchSiblings.length === 0) return void 0;
1435
+ if (patchSiblings.length === 1) return patchSiblings[0].id;
1436
+ if (consumerLocator !== void 0) {
1437
+ const matches = patchSiblings.filter((s) => s.locatorQualifier === consumerLocator);
1438
+ if (matches.length === 1) return matches[0].id;
1439
+ }
1440
+ return void 0;
1441
+ }
1415
1442
  var cmpStr2 = (a, b) => a < b ? -1 : a > b ? 1 : 0;
1416
1443
  function readInstalledManifest(workspaceRoot, parentName, consumerNodeId) {
1417
1444
  return readInstalledManifestFrom([workspaceRoot], parentName);
@@ -1552,6 +1579,7 @@ function parseFamily(input, options, config) {
1552
1579
  const specIndex = /* @__PURE__ */ new Map();
1553
1580
  const patchDescriptorIndex = /* @__PURE__ */ new Map();
1554
1581
  const semverCandidatesByName = /* @__PURE__ */ new Map();
1582
+ const patchSiblingsByBase = /* @__PURE__ */ new Map();
1555
1583
  const seenIds = /* @__PURE__ */ new Set();
1556
1584
  const entryIds = /* @__PURE__ */ new Map();
1557
1585
  for (const { key, value, specs } of entries) {
@@ -1617,6 +1645,13 @@ function parseFamily(input, options, config) {
1617
1645
  const candidateList = semverCandidatesByName.get(authoritativeName);
1618
1646
  if (candidateList === void 0) semverCandidatesByName.set(authoritativeName, [semverCandidate]);
1619
1647
  else candidateList.push(semverCandidate);
1648
+ if (effectivePatch !== void 0 && resolution !== void 0 && isNpmBasePatchResolution(resolution, authoritativeName)) {
1649
+ const sibling = { id, locatorQualifier: locatorQualifierOfPatchResolution(resolution) };
1650
+ const baseKey = `${authoritativeName}@${version}`;
1651
+ const siblings = patchSiblingsByBase.get(baseKey);
1652
+ if (siblings === void 0) patchSiblingsByBase.set(baseKey, [sibling]);
1653
+ else siblings.push(sibling);
1654
+ }
1620
1655
  const peerDependencies = stringRecordOfBlock(asMap(value["peerDependencies"]));
1621
1656
  if (peerDependencies !== void 0) {
1622
1657
  rawPeerDependencies.set(id, peerDependencies);
@@ -1680,6 +1715,7 @@ function parseFamily(input, options, config) {
1680
1715
  }
1681
1716
  const ladderCtx = {
1682
1717
  candidatesByName: semverCandidatesByName,
1718
+ patchSiblingsByBase,
1683
1719
  overrides: options.overrides ?? [],
1684
1720
  codePrefix: config.codePrefix,
1685
1721
  manifestsProvided: options.overrides !== void 0
@@ -2622,6 +2658,7 @@ function addEdgesFromBlock(builder, srcId, block, kind, index, patchDescriptorIn
2622
2658
  const normalizedRange = normalizedEdgeRange(kind, depRange);
2623
2659
  const lookup = `${depName}@${normalizedRange}`;
2624
2660
  let dstId = index.get(lookup);
2661
+ let boundViaOverride = false;
2625
2662
  if (dstId === void 0) {
2626
2663
  dstId = resolvePatchAndLinkFallbacks(
2627
2664
  lookup,
@@ -2651,7 +2688,10 @@ function addEdgesFromBlock(builder, srcId, block, kind, index, patchDescriptorIn
2651
2688
  );
2652
2689
  if (viaOverride === null) continue;
2653
2690
  }
2654
- if (viaOverride !== void 0) dstId = viaOverride;
2691
+ if (viaOverride !== void 0) {
2692
+ dstId = viaOverride;
2693
+ boundViaOverride = true;
2694
+ }
2655
2695
  }
2656
2696
  }
2657
2697
  if (dstId === void 0) {
@@ -2663,6 +2703,30 @@ function addEdgesFromBlock(builder, srcId, block, kind, index, patchDescriptorIn
2663
2703
  continue;
2664
2704
  }
2665
2705
  }
2706
+ if (dstId === void 0) {
2707
+ const result = distTagResolve(normalizedRange, ladder.candidatesByName.get(depName) ?? []);
2708
+ if (result.kind === "bound") {
2709
+ dstId = result.id;
2710
+ } else if (result.kind === "ambiguous") {
2711
+ diagnostics.push(ambiguousResolutionDiagnostic(ladder.codePrefix, srcId, depName, normalizedRange, result.candidateIds));
2712
+ if (!ladder.manifestsProvided) {
2713
+ diagnostics.push(resolutionPinUnresolvedDiagnostic(ladder.codePrefix, srcId, depName, normalizedRange));
2714
+ }
2715
+ continue;
2716
+ }
2717
+ }
2718
+ if (typeof dstId === "string" && !boundViaOverride && isRegistryRange(normalizedRange)) {
2719
+ const bound = nodeNameVersion(dstId);
2720
+ const siblings = bound === void 0 ? void 0 : ladder.patchSiblingsByBase.get(bound);
2721
+ if (siblings !== void 0 && siblings.length > 0) {
2722
+ const consumerLocator = srcResolution !== void 0 ? encodeURIComponent(srcResolution) : void 0;
2723
+ const patchId = patchPreferenceFor(depName, normalizedRange, siblings, consumerLocator);
2724
+ if (patchId !== void 0 && patchId !== dstId) {
2725
+ dstId = patchId;
2726
+ diagnostics.push(patchPreferredDiagnostic(ladder.codePrefix, srcId, depName, normalizedRange, patchId));
2727
+ }
2728
+ }
2729
+ }
2666
2730
  if (!dstId) {
2667
2731
  diagnostics.push({
2668
2732
  code: "YARN_BERRY_UNRESOLVED_DEP",
@@ -2685,6 +2749,16 @@ function normalizedEdgeRange(kind, range) {
2685
2749
  if (kind === "peer") return range;
2686
2750
  return hasExplicitProtocol(range) ? range : `npm:${range}`;
2687
2751
  }
2752
+ function nodeNameVersion(id) {
2753
+ const name = nameOf(id);
2754
+ if (name.length >= id.length) return void 0;
2755
+ let rest = id.slice(name.length + 1);
2756
+ const parenIdx = rest.indexOf("(");
2757
+ if (parenIdx >= 0) rest = rest.slice(0, parenIdx);
2758
+ const plusIdx = rest.indexOf("+");
2759
+ if (plusIdx >= 0) rest = rest.slice(0, plusIdx);
2760
+ return rest.length > 0 ? `${name}@${rest}` : void 0;
2761
+ }
2688
2762
  function hasExplicitProtocol(range) {
2689
2763
  const colonIdx = range.indexOf(":");
2690
2764
  if (colonIdx <= 0) return false;
@@ -2714,6 +2788,17 @@ function locatorQualifierOfPatchSpec(spec) {
2714
2788
  }
2715
2789
  return void 0;
2716
2790
  }
2791
+ function isNpmBasePatchResolution(resolution, name) {
2792
+ const locator = patchLocatorOfResolution(resolution);
2793
+ if (locator === void 0) return false;
2794
+ const base = baseSpecOfPatchLocator(locator);
2795
+ return base !== void 0 && base.startsWith(`${name}@npm:`);
2796
+ }
2797
+ function locatorQualifierOfPatchResolution(resolution) {
2798
+ const locator = patchLocatorOfResolution(resolution);
2799
+ if (locator === void 0 || !locator.startsWith("patch:")) return void 0;
2800
+ return locatorQualifierOfPatchSpec(locator.slice("patch:".length));
2801
+ }
2717
2802
  function resolvePatchDescriptor(candidates, srcResolution, srcId, lookup, diagnostics) {
2718
2803
  if (candidates === void 0 || candidates.length === 0) return void 0;
2719
2804
  if (candidates.length === 1) return candidates[0].id;
@@ -1329,6 +1329,14 @@ function resolutionPinUnresolvedDiagnostic(prefix, subject, depName, range) {
1329
1329
  message: `dependency ${depName}=${range} from ${subject} has no exact or semver-satisfying entry \u2014 likely a resolutions pin to a non-satisfying descriptor; pass ParseOptions.manifests so the override map can bridge it`
1330
1330
  };
1331
1331
  }
1332
+ function patchPreferredDiagnostic(prefix, subject, depName, range, patchId) {
1333
+ return {
1334
+ code: `${prefix}_PATCH_PREFERRED`,
1335
+ severity: "info",
1336
+ subject,
1337
+ message: `dependency ${depName}=${range} from ${subject} redirected to sibling patch node ${patchId} (lock-borne patchedDependencies preference); base left GC-able`
1338
+ };
1339
+ }
1332
1340
  function emitDropped(nodeId, feature, reason, onDiagnostic) {
1333
1341
  if (onDiagnostic === void 0) return;
1334
1342
  onDiagnostic({
@@ -1380,6 +1388,16 @@ function semverResolve(range, candidates) {
1380
1388
  if (top.length === 1) return { kind: "bound", id: top[0] };
1381
1389
  return { kind: "ambiguous", candidateIds: top };
1382
1390
  }
1391
+ function distTagResolve(range, candidates) {
1392
+ const tag = registryRangeOf(range);
1393
+ if (tag === void 0) return { kind: "none" };
1394
+ if (semver.validRange(tag) !== null) return { kind: "none" };
1395
+ const eligible = candidates.filter((c) => c.sourceType === "tarball");
1396
+ if (eligible.length === 0) return { kind: "none" };
1397
+ if (eligible.length === 1) return { kind: "bound", id: eligible[0].id };
1398
+ const ids = eligible.map((c) => c.id).sort(cmpStr2);
1399
+ return { kind: "ambiguous", candidateIds: ids };
1400
+ }
1383
1401
  function overrideTargetFor(depName, declaredRange, consumerPath, overrides) {
1384
1402
  let best;
1385
1403
  let bestScore = -1;
@@ -1412,6 +1430,15 @@ function parentPathMatches(parentPath, consumerPath) {
1412
1430
  }
1413
1431
  return true;
1414
1432
  }
1433
+ function patchPreferenceFor(_name, _version, patchSiblings, consumerLocator) {
1434
+ if (patchSiblings.length === 0) return void 0;
1435
+ if (patchSiblings.length === 1) return patchSiblings[0].id;
1436
+ if (consumerLocator !== void 0) {
1437
+ const matches = patchSiblings.filter((s) => s.locatorQualifier === consumerLocator);
1438
+ if (matches.length === 1) return matches[0].id;
1439
+ }
1440
+ return void 0;
1441
+ }
1415
1442
  var cmpStr2 = (a, b) => a < b ? -1 : a > b ? 1 : 0;
1416
1443
  function readInstalledManifest(workspaceRoot, parentName, consumerNodeId) {
1417
1444
  return readInstalledManifestFrom([workspaceRoot], parentName);
@@ -1552,6 +1579,7 @@ function parseFamily(input, options, config) {
1552
1579
  const specIndex = /* @__PURE__ */ new Map();
1553
1580
  const patchDescriptorIndex = /* @__PURE__ */ new Map();
1554
1581
  const semverCandidatesByName = /* @__PURE__ */ new Map();
1582
+ const patchSiblingsByBase = /* @__PURE__ */ new Map();
1555
1583
  const seenIds = /* @__PURE__ */ new Set();
1556
1584
  const entryIds = /* @__PURE__ */ new Map();
1557
1585
  for (const { key, value, specs } of entries) {
@@ -1617,6 +1645,13 @@ function parseFamily(input, options, config) {
1617
1645
  const candidateList = semverCandidatesByName.get(authoritativeName);
1618
1646
  if (candidateList === void 0) semverCandidatesByName.set(authoritativeName, [semverCandidate]);
1619
1647
  else candidateList.push(semverCandidate);
1648
+ if (effectivePatch !== void 0 && resolution !== void 0 && isNpmBasePatchResolution(resolution, authoritativeName)) {
1649
+ const sibling = { id, locatorQualifier: locatorQualifierOfPatchResolution(resolution) };
1650
+ const baseKey = `${authoritativeName}@${version}`;
1651
+ const siblings = patchSiblingsByBase.get(baseKey);
1652
+ if (siblings === void 0) patchSiblingsByBase.set(baseKey, [sibling]);
1653
+ else siblings.push(sibling);
1654
+ }
1620
1655
  const peerDependencies = stringRecordOfBlock(asMap(value["peerDependencies"]));
1621
1656
  if (peerDependencies !== void 0) {
1622
1657
  rawPeerDependencies.set(id, peerDependencies);
@@ -1680,6 +1715,7 @@ function parseFamily(input, options, config) {
1680
1715
  }
1681
1716
  const ladderCtx = {
1682
1717
  candidatesByName: semverCandidatesByName,
1718
+ patchSiblingsByBase,
1683
1719
  overrides: options.overrides ?? [],
1684
1720
  codePrefix: config.codePrefix,
1685
1721
  manifestsProvided: options.overrides !== void 0
@@ -2617,6 +2653,7 @@ function addEdgesFromBlock(builder, srcId, block, kind, index, patchDescriptorIn
2617
2653
  const normalizedRange = normalizedEdgeRange(kind, depRange);
2618
2654
  const lookup = `${depName}@${normalizedRange}`;
2619
2655
  let dstId = index.get(lookup);
2656
+ let boundViaOverride = false;
2620
2657
  if (dstId === void 0) {
2621
2658
  dstId = resolvePatchAndLinkFallbacks(
2622
2659
  lookup,
@@ -2646,7 +2683,10 @@ function addEdgesFromBlock(builder, srcId, block, kind, index, patchDescriptorIn
2646
2683
  );
2647
2684
  if (viaOverride === null) continue;
2648
2685
  }
2649
- if (viaOverride !== void 0) dstId = viaOverride;
2686
+ if (viaOverride !== void 0) {
2687
+ dstId = viaOverride;
2688
+ boundViaOverride = true;
2689
+ }
2650
2690
  }
2651
2691
  }
2652
2692
  if (dstId === void 0) {
@@ -2658,6 +2698,30 @@ function addEdgesFromBlock(builder, srcId, block, kind, index, patchDescriptorIn
2658
2698
  continue;
2659
2699
  }
2660
2700
  }
2701
+ if (dstId === void 0) {
2702
+ const result = distTagResolve(normalizedRange, ladder.candidatesByName.get(depName) ?? []);
2703
+ if (result.kind === "bound") {
2704
+ dstId = result.id;
2705
+ } else if (result.kind === "ambiguous") {
2706
+ diagnostics.push(ambiguousResolutionDiagnostic(ladder.codePrefix, srcId, depName, normalizedRange, result.candidateIds));
2707
+ if (!ladder.manifestsProvided) {
2708
+ diagnostics.push(resolutionPinUnresolvedDiagnostic(ladder.codePrefix, srcId, depName, normalizedRange));
2709
+ }
2710
+ continue;
2711
+ }
2712
+ }
2713
+ if (typeof dstId === "string" && !boundViaOverride && isRegistryRange(normalizedRange)) {
2714
+ const bound = nodeNameVersion(dstId);
2715
+ const siblings = bound === void 0 ? void 0 : ladder.patchSiblingsByBase.get(bound);
2716
+ if (siblings !== void 0 && siblings.length > 0) {
2717
+ const consumerLocator = srcResolution !== void 0 ? encodeURIComponent(srcResolution) : void 0;
2718
+ const patchId = patchPreferenceFor(depName, normalizedRange, siblings, consumerLocator);
2719
+ if (patchId !== void 0 && patchId !== dstId) {
2720
+ dstId = patchId;
2721
+ diagnostics.push(patchPreferredDiagnostic(ladder.codePrefix, srcId, depName, normalizedRange, patchId));
2722
+ }
2723
+ }
2724
+ }
2661
2725
  if (!dstId) {
2662
2726
  diagnostics.push({
2663
2727
  code: "YARN_BERRY_UNRESOLVED_DEP",
@@ -2680,6 +2744,16 @@ function normalizedEdgeRange(kind, range) {
2680
2744
  if (kind === "peer") return range;
2681
2745
  return hasExplicitProtocol(range) ? range : `npm:${range}`;
2682
2746
  }
2747
+ function nodeNameVersion(id) {
2748
+ const name = nameOf(id);
2749
+ if (name.length >= id.length) return void 0;
2750
+ let rest = id.slice(name.length + 1);
2751
+ const parenIdx = rest.indexOf("(");
2752
+ if (parenIdx >= 0) rest = rest.slice(0, parenIdx);
2753
+ const plusIdx = rest.indexOf("+");
2754
+ if (plusIdx >= 0) rest = rest.slice(0, plusIdx);
2755
+ return rest.length > 0 ? `${name}@${rest}` : void 0;
2756
+ }
2683
2757
  function hasExplicitProtocol(range) {
2684
2758
  const colonIdx = range.indexOf(":");
2685
2759
  if (colonIdx <= 0) return false;
@@ -2709,6 +2783,17 @@ function locatorQualifierOfPatchSpec(spec) {
2709
2783
  }
2710
2784
  return void 0;
2711
2785
  }
2786
+ function isNpmBasePatchResolution(resolution, name) {
2787
+ const locator = patchLocatorOfResolution(resolution);
2788
+ if (locator === void 0) return false;
2789
+ const base = baseSpecOfPatchLocator(locator);
2790
+ return base !== void 0 && base.startsWith(`${name}@npm:`);
2791
+ }
2792
+ function locatorQualifierOfPatchResolution(resolution) {
2793
+ const locator = patchLocatorOfResolution(resolution);
2794
+ if (locator === void 0 || !locator.startsWith("patch:")) return void 0;
2795
+ return locatorQualifierOfPatchSpec(locator.slice("patch:".length));
2796
+ }
2712
2797
  function resolvePatchDescriptor(candidates, srcResolution, srcId, lookup, diagnostics) {
2713
2798
  if (candidates === void 0 || candidates.length === 0) return void 0;
2714
2799
  if (candidates.length === 1) return candidates[0].id;
@@ -1329,6 +1329,14 @@ function resolutionPinUnresolvedDiagnostic(prefix, subject, depName, range) {
1329
1329
  message: `dependency ${depName}=${range} from ${subject} has no exact or semver-satisfying entry \u2014 likely a resolutions pin to a non-satisfying descriptor; pass ParseOptions.manifests so the override map can bridge it`
1330
1330
  };
1331
1331
  }
1332
+ function patchPreferredDiagnostic(prefix, subject, depName, range, patchId) {
1333
+ return {
1334
+ code: `${prefix}_PATCH_PREFERRED`,
1335
+ severity: "info",
1336
+ subject,
1337
+ message: `dependency ${depName}=${range} from ${subject} redirected to sibling patch node ${patchId} (lock-borne patchedDependencies preference); base left GC-able`
1338
+ };
1339
+ }
1332
1340
  function emitDropped(nodeId, feature, reason, onDiagnostic) {
1333
1341
  if (onDiagnostic === void 0) return;
1334
1342
  onDiagnostic({
@@ -1380,6 +1388,16 @@ function semverResolve(range, candidates) {
1380
1388
  if (top.length === 1) return { kind: "bound", id: top[0] };
1381
1389
  return { kind: "ambiguous", candidateIds: top };
1382
1390
  }
1391
+ function distTagResolve(range, candidates) {
1392
+ const tag = registryRangeOf(range);
1393
+ if (tag === void 0) return { kind: "none" };
1394
+ if (semver.validRange(tag) !== null) return { kind: "none" };
1395
+ const eligible = candidates.filter((c) => c.sourceType === "tarball");
1396
+ if (eligible.length === 0) return { kind: "none" };
1397
+ if (eligible.length === 1) return { kind: "bound", id: eligible[0].id };
1398
+ const ids = eligible.map((c) => c.id).sort(cmpStr2);
1399
+ return { kind: "ambiguous", candidateIds: ids };
1400
+ }
1383
1401
  function overrideTargetFor(depName, declaredRange, consumerPath, overrides) {
1384
1402
  let best;
1385
1403
  let bestScore = -1;
@@ -1412,6 +1430,15 @@ function parentPathMatches(parentPath, consumerPath) {
1412
1430
  }
1413
1431
  return true;
1414
1432
  }
1433
+ function patchPreferenceFor(_name, _version, patchSiblings, consumerLocator) {
1434
+ if (patchSiblings.length === 0) return void 0;
1435
+ if (patchSiblings.length === 1) return patchSiblings[0].id;
1436
+ if (consumerLocator !== void 0) {
1437
+ const matches = patchSiblings.filter((s) => s.locatorQualifier === consumerLocator);
1438
+ if (matches.length === 1) return matches[0].id;
1439
+ }
1440
+ return void 0;
1441
+ }
1415
1442
  var cmpStr2 = (a, b) => a < b ? -1 : a > b ? 1 : 0;
1416
1443
  function readInstalledManifest(workspaceRoot, parentName, consumerNodeId) {
1417
1444
  return readInstalledManifestFrom([workspaceRoot], parentName);
@@ -1552,6 +1579,7 @@ function parseFamily(input, options, config) {
1552
1579
  const specIndex = /* @__PURE__ */ new Map();
1553
1580
  const patchDescriptorIndex = /* @__PURE__ */ new Map();
1554
1581
  const semverCandidatesByName = /* @__PURE__ */ new Map();
1582
+ const patchSiblingsByBase = /* @__PURE__ */ new Map();
1555
1583
  const seenIds = /* @__PURE__ */ new Set();
1556
1584
  const entryIds = /* @__PURE__ */ new Map();
1557
1585
  for (const { key, value, specs } of entries) {
@@ -1617,6 +1645,13 @@ function parseFamily(input, options, config) {
1617
1645
  const candidateList = semverCandidatesByName.get(authoritativeName);
1618
1646
  if (candidateList === void 0) semverCandidatesByName.set(authoritativeName, [semverCandidate]);
1619
1647
  else candidateList.push(semverCandidate);
1648
+ if (effectivePatch !== void 0 && resolution !== void 0 && isNpmBasePatchResolution(resolution, authoritativeName)) {
1649
+ const sibling = { id, locatorQualifier: locatorQualifierOfPatchResolution(resolution) };
1650
+ const baseKey = `${authoritativeName}@${version}`;
1651
+ const siblings = patchSiblingsByBase.get(baseKey);
1652
+ if (siblings === void 0) patchSiblingsByBase.set(baseKey, [sibling]);
1653
+ else siblings.push(sibling);
1654
+ }
1620
1655
  const peerDependencies = stringRecordOfBlock(asMap(value["peerDependencies"]));
1621
1656
  if (peerDependencies !== void 0) {
1622
1657
  rawPeerDependencies.set(id, peerDependencies);
@@ -1680,6 +1715,7 @@ function parseFamily(input, options, config) {
1680
1715
  }
1681
1716
  const ladderCtx = {
1682
1717
  candidatesByName: semverCandidatesByName,
1718
+ patchSiblingsByBase,
1683
1719
  overrides: options.overrides ?? [],
1684
1720
  codePrefix: config.codePrefix,
1685
1721
  manifestsProvided: options.overrides !== void 0
@@ -2617,6 +2653,7 @@ function addEdgesFromBlock(builder, srcId, block, kind, index, patchDescriptorIn
2617
2653
  const normalizedRange = normalizedEdgeRange(kind, depRange);
2618
2654
  const lookup = `${depName}@${normalizedRange}`;
2619
2655
  let dstId = index.get(lookup);
2656
+ let boundViaOverride = false;
2620
2657
  if (dstId === void 0) {
2621
2658
  dstId = resolvePatchAndLinkFallbacks(
2622
2659
  lookup,
@@ -2646,7 +2683,10 @@ function addEdgesFromBlock(builder, srcId, block, kind, index, patchDescriptorIn
2646
2683
  );
2647
2684
  if (viaOverride === null) continue;
2648
2685
  }
2649
- if (viaOverride !== void 0) dstId = viaOverride;
2686
+ if (viaOverride !== void 0) {
2687
+ dstId = viaOverride;
2688
+ boundViaOverride = true;
2689
+ }
2650
2690
  }
2651
2691
  }
2652
2692
  if (dstId === void 0) {
@@ -2658,6 +2698,30 @@ function addEdgesFromBlock(builder, srcId, block, kind, index, patchDescriptorIn
2658
2698
  continue;
2659
2699
  }
2660
2700
  }
2701
+ if (dstId === void 0) {
2702
+ const result = distTagResolve(normalizedRange, ladder.candidatesByName.get(depName) ?? []);
2703
+ if (result.kind === "bound") {
2704
+ dstId = result.id;
2705
+ } else if (result.kind === "ambiguous") {
2706
+ diagnostics.push(ambiguousResolutionDiagnostic(ladder.codePrefix, srcId, depName, normalizedRange, result.candidateIds));
2707
+ if (!ladder.manifestsProvided) {
2708
+ diagnostics.push(resolutionPinUnresolvedDiagnostic(ladder.codePrefix, srcId, depName, normalizedRange));
2709
+ }
2710
+ continue;
2711
+ }
2712
+ }
2713
+ if (typeof dstId === "string" && !boundViaOverride && isRegistryRange(normalizedRange)) {
2714
+ const bound = nodeNameVersion(dstId);
2715
+ const siblings = bound === void 0 ? void 0 : ladder.patchSiblingsByBase.get(bound);
2716
+ if (siblings !== void 0 && siblings.length > 0) {
2717
+ const consumerLocator = srcResolution !== void 0 ? encodeURIComponent(srcResolution) : void 0;
2718
+ const patchId = patchPreferenceFor(depName, normalizedRange, siblings, consumerLocator);
2719
+ if (patchId !== void 0 && patchId !== dstId) {
2720
+ dstId = patchId;
2721
+ diagnostics.push(patchPreferredDiagnostic(ladder.codePrefix, srcId, depName, normalizedRange, patchId));
2722
+ }
2723
+ }
2724
+ }
2661
2725
  if (!dstId) {
2662
2726
  diagnostics.push({
2663
2727
  code: "YARN_BERRY_UNRESOLVED_DEP",
@@ -2680,6 +2744,16 @@ function normalizedEdgeRange(kind, range) {
2680
2744
  if (kind === "peer") return range;
2681
2745
  return hasExplicitProtocol(range) ? range : `npm:${range}`;
2682
2746
  }
2747
+ function nodeNameVersion(id) {
2748
+ const name = nameOf(id);
2749
+ if (name.length >= id.length) return void 0;
2750
+ let rest = id.slice(name.length + 1);
2751
+ const parenIdx = rest.indexOf("(");
2752
+ if (parenIdx >= 0) rest = rest.slice(0, parenIdx);
2753
+ const plusIdx = rest.indexOf("+");
2754
+ if (plusIdx >= 0) rest = rest.slice(0, plusIdx);
2755
+ return rest.length > 0 ? `${name}@${rest}` : void 0;
2756
+ }
2683
2757
  function hasExplicitProtocol(range) {
2684
2758
  const colonIdx = range.indexOf(":");
2685
2759
  if (colonIdx <= 0) return false;
@@ -2709,6 +2783,17 @@ function locatorQualifierOfPatchSpec(spec) {
2709
2783
  }
2710
2784
  return void 0;
2711
2785
  }
2786
+ function isNpmBasePatchResolution(resolution, name) {
2787
+ const locator = patchLocatorOfResolution(resolution);
2788
+ if (locator === void 0) return false;
2789
+ const base = baseSpecOfPatchLocator(locator);
2790
+ return base !== void 0 && base.startsWith(`${name}@npm:`);
2791
+ }
2792
+ function locatorQualifierOfPatchResolution(resolution) {
2793
+ const locator = patchLocatorOfResolution(resolution);
2794
+ if (locator === void 0 || !locator.startsWith("patch:")) return void 0;
2795
+ return locatorQualifierOfPatchSpec(locator.slice("patch:".length));
2796
+ }
2712
2797
  function resolvePatchDescriptor(candidates, srcResolution, srcId, lookup, diagnostics) {
2713
2798
  if (candidates === void 0 || candidates.length === 0) return void 0;
2714
2799
  if (candidates.length === 1) return candidates[0].id;