Repository navigation
refactor(registries): give the known-registry set one owner - #13591
Conversation
The built-in aliases and the user's `namedRegistries` were combined independently at each place that needed them: `resolveNamedRegistries` in constants, a second call inside the same verifier factory to build the URL prefix list, and in pacquet a hand-rolled `chain` next to a separate `build_named_registry_prefixes`. The Rust pair had already drifted — the hand-rolled merge skipped the URL validation the other applied. That set feeds two different consumers: alias lookup for an entry that names its registry in the dep path, and the tarball-URL prefix list that decides which registry an entry carrying only a recorded URL is verified against. Splitting the merge across call sites is what made adding the `npmjs` built-in look local while it silently redirected verification traffic for lockfiles that record a registry.npmjs.org URL and name no alias at all. That consequence was caught by an unrelated normalization test that happened to use such a URL, not by anything at the edit site. `KnownRegistries` now owns the merge and exposes both views, so a change to either input reaches both consumers or neither. `createKnownRegistries` computes the prefixes lazily because alias lookup runs per package while prefix matching runs only for entries with a recorded URL. Both stacks now pin the default prefix list in a test, so a new built-in cannot land without stating where it sends verification traffic. Writing that test surfaced a latent bug: the two built-in URLs are both 27 characters, and sorting by length alone left their relative order to hash-map iteration, which varies between runs. The sort now tie-breaks lexicographically in both stacks. No routing outcome changes — two prefixes of equal length cannot both match one URL unless they are identical — but the list is now stable enough to assert on. Closes #13590
…switch The rename from resolveNamedRegistries to createKnownRegistries changed the alphabetical order within the import, which simple-import-sort enforces.
build_named_registry_prefixes no longer exists; the prefix list is now reached through KnownRegistries::tarball_prefixes. Caught by the pre-push rustdoc gate.
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThe change centralizes named-registry normalization, alias lookup, and tarball-prefix generation in TypeScript and Rust. Resolver, lockfile, SBOM, and verification paths now use shared registry maps. Prefix matching uses longest-prefix ordering with deterministic lexicographic tie-breaking. ChangesKnown registry consolidation
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant ConfigReader
participant normalizeNamedRegistries
participant namedRegistryTarballPrefixes
participant ResolutionVerifier
participant RegistrySelector
ConfigReader->>normalizeNamedRegistries: normalize built-in and user aliases
normalizeNamedRegistries-->>ResolutionVerifier: provide alias-to-URL map
normalizeNamedRegistries->>namedRegistryTarballPrefixes: provide normalized registry map
namedRegistryTarballPrefixes-->>ResolutionVerifier: provide ordered URL prefixes
ResolutionVerifier->>RegistrySelector: match lockfile tarball URL
RegistrySelector-->>ResolutionVerifier: select registry for verification
Assessment against linked issues
Possibly related PRs
Suggested labels: Suggested reviewers: ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
PR Summary by QodoUnify named-registry merge via KnownRegistries and stabilize tarball prefix ordering
AI Description
Diagram
High-Level Assessment
Files changed (11)
|
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains. Reviews (9): Last reviewed commit: "chore(registries): drop the diff this re..." | Re-trigger Greptile |
Code Review by Qodo
Context used✅ Compliance rules (platform):
24 rules 1.
|
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@pnpm/crates/resolving-npm-resolver/src/named_registry.rs`:
- Around line 126-135: Make KnownRegistries::new fallible and validate every
built-in and supplied registry entry before inserting it into by_alias; reject
invalid aliases and non-HTTP(S) URLs using the existing validation/error types
rather than silently retaining raw data. Build both by_alias and
tarball_prefixes from the same validated registry set, and update
create_npm_resolution_verifier and any callers to propagate the construction
error instead of bypassing merge validation.
In `@pnpm/crates/resolving-npm-resolver/src/named_registry/tests.rs`:
- Line 63: Add an assertion in the existing KnownRegistries tarball-prefix test
covering two registry URLs with equal-length prefixes, and verify they are
ordered lexicographically. Keep the existing different-length coverage and
ensure the expected sequence demonstrates deterministic longest-prefix ordering
rather than HashMap iteration order.
In `@pnpm11/deps/compliance/sbom/src/collectComponents.ts`:
- Around line 216-218: Reuse one KnownRegistries instance per install: in
pnpm11/deps/compliance/sbom/src/collectComponents.ts lines 216-218, hoist
createKnownRegistries(opts.namedRegistries) to collectSbomComponents and pass
its byAlias through walkStep instead of rebuilding it per dependency; in
pnpm11/lockfile/utils/src/pkgSnapshotToResolution.ts line 52, extend
PkgSnapshotToResolutionOptions with an optional precomputed alias map or
KnownRegistries, using createKnownRegistries(opts.namedRegistries) only when
none is supplied, so collectComponents.ts can reuse the shared instance.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: e7304e70-277c-4079-9fa2-974590b9bc40
📒 Files selected for processing (11)
.changeset/known-registries-single-owner.mdpnpm/crates/resolving-npm-resolver/src/create_npm_resolution_verifier.rspnpm/crates/resolving-npm-resolver/src/lib.rspnpm/crates/resolving-npm-resolver/src/named_registry.rspnpm/crates/resolving-npm-resolver/src/named_registry/tests.rspnpm11/core/constants/src/index.tspnpm11/deps/compliance/sbom/src/collectComponents.tspnpm11/installing/deps-resolver/src/updateLockfile.tspnpm11/lockfile/utils/src/pkgSnapshotToResolution.tspnpm11/resolving/npm-resolver/src/createNpmResolutionVerifier.tspnpm11/resolving/npm-resolver/test/knownRegistries.test.ts
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
Micro-Benchmark ResultsLinux |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #13591 +/- ##
==========================================
+ Coverage 87.98% 87.99% +0.01%
==========================================
Files 565 567 +2
Lines 97856 97936 +80
==========================================
+ Hits 86101 86182 +81
+ Misses 11755 11754 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
`@pnpm/constants` holds constants. `createKnownRegistries` is a factory that parses URLs, normalizes paths, sorts, and memoizes — none of which the package name leads a reader to expect. `BUILTIN_NAMED_REGISTRIES` stays, since that genuinely is one. `@pnpm/config.pick-registry-for-package` is the natural home: its whole job is deciding which registry a package comes from, and the known-registry set is the input to that decision. Scope-based selection (`pickRegistryForPackage`) and alias-based selection now sit together, which also matches pacquet, where `KnownRegistries` already lives beside `pick_registry_for_package` and `pick_registry_for_version` in `named_registry.rs`. The pinning test moves with the code it covers.
|
Moved
It now lives in Costs three new workspace deps ( All suites re-run green after the move: Written by an agent (Claude Code, claude-opus-5). |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
pnpm11/config/pick-registry-for-package/test/knownRegistries.test.ts (1)
37-47: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick winAdd a deterministic tie-break test.
The test verifies descending prefix length only. It does not verify lexicographic ordering when two prefixes have equal length.
Add two same-length registry paths and assert their exact order. This protects the
a < b ? -1 : a > b ? 1 : 0contract.Proposed test addition
test('prefixes are ordered longest first so the deepest match wins', () => { const { tarballPrefixes } = createKnownRegistries({ team: 'https://npm.example/team', teamSub: 'https://npm.example/team/sub', + tieA: 'https://npm.example/a', + tieB: 'https://npm.example/b', }) const lengths = tarballPrefixes.map((prefix) => prefix.length) expect(lengths).toStrictEqual([...lengths].sort((a, b) => b - a)) expect(tarballPrefixes.indexOf('https://npm.example/team/sub/')) .toBeLessThan(tarballPrefixes.indexOf('https://npm.example/team/')) + expect(tarballPrefixes.filter((prefix) => + prefix === 'https://npm.example/a/' || prefix === 'https://npm.example/b/' + )).toStrictEqual([ + 'https://npm.example/a/', + 'https://npm.example/b/', + ]) })As per path instructions, add focused tests for deterministic ties.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@pnpm11/config/pick-registry-for-package/test/knownRegistries.test.ts` around lines 37 - 47, Add a focused test alongside “prefixes are ordered longest first so the deepest match wins” using two registry paths with equal-length prefixes, then assert the complete tarballPrefixes order matches lexicographic ascending order. Keep the existing longest-prefix assertions unchanged and target the ordering behavior implemented by createKnownRegistries.Source: Path instructions
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@pnpm11/config/pick-registry-for-package/test/knownRegistries.test.ts`:
- Around line 37-47: Add a focused test alongside “prefixes are ordered longest
first so the deepest match wins” using two registry paths with equal-length
prefixes, then assert the complete tarballPrefixes order matches lexicographic
ascending order. Keep the existing longest-prefix assertions unchanged and
target the ordering behavior implemented by createKnownRegistries.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 8b32ac90-1ab0-45ec-81e0-f1cf2acd3eb4
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml,!pnpm-lock.yaml
📒 Files selected for processing (16)
.changeset/known-registries-single-owner.mdpnpm11/config/pick-registry-for-package/package.jsonpnpm11/config/pick-registry-for-package/src/index.tspnpm11/config/pick-registry-for-package/test/knownRegistries.test.tspnpm11/config/pick-registry-for-package/tsconfig.jsonpnpm11/core/constants/src/index.tspnpm11/deps/compliance/sbom/package.jsonpnpm11/deps/compliance/sbom/src/collectComponents.tspnpm11/deps/compliance/sbom/tsconfig.jsonpnpm11/installing/deps-resolver/package.jsonpnpm11/installing/deps-resolver/src/updateLockfile.tspnpm11/installing/deps-resolver/tsconfig.jsonpnpm11/lockfile/utils/package.jsonpnpm11/lockfile/utils/src/pkgSnapshotToResolution.tspnpm11/lockfile/utils/tsconfig.jsonpnpm11/resolving/npm-resolver/src/createNpmResolutionVerifier.ts
💤 Files with no reviewable changes (1)
- pnpm11/core/constants/src/index.ts
🚧 Files skipped from review as they are similar to previous changes (5)
- .changeset/known-registries-single-owner.md
- pnpm11/lockfile/utils/src/pkgSnapshotToResolution.ts
- pnpm11/installing/deps-resolver/src/updateLockfile.ts
- pnpm11/resolving/npm-resolver/src/createNpmResolutionVerifier.ts
- pnpm11/deps/compliance/sbom/src/collectComponents.ts
|
Code review by qodo was updated up to the latest commit b585229 |
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
`createKnownRegistries` had no business knowing the built-ins. `registries` already showed the right shape: `normalizeRegistries` fills in the defaults — `@jsr` included — once at the boundary, and everything downstream just indexes a complete map. `namedRegistries` skipped that step, so every consumer that resolved an alias had to remember to merge the built-ins at lookup time. `normalizeNamedRegistries` now sits beside `normalizeRegistries`, and the config reader applies it where `registries` gets its defaults, so `config.namedRegistries` arrives complete. The risk in moving a merge from the lookup to the boundary is that it fails open: miss one entry point and `gh:` and `npmjs:` silently stop resolving there. So the guarantee is carried by the type, exactly as `Registries` does it with its required `default`. `NamedRegistries` requires `gh` and `npmjs`, which means a raw config map cannot reach a consumer without passing through the normalizer, and a missed boundary is a compile error rather than a runtime regression. Adding a built-in now means widening the type — the same acknowledgement the reverse-routing prefix test asks for. `Config.namedRegistries` stays optional. Making it required is the stronger statement but it invalidates every hand-built `Config` in the test suite — 574 errors, almost all fixtures — for no gain the type does not already give at the consumer boundary. pacquet already had this shape: `merge_named_registries` is the normalizer and runs at the entry points. Its verifier was the exception, taking the raw user map and re-merging internally, so it now receives an already-merged one like every other consumer.
|
Done in 17de458 —
How the fail-open risk is handledMoving a merge from the lookup to the boundary fails open — miss one entry point and export interface NamedRegistries {
gh: string
npmjs: string
[alias: string]: string
}A raw config map cannot reach a consumer without passing through the normalizer, so a missed boundary is a compile error rather than a runtime regression. Adding a built-in now means widening the type — the same acknowledgement the reverse-routing prefix test asks for. The compiler found the boundaries for me: 21 option declarations retyped, and it pointed at exactly the four production call sites plus the test fixtures constructing partial maps. One thing I did not do
pacquetIt already had this shape — VerificationTypeScript: One behavioural note now pinned by a test: Written by an agent (Claude Code, claude-opus-5). |
|
Code review by qodo was updated up to the latest commit 17de458 |
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (1)
pnpm/crates/package-manager/src/build_resolution_verifiers.rs (1)
113-118: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick winRemove the intermediate
HashMapallocation.
KnownRegistries::newaccepts a borrowedHashMap<String, String>. The current code clones every key and URL into a temporary map, then clones them again insideKnownRegistries::new. Pass&config.named_registriesdirectly when the field uses the same map type.Proposed simplification
- named_registries: KnownRegistries::new( - &config - .named_registries - .iter() - .map(|(name, url)| (name.clone(), url.clone())) - .collect(), - ) + named_registries: KnownRegistries::new(&config.named_registries) .into_by_alias(),As per coding guidelines, choose borrowed parameters to minimize copies. As per path instructions, Rust registry code should prefer borrowed parameters unless ownership avoids copying.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@pnpm/crates/package-manager/src/build_resolution_verifiers.rs` around lines 113 - 118, Update the named_registries argument to KnownRegistries::new to pass a reference to config.named_registries directly, removing the iterator, key/URL clones, and temporary HashMap allocation while preserving the existing behavior.Sources: Coding guidelines, Path instructions
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@pnpm/crates/package-manager/src/build_resolution_verifiers.rs`:
- Around line 109-120: Validate every configured named registry URL and alias
while constructing Config or PackageManagerVerifierOptions, before the
named_registries map reaches KnownRegistries::new(...).into_by_alias() in build
resolution verification. Reuse merge_named_registries() or the existing
validation logic so malformed aliases and URLs are rejected consistently, while
preserving the verifier’s current registry merge behavior.
In `@pnpm11/config/reader/src/index.ts`:
- Around line 358-360: Move the normalizeNamedRegistries call out of the current
defaults setup and into the final Config-to-install-options normalization
section, after addSettingsFromWorkspaceManifestToConfig and all registry
overlays have been applied. Ensure the final namedRegistries map retains
built-in aliases such as gh and npmjs even when workspace settings replace the
merged value.
In `@pnpm11/lockfile/utils/src/pkgSnapshotToResolution.ts`:
- Line 53: Update pkgSnapshotToResolution and its callers so KnownRegistries is
constructed once by the owning resolver or traversal and passed through the
options for every snapshot resolution; replace the per-call
createKnownRegistries invocation and reuse the shared instance for
named-registry alias lookups across dependency, SBOM, license, inspection, and
hoisting flows.
---
Nitpick comments:
In `@pnpm/crates/package-manager/src/build_resolution_verifiers.rs`:
- Around line 113-118: Update the named_registries argument to
KnownRegistries::new to pass a reference to config.named_registries directly,
removing the iterator, key/URL clones, and temporary HashMap allocation while
preserving the existing behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 31a86033-8351-4762-b806-89b6122d47e7
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml,!pnpm-lock.yaml
📒 Files selected for processing (54)
.changeset/known-registries-single-owner.mdpnpm/crates/package-manager/src/build_resolution_verifiers.rspnpm/crates/resolving-npm-resolver/src/named_registry.rspnpm11/config/normalize-registries/package.jsonpnpm11/config/normalize-registries/src/index.tspnpm11/config/normalize-registries/tsconfig.jsonpnpm11/config/pick-registry-for-package/package.jsonpnpm11/config/pick-registry-for-package/src/index.tspnpm11/config/pick-registry-for-package/test/knownRegistries.test.tspnpm11/config/pick-registry-for-package/tsconfig.jsonpnpm11/config/reader/package.jsonpnpm11/config/reader/src/Config.tspnpm11/config/reader/src/index.tspnpm11/config/reader/test/index.tspnpm11/config/reader/tsconfig.jsonpnpm11/core/types/src/misc.tspnpm11/core/types/src/package.tspnpm11/deps/compliance/license-scanner/package.jsonpnpm11/deps/compliance/license-scanner/src/getPkgInfo.tspnpm11/deps/compliance/license-scanner/src/licenses.tspnpm11/deps/compliance/license-scanner/src/lockfileToLicenseNodeTree.tspnpm11/deps/compliance/license-scanner/test/licenses.spec.tspnpm11/deps/compliance/license-scanner/tsconfig.jsonpnpm11/deps/compliance/sbom/package.jsonpnpm11/deps/compliance/sbom/src/collectComponents.tspnpm11/deps/compliance/sbom/test/collectComponents.test.tspnpm11/deps/compliance/sbom/tsconfig.jsonpnpm11/deps/graph-builder/src/lockfileToDepGraph.tspnpm11/deps/inspection/list/src/index.tspnpm11/deps/inspection/tree-builder/src/buildDependenciesTree.tspnpm11/deps/inspection/tree-builder/src/buildDependentsTree.tspnpm11/deps/inspection/tree-builder/src/getPkgInfo.tspnpm11/deps/inspection/tree-builder/src/getTree.tspnpm11/installing/deps-installer/src/install/extendInstallOptions.tspnpm11/installing/deps-resolver/package.jsonpnpm11/installing/deps-resolver/src/resolveDependencies.tspnpm11/installing/deps-resolver/src/resolveDependencyTree.tspnpm11/installing/deps-resolver/src/updateLockfile.tspnpm11/installing/deps-resolver/tsconfig.jsonpnpm11/installing/deps-restorer/src/index.tspnpm11/installing/deps-restorer/src/lockfileToHoistedDepGraph.tspnpm11/lockfile/utils/package.jsonpnpm11/lockfile/utils/src/pkgSnapshotToResolution.tspnpm11/lockfile/utils/test/pkgSnapshotToResolution.tspnpm11/lockfile/utils/tsconfig.jsonpnpm11/resolving/default-resolver/package.jsonpnpm11/resolving/default-resolver/test/namedRegistry.tspnpm11/resolving/default-resolver/tsconfig.jsonpnpm11/resolving/npm-resolver/package.jsonpnpm11/resolving/npm-resolver/src/createNpmResolutionVerifier.tspnpm11/resolving/npm-resolver/src/index.tspnpm11/resolving/npm-resolver/test/createNpmResolutionVerifier.test.tspnpm11/resolving/npm-resolver/test/resolveNamedRegistry.test.tspnpm11/resolving/npm-resolver/tsconfig.json
🚧 Files skipped from review as they are similar to previous changes (11)
- .changeset/known-registries-single-owner.md
- pnpm11/deps/compliance/sbom/package.json
- pnpm11/config/pick-registry-for-package/package.json
- pnpm11/config/pick-registry-for-package/test/knownRegistries.test.ts
- pnpm11/deps/compliance/sbom/tsconfig.json
- pnpm11/config/pick-registry-for-package/tsconfig.json
- pnpm11/lockfile/utils/tsconfig.json
- pnpm11/installing/deps-resolver/src/updateLockfile.ts
- pnpm11/resolving/npm-resolver/src/createNpmResolutionVerifier.ts
- pnpm11/installing/deps-resolver/tsconfig.json
- pnpm/crates/resolving-npm-resolver/src/named_registry.rs
|
Code review by qodo was updated up to the latest commit ec57bae |
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
Verifier construction unwrapped `merge_named_registries` with `.expect()`, so a reserved name or an unusable URL aborted the process instead of reporting ERR_PNPM_RESERVED_NAMED_REGISTRY_NAME. Reachable on the ordinary install path: `install.rs` builds verifiers before the resolver chain that also validates, and on the frozen path that chain never runs at all. The error now propagates through `BuildVerifiersError`, which the call site already routes into `InstallError`. `#[diagnostic(transparent)]` keeps the inner code, so the message a user sees is unchanged from the resolver path. This also closes a gap that predates the PR: a frozen install with an invalid `namedRegistries` previously reached no validation at all.
The dylint perfectionist rule rejects an inline `mod tests { ... }`.
|
Code review by qodo was updated up to the latest commit 36672c8 |
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
A stray blank line at the top of core/types/src/package.ts, left by a scripted import removal, and three `@pnpm/config.pick-registry-for-package` dependencies that stopped being used when `createKnownRegistries` went away — those callers only reach for `normalizeNamedRegistries` now. tsconfig references regenerated with meta-updater to match.
|
Code review by qodo was updated up to the latest commit de065a4 |
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
Summary
Closes pnpm/pnpm#13590.
The built-in aliases and the user's
namedRegistrieswere combined independently at every place that needed them:resolveNamedRegistries()in@pnpm/constantschainsitting directly above a separatebuild_named_registry_prefixes()The Rust pair had already drifted: the hand-rolled merge skipped the URL validation the other one applied.
That set feeds two consumers that look unrelated but are not — alias lookup for an entry that names its registry in the dep path, and the tarball-URL prefix list deciding which registry an entry carrying only a recorded URL is verified against. Splitting the merge across call sites is exactly what made adding the
npmjsbuilt-in look like a local change while it silently redirected verification traffic for lockfiles that record aregistry.npmjs.orgURL and name no alias at all. That consequence was caught by an unrelated normalization test that happened to use such a URL, not by anything at the edit site.KnownRegistriesnow owns the merge and exposes both views, so a change to either input reaches both consumers or neither.What's here
KnownRegistriesin both stacks —createKnownRegistries()in@pnpm/constants,KnownRegistries::new()inpacquet-resolving-npm-resolver.merge_named_registrieskeeps its validating role and now delegates the merge itself, so there is one implementation rather than two that can disagree.tarballPrefixesis computed lazily on the TS side. Alias lookup runs per package (pkgSnapshotToResolution), while prefix matching only runs for entries with a recorded URL — eagerly parsing URLs there would have been a per-package regression.A latent bug this surfaced
Writing the pinning test exposed one: the two built-in URLs are both exactly 27 characters, and sorting by length alone left their relative order to hash-map iteration, which varies between runs. My first version of the test failed for this reason.
The sort now tie-breaks lexicographically in both stacks. No routing outcome changes — two prefixes of equal length cannot both match one URL unless they are identical — but the list is now stable enough to assert on, which is the property the issue was asking for.
Verification
resolving.npm-resolver(334),lockfile.utils(18),deps.compliance.sbom(79),installing.deps-resolver(176).pacquet-resolving-npm-resolver(351),pacquet-package-manager(856).cargo fmt,clippy, and rustdoc clean.Not in scope
Per the issue: merging
registriesandnamedRegistries(different contracts — one is recorded in the lockfile, the other is ambient config), and movingjsrinto named registries (it legitimately needs scope routing for@jsr/*names, and converting it would churn every jsr user's lockfile keys).Squash Commit Body
Checklist
already linked to it solves it.
pnpm/port, or the description notes what still needs porting.pnpm changeset) if this PR changes any publishedpackage. Keep it short and written for pnpm users — it becomes a release note.
Written by an agent (Claude Code, claude-opus-5).
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Summary by CodeRabbit
Bug Fixes
Tests