Repository navigation
fix(resolver): don't fail on changed overrides when an optional peer is locked to an npm alias - #16658
Conversation
Lockfiles written before #15503 record an optional peer that the package also depends on as the peer's provider. When that provider is an npm alias of another package, the snapshot keeps it, for example `[email protected](@redocly/[email protected])` with `optionalDependencies: { ajv: '@redocly/[email protected]' }`. Since #15503 the name is resolved as a regular dependency again, from its plain range (`ajv: ^8.0.0`). The check that decides whether the locked ref still satisfies that range compared only the version, so the alias was accepted. The resolver then either kept the other package under the alias or, when it looks the locked version up in the registry as the default minimumReleaseAge makes it do, asked for `[email protected]` and failed with ERR_PNPM_NO_MATCHING_VERSION. Overrides with a version range in the selector reach this path because they skip the fast override rewrite. A plain range now requires the locked package to have the alias's own name, in both the TypeScript resolver (getRangeOfLockedPackage) and the Rust resolver (prior_child_key). Non-range specifiers such as git and tarball URLs keep their existing handling. Closes #16654
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
There was a problem hiding this comment.
Your trial has ended. Reactivate Greptile to resume code reviews.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (8)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review. 📝 WalkthroughWalkthroughResolver matching now checks package names when a bare semver range is compared with a lockfile entry. Regression tests cover aliased optional peers during lockfile reuse and lockfile-only installs after an override changes. ChangesAliased optional peer resolution
Priority: ➖ Normal Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Bug fix · Severity of issue fixed: Medium Assessment against linked issues
Suggested labels: Merge Risk: ⚪ Minimal · up to No merge-blocking issue is identified; the change is mergeable after normal checks. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning Some tools did not complete. Review the errors below. 🔧 ESLint
pnpm11/installing/deps-installer/test/install/peerDependencies.tsESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox. pnpm11/installing/deps-resolver/src/getDepsToResolve.tsESLint skipped: the matched ESLint configuration already failed (missing-dependency). pnpr/.fixtures/packages/@pnpm.e2e/aliases-optional-peer-of-dep/1.0.0/package.jsonESLint skipped: the matched ESLint configuration already failed (missing-dependency).
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 |
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
It alters the lockfile-reuse gate in both the v11 and v12 resolver hot paths, where subtle reuse regressions are high-impact and cannot be fully verified without running the complete test suites, so it warrants final human review.
Review effort: Balanced
Findings: None
What changed in this PR
This PR fixes a resolver regression where changing a ranged override caused pnpm install to fail with ERR_PNPM_NO_MATCHING_VERSION. The trigger is an old lockfile (written before #15503) that records an optional peer dependency — which the package also depends on by a plain range — as the peer's provider, where that provider is an npm: alias of a different package. The lockfile-reuse gate compared only the version and accepted the alias, so the resolver later looked up a non-existent version. The fix tightens the gate in both the TypeScript v11 resolver and the Rust v12 resolver so a plain semver range only reuses a locked ref whose package name matches the alias, while git and tarball specifiers keep their existing handling.
Changes:
- Require the locked package's name to equal the alias before a bare range reuses a locked ref, in
getRangeOfLockedPackage(TS) andprior_child_key(Rust). - Add regression tests across both stacks (a Rust unit test, and e2e tests driving
--lockfile-onlywith a changed override), plus two shared registry fixtures. - Add a changeset describing the user-visible fix.
| File | Description |
|---|---|
pnpm11/installing/deps-resolver/src/getDepsToResolve.ts |
Bare range now requires name === wantedDep.alias; git/tarball specs still return the bare specifier. |
pnpm/crates/resolving-deps-resolver/src/lockfile_reuse.rs |
prior_child_key adds key.name == name to the bare-range satisfaction check; updated doc comment. |
pnpm/crates/resolving-deps-resolver/src/lockfile_reuse/tests.rs |
Unit test asserting an alias ref is rejected for a bare range. |
pnpm11/installing/deps-installer/test/install/peerDependencies.ts |
e2e regression test simulating the pre-#15503 lockfile and re-resolving on changed overrides. |
pnpm/crates/cli/tests/suite/install/peers.rs |
Equivalent e2e regression test in the Rust CLI suite. |
pnpr/.fixtures/packages/@pnpm.e2e/has-optional-peer-range-also-in-deps/1.0.0/package.json |
Fixture whose dep and optional peer are the same ranged package. |
pnpr/.fixtures/packages/@pnpm.e2e/aliases-optional-peer-of-dep/1.0.0/package.json |
Fixture aliasing that peer to another package via npm:. |
.changeset/aliased-optional-peer-in-old-lockfile.md |
Release note targeting @pnpm/installing.deps-resolver, pnpm, and pacquet. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Micro-Benchmark ResultsLinux |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #16658 +/- ##
==========================================
- Coverage 92.34% 92.34% -0.01%
==========================================
Files 1590 1590
Lines 210019 210028 +9
==========================================
+ Hits 193947 193949 +2
- Misses 16072 16079 +7 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Same-run regression checkHEAD and main are measured on the same runner. The tolerance is 5% of the main median or 2 ms, whichever is larger. A regression requires both the median slowdown and the gap between the fastest retained HEAD sample and slowest retained main sample to exceed this tolerance, after trimming up to 10% from each tail. Suspected regressions are rerun once with target order reversed and only fail if reproduced. This conservative noise guard is not a statistical confidence interval. Inconclusive rows do not fail the check. They remain visible for performance review. Bencher retains absolute minimum timings for historical tracking; historical alerts do not gate this PR. Sequential measurements can still be affected by runner drift.
Integrated-Benchmark Report (Linux)Commit: Regular scenarios report direct and pnpr installs. The peer-heavy resolver scenario compares current Rust, main Rust, and TypeScript pnpm; the linked-workspace scenario compares current Rust against main Rust. Bencher consumes pacquet@HEAD and pnpr@HEAD. The tables below show mean ± σ. Bencher tracks absolute minimum latency; PR regression checks compare HEAD and main samples from the same runner. Historical timing alerts do not gate PRs. Scenario: Isolated linker: fresh restore, cold cache + cold store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 2.7181126393599997,
"stddev": 0.19600868413386469,
"median": 2.76180018046,
"user": 2.10102658,
"system": 2.0733923600000006,
"min": 2.40916079396,
"max": 2.95117894196
},
{
"command": "pacquet@main",
"mean": 2.49357458246,
"stddev": 0.16459624027113878,
"median": 2.41573037996,
"user": 1.7515905799999998,
"system": 1.66642176,
"min": 2.34550823296,
"max": 2.75782315396
},
{
"command": "pnpr@HEAD",
"mean": 1.45247672336,
"stddev": 0.09538084148548849,
"median": 1.41448131946,
"user": 1.7151152799999998,
"system": 1.6155967599999996,
"min": 1.3253142989600002,
"max": 1.62165347796
},
{
"command": "pnpr@main",
"mean": 1.50502456736,
"stddev": 0.13486778987487014,
"median": 1.45915373146,
"user": 1.5754863799999999,
"system": 1.59318706,
"min": 1.31433450396,
"max": 1.7246849449600001
}
]
}Scenario: Isolated linker: fresh restore, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.30790479428,
"stddev": 0.018972745927099716,
"median": 0.30407876438000003,
"user": 0.36855004,
"system": 0.6929109999999998,
"min": 0.28233813488000004,
"max": 0.35262706488
},
{
"command": "pacquet@main",
"mean": 0.34659206468,
"stddev": 0.06915088308760876,
"median": 0.33850604738,
"user": 0.40083724,
"system": 0.7495088,
"min": 0.25716949088,
"max": 0.45837349388000004
},
{
"command": "pnpr@HEAD",
"mean": 0.37356461508,
"stddev": 0.037638895356806555,
"median": 0.37388536838,
"user": 0.4215852399999999,
"system": 0.7584284,
"min": 0.31986958788000003,
"max": 0.45082859288000005
},
{
"command": "pnpr@main",
"mean": 0.33867541628000003,
"stddev": 0.02414914633194478,
"median": 0.33883806588000004,
"user": 0.38800164,
"system": 0.7108112,
"min": 0.30878917688,
"max": 0.39505882288000005
}
]
}Scenario: Isolated linker: repeat install, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.020213452349830505,
"stddev": 0.0032517745379965807,
"median": 0.01946520846,
"user": 0.010900679661016948,
"system": 0.01149818559322034,
"min": 0.01428539296,
"max": 0.03413229996000001
},
{
"command": "pacquet@main",
"mean": 0.03254982171912409,
"stddev": 0.011186680298614969,
"median": 0.03101089096,
"user": 0.01355902408759124,
"system": 0.017570352992700725,
"min": 0.01584716396,
"max": 0.07157871296000001
},
{
"command": "pnpr@HEAD",
"mean": 0.02985788859513515,
"stddev": 0.008819755594726277,
"median": 0.02753518396,
"user": 0.014122508108108112,
"system": 0.01566698972972973,
"min": 0.01732228196,
"max": 0.05457446296000001
},
{
"command": "pnpr@main",
"mean": 0.025671309616565652,
"stddev": 0.006634353959131298,
"median": 0.02367918296,
"user": 0.01269422323232323,
"system": 0.014176671515151522,
"min": 0.01673716396,
"max": 0.04760987296000001
}
]
}Scenario: Isolated linker: repeat install, cold cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.020681494285546217,
"stddev": 0.003399554335607247,
"median": 0.02018671042,
"user": 0.010963297310924377,
"system": 0.011371353949579834,
"min": 0.014165707420000001,
"max": 0.03255945742000001
},
{
"command": "pacquet@main",
"mean": 0.01916177656393941,
"stddev": 0.003200508067668096,
"median": 0.01881673692,
"user": 0.011315929090909088,
"system": 0.009529524848484844,
"min": 0.01292628342,
"max": 0.02722656642
},
{
"command": "pnpr@HEAD",
"mean": 0.019398085915652168,
"stddev": 0.0023520102377408564,
"median": 0.01934965042,
"user": 0.011231115652173917,
"system": 0.00996975513043478,
"min": 0.01310542942,
"max": 0.02554203542
},
{
"command": "pnpr@main",
"mean": 0.019554380690491806,
"stddev": 0.0034548609541295715,
"median": 0.01936196842,
"user": 0.011870306885245898,
"system": 0.009360006557377046,
"min": 0.013835888420000001,
"max": 0.040839608420000006
}
]
}Scenario: Isolated linker: fresh install, cold cache + cold store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 2.72295429886,
"stddev": 0.10250521320029665,
"median": 2.69904895326,
"user": 2.6924848399999997,
"system": 1.9631597599999995,
"min": 2.62772178176,
"max": 2.98989137576
},
{
"command": "pacquet@main",
"mean": 2.6490659772600003,
"stddev": 0.04798543806578675,
"median": 2.65484112976,
"user": 2.33235794,
"system": 1.8552397600000003,
"min": 2.5752269177600002,
"max": 2.72052270376
},
{
"command": "pnpr@HEAD",
"mean": 1.68665774366,
"stddev": 0.11399105885377639,
"median": 1.6732606852599998,
"user": 1.71713834,
"system": 1.81473366,
"min": 1.51898855476,
"max": 1.87206040576
},
{
"command": "pnpr@main",
"mean": 1.64968965286,
"stddev": 0.11790580260199171,
"median": 1.5874493052599998,
"user": 1.7007574399999998,
"system": 1.7296493599999998,
"min": 1.54090926076,
"max": 1.8584290007600002
}
]
}Scenario: Isolated linker: fresh install, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.7107399674200001,
"stddev": 0.024070140360241833,
"median": 0.71296926662,
"user": 1.0764417199999996,
"system": 1.0218380999999999,
"min": 0.6660903066200001,
"max": 0.74649181362
},
{
"command": "pacquet@main",
"mean": 0.6132236326200001,
"stddev": 0.08192713423832718,
"median": 0.5818503676200001,
"user": 0.8965565200000001,
"system": 0.9401777000000001,
"min": 0.5344711606200001,
"max": 0.7903315196200001
},
{
"command": "pnpr@HEAD",
"mean": 0.36475488992000005,
"stddev": 0.03149458815246202,
"median": 0.35920898562000003,
"user": 0.35127132,
"system": 0.6747325999999999,
"min": 0.32349756162000004,
"max": 0.43881019962
},
{
"command": "pnpr@main",
"mean": 0.3789270229200001,
"stddev": 0.04198773886219056,
"median": 0.37762535562,
"user": 0.3582688199999999,
"system": 0.7381228,
"min": 0.33056337662,
"max": 0.45444341962
}
]
}Scenario: Isolated linker: fresh install, cold cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 2.08410882258,
"stddev": 0.09523732448325312,
"median": 2.07416293668,
"user": 1.7800348,
"system": 1.51950966,
"min": 1.97759530868,
"max": 2.24349195668
},
{
"command": "pacquet@main",
"mean": 2.0006243917799997,
"stddev": 0.07866514785332313,
"median": 1.98718752868,
"user": 1.684977,
"system": 1.4361507600000003,
"min": 1.87765977068,
"max": 2.16590235368
},
{
"command": "pnpr@HEAD",
"mean": 0.45338622267999995,
"stddev": 0.029330227645587396,
"median": 0.46355161568000003,
"user": 0.4447468,
"system": 0.8124894599999999,
"min": 0.40341019568,
"max": 0.48694107868000003
},
{
"command": "pnpr@main",
"mean": 0.44372860098,
"stddev": 0.017156077746587367,
"median": 0.44045117918,
"user": 0.4390834,
"system": 0.81079316,
"min": 0.42224560368,
"max": 0.47313889068000003
}
]
}Scenario: Isolated linker: fresh resolve, hot cache, offline
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.42395449464000007,
"stddev": 0.06663306915962183,
"median": 0.41731370034000004,
"user": 0.4548621,
"system": 0.16425605999999998,
"min": 0.33404944134000003,
"max": 0.53797945334
},
{
"command": "pacquet@main",
"mean": 0.4137274218400001,
"stddev": 0.048255347944282906,
"median": 0.41709243984,
"user": 0.4346984,
"system": 0.17048276,
"min": 0.33869731434,
"max": 0.49223806934000003
},
{
"command": "pnpr@HEAD",
"mean": 0.1441413527747826,
"stddev": 0.0151307196409467,
"median": 0.14403226034000002,
"user": 0.07363822608695654,
"system": 0.03165943391304348,
"min": 0.12142709634000001,
"max": 0.17264235334000003
},
{
"command": "pnpr@main",
"mean": 0.1410110427945455,
"stddev": 0.016407829142870662,
"median": 0.13734935284,
"user": 0.06984426363636363,
"system": 0.03040171454545454,
"min": 0.11636942434000001,
"max": 0.17588700334000001
}
]
}Scenario: Isolated linker: peer-heavy resolve, hot cache, offline
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.3644028382933333,
"stddev": 0.051356247419154316,
"median": 0.37068285596,
"user": 0.39046076,
"system": 0.0792618511111111,
"min": 0.28333940696,
"max": 0.44083517096
},
{
"command": "pacquet@main",
"mean": 0.3837223936266667,
"stddev": 0.05169501658350176,
"median": 0.38355169996,
"user": 0.4170516488888889,
"system": 0.07691451777777777,
"min": 0.31092306996,
"max": 0.49566456996
},
{
"command": "pnpm@HEAD",
"mean": 4.8738525819600005,
"stddev": 0.31287181910625267,
"median": 4.83678665696,
"user": 7.55050376,
"system": 0.5204055177777778,
"min": 4.45381854796,
"max": 5.42999848196
}
]
}Scenario: Isolated linker: linked-workspace resolve, hot cache, offline
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.23292960325333334,
"stddev": 0.010686271675440874,
"median": 0.23223067792000002,
"user": 0.20050735333333333,
"system": 0.07808921333333334,
"min": 0.21104515142000002,
"max": 0.24935692242000002
},
{
"command": "pacquet@main",
"mean": 0.22426981572769228,
"stddev": 0.008131618781737255,
"median": 0.22724475742,
"user": 0.1821997123076923,
"system": 0.08597030307692308,
"min": 0.21217630542000002,
"max": 0.23413821842000002
}
]
}Scenario: Isolated linker: fresh restore, cold cache + cold store + cold pnpr
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 5.818725758879999,
"stddev": 0.300651897816325,
"median": 5.845156945679999,
"user": 2.86366852,
"system": 3.0387225399999997,
"min": 5.19418041418,
"max": 6.17201229118
},
{
"command": "pacquet@main",
"mean": 5.300478441879998,
"stddev": 0.39257714556475,
"median": 5.33485060818,
"user": 2.6266285199999997,
"system": 2.4902647399999998,
"min": 4.76125585318,
"max": 5.83506693718
},
{
"command": "pnpr@HEAD",
"mean": 3.83389340608,
"stddev": 0.2394535608758287,
"median": 3.90831585968,
"user": 2.1279815199999996,
"system": 2.0711235400000003,
"min": 3.54243827118,
"max": 4.1652338231799995
},
{
"command": "pnpr@main",
"mean": 3.8313644436799996,
"stddev": 0.1481932392751376,
"median": 3.8245601446800004,
"user": 2.1334429200000002,
"system": 1.88594404,
"min": 3.67893681018,
"max": 4.13922613618
}
]
}Scenario: GVS linker: fresh restore, hot cache + hot storeSame install as the isolated fresh-restore hot/hot scenario, into the shared virtual store, the layout pnpm 12 installs into by default. Scenarios run on separate machines, so compare main and branch within each table.
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.15247936860444444,
"stddev": 0.023213534958624375,
"median": 0.14480397616000001,
"user": 0.18627087777777776,
"system": 0.14253451777777776,
"min": 0.13096685866000002,
"max": 0.21608883066
},
{
"command": "pacquet@main",
"mean": 0.18266631895411764,
"stddev": 0.025460667757361836,
"median": 0.18423957566000002,
"user": 0.2292847470588235,
"system": 0.15721265176470586,
"min": 0.14642068566000002,
"max": 0.25662896066
},
{
"command": "pnpr@HEAD",
"mean": 0.20299787296769237,
"stddev": 0.021686175842549654,
"median": 0.20221054966000002,
"user": 0.24082986923076916,
"system": 0.16258285538461534,
"min": 0.17455134566000002,
"max": 0.24600061866000003
},
{
"command": "pnpr@main",
"mean": 0.19199995304461542,
"stddev": 0.026485711460739463,
"median": 0.19281438666,
"user": 0.22096994615384613,
"system": 0.17138500923076924,
"min": 0.15102322066,
"max": 0.24538141366000002
}
]
} |
Thirteen commits, none overlapping this branch's conversions. #16658 touches `lockfile_reuse.rs` too, at `prior_child_key`, which is far from the `ReusableResolution` conversion further down the file, so both sides merge on their own. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01QYTBQo8HY7xD2iz6hjo1CW
Summary
Changing a ranged override no longer fails when an old lockfile locks a dependency to an npm alias of another package through an optional peer. Closes #16654
--lockfile-only)pnpm/)ERR_PNPM_NO_MATCHING_VERSIONfor[email protected]pnpm11/)ERR_PNPM_NO_MATCHING_VERSIONfor[email protected]ajv-formatsuse the hoistedajvalias; pnpm has resolved it as its own dependency since fix(resolver): install a dependency that is also an optional peer #15503, and this matches that.Squash Commit Body
Checklist
already linked to it solves it.
are implemented in every affected version.
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-5).
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Summary by CodeRabbit
ERR_PNPM_NO_MATCHING_VERSIONafter an override changes when an optional peer dependency is resolved through an npm alias.