Repository navigation
fix(resolver): stop hoisted peers from ignoring the declared peer range - #12932
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughPeer hoisting now respects declared semver ranges, preserves workspace-root dependencies during re-resolution, and matches aliased peer providers by real package name. Rust, TypeScript, CLI, and integration tests cover these behaviors. ChangesPeer resolution and hoisting
Estimated code review effort: 4 (Complex) | ~45 minutes Possibly related PRs
Suggested labels: Suggested reviewers: ✨ Finishing Touches🧪 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 |
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? |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #12932 +/- ##
=======================================
Coverage 85.45% 85.45%
=======================================
Files 474 474
Lines 74561 74561
=======================================
Hits 63716 63716
Misses 10845 10845 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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? |
42e445f to
cf63810
Compare
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.
Pull request overview
This PR fixes a peer auto-install/hoisting correctness gap where hoistPeers could deduplicate to the highest preferred version across a workspace without checking whether it satisfies the declared peer semver range, which could silently produce an incompatible peer graph in multi-importer workspaces. It also aligns the Rust port’s peer resolution behavior with the TypeScript implementation for npm-alias children and adds regression coverage for re-resolve vs fresh install consistency.
Changes:
- Update
hoistPeers/hoist_peersto dedupe onto the highest preferred version that satisfies the peer range, and fall back to resolving the range when preferred versions exist but none satisfy. - Fix pacquet
resolve_peersto allow an npm-alias child to satisfy a peer by its real package name (matching the TS behavior). - Add/adjust tests (TS + Rust) to lock in the new behavior and re-resolve consistency; add a changeset for the user-visible behavior change.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| pnpm11/installing/deps-resolver/test/hoistPeers.test.ts | Updates/extends unit coverage to ensure preferred-version dedupe respects semver ranges and key edge cases (including prerelease behavior). |
| pnpm11/installing/deps-resolver/src/resolveDependencies.ts | Builds a workspaceRootDeps table that can fall back to wanted specifiers when lockfile reuse skips normalization, ensuring consistent hoist behavior across re-resolve. |
| pnpm11/installing/deps-resolver/src/hoistPeers.ts | Core logic change: validate as semver range and select max satisfying preferred version; otherwise fall back appropriately. |
| pnpm11/installing/deps-installer/test/install/autoInstallPeers.ts | Strengthens integration test to ensure auto-installed peers don’t reuse an incompatible preferred version from elsewhere in the graph. |
| pnpm/crates/resolving-deps-resolver/src/resolve_peers/tests.rs | Updates Rust tests to assert alias children can satisfy peers by real package name. |
| pnpm/crates/resolving-deps-resolver/src/resolve_peers.rs | Aligns parent-ref indexing with TS by treating alias children as peer-relevant when either alias or real name matches peer names. |
| pnpm/crates/resolving-deps-resolver/src/hoist_peers/tests.rs | Mirrors TS hoist-peers tests for range-respecting preferred dedupe and fallback behavior. |
| pnpm/crates/resolving-deps-resolver/src/hoist_peers.rs | Mirrors TS hoist-peers range validation and “fallback to range” behavior when preferred versions don’t satisfy. |
| pnpm/crates/cli/tests/install.rs | Adds regression test ensuring re-resolve with an existing lockfile binds peers the same way as a fresh install. |
| .changeset/peer-hoist-respect-range.md | Records the user-visible fix and lockfile consistency improvement for release notes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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)
pnpm/crates/resolving-deps-resolver/src/hoist_peers.rs (1)
87-119: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winDon't fall back to the highest preferred version for unsatisfied semver ranges. In
pnpm/crates/resolving-deps-resolver/src/hoist_peers.rs, theauto_install_peers == falsefallback still usesmax_satisfying_any(&versions)whenis_semver_rangeis true and no preferred version matches, so it can hoist a range-rejecting major anyway. Mirror the same fix inpnpm11/installing/deps-resolver/src/hoistPeers.ts.🤖 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/resolving-deps-resolver/src/hoist_peers.rs` around lines 87 - 119, Update the fallback logic in the hoisting code to avoid selecting max_satisfying_any(&versions) when is_semver_range is true but no preferred version satisfies the requested range, especially when auto_install_peers is false; preserve non-semver fallback behavior and resolve unsatisfied semver ranges from the range instead. Apply the equivalent change to hoistPeers in pnpm11/installing/deps-resolver/src/hoistPeers.ts.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 `@pnpm/crates/resolving-deps-resolver/src/hoist_peers.rs`:
- Around line 87-119: Update the fallback logic in the hoisting code to avoid
selecting max_satisfying_any(&versions) when is_semver_range is true but no
preferred version satisfies the requested range, especially when
auto_install_peers is false; preserve non-semver fallback behavior and resolve
unsatisfied semver ranges from the range instead. Apply the equivalent change to
hoistPeers in pnpm11/installing/deps-resolver/src/hoistPeers.ts.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 0c2997e0-c17a-432e-a98e-6611fc2b8263
📒 Files selected for processing (10)
.changeset/peer-hoist-respect-range.mdpnpm/crates/cli/tests/install.rspnpm/crates/resolving-deps-resolver/src/hoist_peers.rspnpm/crates/resolving-deps-resolver/src/hoist_peers/tests.rspnpm/crates/resolving-deps-resolver/src/resolve_peers.rspnpm/crates/resolving-deps-resolver/src/resolve_peers/tests.rspnpm11/installing/deps-installer/test/install/autoInstallPeers.tspnpm11/installing/deps-resolver/src/hoistPeers.tspnpm11/installing/deps-resolver/src/resolveDependencies.tspnpm11/installing/deps-resolver/test/hoistPeers.test.ts
…to-install With autoInstallPeers off (the dedupe-peer-dependents hoist), a semver peer range that no preferred version satisfies fell through to the dedupe-to-highest branch and could still hoist a version the range rejects. Leave the peer missing instead — the ordinary missing-peer warning applies. Raised by CodeRabbit on pnpm#12932. Signed-off-by: C. Spencer Beggs <[email protected]>
|
Addressed CodeRabbit's outside-diff finding on Written by an agent (Claude Code, claude-fable-5). |
|
The Written by an agent (Claude Code, claude-fable-5). |
Integrated-Benchmark Report (Linux)Commit: Each scenario reports direct installs and pnpr installs. Bencher consumes pacquet@HEAD and pnpr@HEAD. Scenario: Isolated linker: fresh restore, cold cache + cold store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 4.09903901452,
"stddev": 0.13055466946721822,
"median": 4.04792488902,
"user": 3.9347863599999995,
"system": 3.4397765799999993,
"min": 3.98204685202,
"max": 4.32424004802,
"times": [
4.21734254302,
4.32424004802,
3.99287231402,
4.06929425702,
4.27365528102,
3.98809328402,
3.98248826302,
4.02655552102,
4.13380178202,
3.98204685202
]
},
{
"command": "pacquet@main",
"mean": 4.048509955519999,
"stddev": 0.1484015324908731,
"median": 4.02494718452,
"user": 3.9401107600000005,
"system": 3.44815978,
"min": 3.90541797402,
"max": 4.41635601402,
"times": [
4.03695827002,
4.41635601402,
4.01293609902,
4.07514856802,
4.08785813602,
3.90541797402,
3.9547258760200004,
3.91736996302,
3.95980304202,
4.11852561302
]
},
{
"command": "pnpr@HEAD",
"mean": 2.17238569912,
"stddev": 0.12176760625992558,
"median": 2.1592768950199996,
"user": 2.76988426,
"system": 2.95323438,
"min": 2.04191156602,
"max": 2.32863631102,
"times": [
2.32687210302,
2.23652287202,
2.04191156602,
2.21071185902,
2.04319647002,
2.10784193102,
2.06235401502,
2.06171120102,
2.32863631102,
2.30409866302
]
},
{
"command": "pnpr@main",
"mean": 2.15435309372,
"stddev": 0.120607257179547,
"median": 2.10763117752,
"user": 2.74863856,
"system": 2.9418326799999996,
"min": 2.00397784302,
"max": 2.35474322202,
"times": [
2.28919223702,
2.1083894610200002,
2.10687289402,
2.09866566502,
2.23861302702,
2.00397784302,
2.03745676402,
2.35474322202,
2.04858152202,
2.25703830202
]
}
]
}Scenario: Isolated linker: fresh restore, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.6684769064600001,
"stddev": 0.009969768808813678,
"median": 0.6697000630600001,
"user": 0.41088509999999995,
"system": 1.3402659199999998,
"min": 0.65082770706,
"max": 0.6810166280600001,
"times": [
0.67982300106,
0.65992550106,
0.67023634706,
0.65082770706,
0.6595654790600001,
0.66916377906,
0.66378477006,
0.6810166280600001,
0.6714564430600001,
0.67896940906
]
},
{
"command": "pacquet@main",
"mean": 0.6834991760600001,
"stddev": 0.07538558396795338,
"median": 0.6589987420600001,
"user": 0.38654230000000006,
"system": 1.3395096199999998,
"min": 0.63708513806,
"max": 0.89268469506,
"times": [
0.68652939406,
0.66290896706,
0.6462511750600001,
0.6789232070600001,
0.63708513806,
0.65508851706,
0.64617604206,
0.6491246970600001,
0.89268469506,
0.6802199280600001
]
},
{
"command": "pnpr@HEAD",
"mean": 0.7372040815600001,
"stddev": 0.09506848787931015,
"median": 0.70731624906,
"user": 0.418748,
"system": 1.35541432,
"min": 0.68750187106,
"max": 1.0046209100599999,
"times": [
0.7253390460600001,
0.7159091870600001,
0.69840433806,
0.70844655006,
0.6882457510600001,
0.68750187106,
0.7047454670600001,
1.0046209100599999,
0.7326417470600001,
0.70618594806
]
},
{
"command": "pnpr@main",
"mean": 0.72951844446,
"stddev": 0.009191100996470322,
"median": 0.73203615156,
"user": 0.4013331,
"system": 1.40122052,
"min": 0.71630366706,
"max": 0.7406551060600001,
"times": [
0.7386188880600001,
0.7406551060600001,
0.73842422506,
0.71630366706,
0.7262857380600001,
0.7311137160600001,
0.7191560130600001,
0.73295858706,
0.73420515606,
0.71746334806
]
}
]
}Scenario: Isolated linker: fresh install, cold cache + cold store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 4.31105912486,
"stddev": 0.027296323073829995,
"median": 4.3155930399599995,
"user": 3.89089174,
"system": 3.33861572,
"min": 4.2611457899600005,
"max": 4.34537937396,
"times": [
4.32156374496,
4.29412010096,
4.2611457899600005,
4.3392340459600005,
4.34537937396,
4.2764896849600005,
4.30649299196,
4.31273916296,
4.33497943596,
4.31844691696
]
},
{
"command": "pacquet@main",
"mean": 4.329499830960001,
"stddev": 0.049776629775337325,
"median": 4.32892175896,
"user": 3.9056600399999994,
"system": 3.3454023200000003,
"min": 4.23907853996,
"max": 4.41227109396,
"times": [
4.23907853996,
4.27131997596,
4.33096285796,
4.33772501196,
4.31150138796,
4.41227109396,
4.3268806599600005,
4.38015617096,
4.32552069096,
4.35958191996
]
},
{
"command": "pnpr@HEAD",
"mean": 2.1564066337599996,
"stddev": 0.14698987952938894,
"median": 2.10179265896,
"user": 2.606273039999999,
"system": 2.85091802,
"min": 2.0377890449600002,
"max": 2.5492438279600003,
"times": [
2.5492438279600003,
2.2021473249600003,
2.18122776596,
2.0815766089600003,
2.1036329459600003,
2.06758495896,
2.09995237196,
2.14603725996,
2.09487422796,
2.0377890449600002
]
},
{
"command": "pnpr@main",
"mean": 2.08784249376,
"stddev": 0.08731701609331732,
"median": 2.06238412046,
"user": 2.60925094,
"system": 2.8475464199999996,
"min": 2.00246777696,
"max": 2.30403698396,
"times": [
2.00246777696,
2.30403698396,
2.04248417996,
2.05862733296,
2.0552307669600003,
2.15135391096,
2.0113442419600003,
2.06614090796,
2.08343740896,
2.1033014269600003
]
}
]
}Scenario: Isolated linker: fresh install, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 1.4273389554400002,
"stddev": 0.012188124484527016,
"median": 1.42319056944,
"user": 1.3984827799999997,
"system": 1.7329195799999997,
"min": 1.41142365444,
"max": 1.44395134444,
"times": [
1.41478400144,
1.41595556544,
1.42269958544,
1.43686021144,
1.42316108044,
1.43761713144,
1.41142365444,
1.44371692144,
1.44395134444,
1.42322005844
]
},
{
"command": "pacquet@main",
"mean": 1.42973404894,
"stddev": 0.04522988568412074,
"median": 1.42315389494,
"user": 1.3634850799999998,
"system": 1.7241813799999999,
"min": 1.38504907344,
"max": 1.54024081344,
"times": [
1.4043522904399999,
1.44899602444,
1.54024081344,
1.41519095144,
1.3983310764399999,
1.3896821024400001,
1.38504907344,
1.44826850644,
1.43111683844,
1.43611281244
]
},
{
"command": "pnpr@HEAD",
"mean": 0.6915095040400001,
"stddev": 0.021207567955761817,
"median": 0.68596441094,
"user": 0.37380388,
"system": 1.2810505799999998,
"min": 0.67412080144,
"max": 0.74665169344,
"times": [
0.68937918544,
0.67412080144,
0.67828391844,
0.69357753844,
0.74665169344,
0.69042411644,
0.6818011834400001,
0.67622524244,
0.70208172444,
0.68254963644
]
},
{
"command": "pnpr@main",
"mean": 0.6841067798400001,
"stddev": 0.009676331543613704,
"median": 0.68539625844,
"user": 0.35231757999999996,
"system": 1.2864856799999997,
"min": 0.67221459644,
"max": 0.6971277824400001,
"times": [
0.67427054744,
0.67437910444,
0.67221459644,
0.67530344744,
0.68626442544,
0.68452809144,
0.6971277824400001,
0.69621613144,
0.69441991744,
0.6863437544400001
]
}
]
}Scenario: Isolated linker: fresh install, cold cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 3.1913319595,
"stddev": 0.0365194694734581,
"median": 3.2046170925,
"user": 1.93122912,
"system": 2.0224480599999994,
"min": 3.1281342665,
"max": 3.2264619555,
"times": [
3.1923553625,
3.2020508265,
3.2182242795,
3.2166931284999998,
3.2260955145,
3.2264619555,
3.2071833585,
3.1546949895,
3.1414259135,
3.1281342665
]
},
{
"command": "pacquet@main",
"mean": 3.2193624746999996,
"stddev": 0.06202043466184382,
"median": 3.200432827,
"user": 1.9025370199999998,
"system": 2.05267916,
"min": 3.1773398335,
"max": 3.3816183095,
"times": [
3.2093890595,
3.2195422805,
3.1787441015,
3.1773398335,
3.2582538205,
3.1827192105,
3.2045767585,
3.3816183095,
3.1962888955,
3.1851524775
]
},
{
"command": "pnpr@HEAD",
"mean": 0.6832898783000001,
"stddev": 0.006870468117246211,
"median": 0.6850266225,
"user": 0.37690722,
"system": 1.2826396599999998,
"min": 0.6692689085,
"max": 0.6912448445,
"times": [
0.6863309545,
0.6811560655000001,
0.6740944205,
0.6857774605,
0.6912448445,
0.6884038845,
0.6832868315,
0.6692689085,
0.6890596285,
0.6842757845
]
},
{
"command": "pnpr@main",
"mean": 0.6910295479999999,
"stddev": 0.015713986786841428,
"median": 0.6864468855000001,
"user": 0.36189352,
"system": 1.2936359600000003,
"min": 0.6767242635,
"max": 0.7317261255,
"times": [
0.6804516415,
0.6767242635,
0.6864038505000001,
0.6813807185,
0.6859751915000001,
0.6864899205,
0.6990174685,
0.6875163995,
0.7317261255,
0.6946099005
]
}
]
}Scenario: Isolated linker: fresh resolve, hot cache, offline
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.7253934999800001,
"stddev": 0.01939360037505428,
"median": 0.7213638713800001,
"user": 0.6787718,
"system": 0.16117917999999998,
"min": 0.7038231423800001,
"max": 0.7664313813800001,
"times": [
0.7038231423800001,
0.7113051113800001,
0.7239285363800001,
0.7515339613800001,
0.7664313813800001,
0.71912900438,
0.7235987383800001,
0.7277044723800001,
0.7111836173800001,
0.7152970343800001
]
},
{
"command": "pacquet@main",
"mean": 0.7118370981800001,
"stddev": 0.012210768933700272,
"median": 0.7082076298800001,
"user": 0.6696978999999998,
"system": 0.15525728,
"min": 0.6959624073800001,
"max": 0.7373356663800001,
"times": [
0.7056243473800001,
0.70257904538,
0.6959624073800001,
0.7086834093800001,
0.71086993738,
0.7258454293800001,
0.7186319753800001,
0.7373356663800001,
0.7077318503800001,
0.7051069133800001
]
},
{
"command": "pnpr@HEAD",
"mean": 0.11208668583833335,
"stddev": 0.0005946166461595222,
"median": 0.11198269488000001,
"user": 0.027835374999999996,
"system": 0.02342688833333334,
"min": 0.11107018638,
"max": 0.11321926438,
"times": [
0.11166380338,
0.11279218838,
0.11184489738,
0.11202805338,
0.11161694238,
0.11321926438,
0.11107018638,
0.11178441538,
0.11243491838,
0.11279213838,
0.11177829638,
0.11135030938,
0.11209520538000001,
0.11113141838,
0.11285429338,
0.11151482838,
0.11246958138,
0.11206857538,
0.11243675138,
0.11302783538,
0.11179728538,
0.11193733638,
0.11173906738,
0.11263286838
]
},
{
"command": "pnpr@main",
"mean": 0.11849011979666664,
"stddev": 0.02796737818631637,
"median": 0.11260520888,
"user": 0.029301000000000004,
"system": 0.022546846666666665,
"min": 0.11077748638,
"max": 0.24959864537999998,
"times": [
0.11102487738,
0.11297875038,
0.11276754138,
0.11214126538,
0.11189388138,
0.11170595738,
0.11244683738,
0.11283616038,
0.11285920338,
0.11077748638,
0.11253902938,
0.11339519338,
0.11703733938,
0.11528865538,
0.11260242438,
0.11278813538,
0.11260799338000001,
0.11198229738,
0.11170090238,
0.11155479138,
0.24959864537999998,
0.11653383738,
0.11302986138,
0.11167180838
]
}
]
}Scenario: Isolated linker: fresh restore, cold cache + cold store + cold pnpr
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 6.918297195879999,
"stddev": 0.11710655765108625,
"median": 6.950470730779999,
"user": 4.19744016,
"system": 3.6697252199999992,
"min": 6.71072303528,
"max": 7.11901167728,
"times": [
6.97319606728,
7.11901167728,
6.8392534202799995,
6.99948200328,
6.9767524412799995,
6.97378713928,
6.7958026692799995,
6.86721811128,
6.71072303528,
6.92774539428
]
},
{
"command": "pacquet@main",
"mean": 6.917501079180001,
"stddev": 0.13896432221887417,
"median": 6.874128628779999,
"user": 4.127026760000001,
"system": 3.6894824199999996,
"min": 6.77231592228,
"max": 7.181192107279999,
"times": [
6.83373175028,
6.852489009279999,
6.83489003228,
7.181192107279999,
6.90785123628,
7.13804441828,
6.96000501128,
6.77231592228,
6.89576824828,
6.79872305628
]
},
{
"command": "pnpr@HEAD",
"mean": 4.94073205668,
"stddev": 0.09980576115571188,
"median": 4.954405102779999,
"user": 2.8915503599999997,
"system": 3.1343194199999997,
"min": 4.742720923279999,
"max": 5.07864290528,
"times": [
5.04617400228,
4.97321964328,
4.936204077279999,
4.91730920028,
4.82124062928,
4.742720923279999,
5.07864290528,
4.99616686028,
4.97260612828,
4.92303619728
]
},
{
"command": "pnpr@main",
"mean": 4.88475187498,
"stddev": 0.08026552333100233,
"median": 4.87103237828,
"user": 2.8679316599999995,
"system": 3.1330787199999994,
"min": 4.78709393928,
"max": 5.02288145828,
"times": [
4.79057330628,
4.8306189242799995,
5.02288145828,
4.78709393928,
4.8607676262799995,
4.88129713028,
4.930619324279999,
5.0030384112799995,
4.85504078428,
4.88558784528
]
}
]
} |
|
| Branch | pr/12932 |
| Testbed | pnpr |
⚠️ WARNING: No Threshold found!Without a Threshold, no Alerts will ever be generated.
Click here to create a new Threshold
For more information, see the Threshold documentation.
To only post results if a Threshold exists, set the--ci-only-thresholdsflag.
Click to view all benchmark results
| Benchmark | Latency | milliseconds (ms) |
|---|---|---|
| isolated-linker.fresh-install.cold-cache.cold-store | 📈 view plot | 2,156.41 ms |
| isolated-linker.fresh-install.cold-cache.hot-store | 📈 view plot | 683.29 ms |
| isolated-linker.fresh-install.hot-cache.hot-store | 📈 view plot | 691.51 ms |
| isolated-linker.fresh-resolve.hot-cache.offline | 📈 view plot | 112.09 ms |
| isolated-linker.fresh-restore.cold-cache.cold-store | 📈 view plot | 2,172.39 ms |
| isolated-linker.fresh-restore.cold-cache.cold-store.cold-pnpr | 📈 view plot | 4,940.73 ms |
| isolated-linker.fresh-restore.hot-cache.hot-store | 📈 view plot | 737.20 ms |
When deduplicating a missing peer onto the workspace's preferred versions, hoistPeers matched candidates against '*' unless the wanted range was an exact version. In a multi-importer workspace, allPreferredVersions aggregates versions from every importer, so a peer declared as ^1.0.0 inside one importer's closure could be auto-installed as a 2.x resolved for another importer, silently producing a peer graph that mixes incompatible majors. This survived pnpm#12847 (which fixed the single-importer case in resolvePeers) and is independent of the pnpm#12921 deadlock fix: the wrong version is chosen upstream of peer resolution, during peer hoisting. Both stacks now dedupe onto the highest preferred version that satisfies the wanted range and fall back to resolving the range from the registry when no candidate satisfies it. Non-semver specifiers (workspace:, npm: aliases, dist-tags) keep the dedupe-to-highest behavior. Fixing this exposed a pacquet-only divergence the old behavior masked: resolve_peers indexed a node's children into ParentRefs only by their install alias, so an npm-alias child could never provide a peer under its real package name below the importer level, and the binding fell through to the importer-level hoisted entry. Descent-time children are now indexed by both alias and real name, matching resolvePeers.ts. Measured on the multi-importer reproduction: 46 poisoned snapshots on pnpm 11.11.0, 0 with this change, in both the TypeScript CLI and pacquet. Signed-off-by: C. Spencer Beggs <[email protected]>
The perfectionist::macro-trailing-comma dylint check rejects a multi-line macro invocation without a trailing comma; the local pre-push hook skips dylint when cargo-dylint is not installed, so CI caught it. Signed-off-by: C. Spencer Beggs <[email protected]>
On a fresh install, a missing peer that a workspace-root dependency
provides is hoisted to that dependency's own specifier (the
workspaceRootDeps branch of hoistPeers), so the peer dedupes onto the
package the root dependency brings in. On a re-resolve with an existing
lockfile, root dependencies reused from the lockfile skip full
resolution: their addresses carry no normalizedBareSpecifier (or they
produce no address at all), so hoistPeers fell through to the
preferred-versions branch and could pick a different version than the
fresh install of the same manifest. With the range-respecting hoist
this stopped being coincidentally identical and produced a lockfile
that differed between the two flows — and diverged from the Rust port,
whose peers-dry-run sees providers regardless of lockfile reuse and
already behaved like the fresh install in both flows.
The hoist's root-dep table is now built with a fallback to the
importer's wanted specifiers, covering lockfile-reused dependencies.
Its entry type is narrowed to HoistableRootDep { alias, pkgName,
normalizedBareSpecifier } — the exact fields hoistPeers reads, and the
same shape as the Rust port's WorkspaceRootDep.
The Rust port gets a regression test pinning the shared expectation
(adding a dependent to an existing lockfile binds the same peer
provider as a fresh install); the TypeScript expectation is restored to
the pre-existing aliased-providers test it had temporarily changed.
Signed-off-by: C. Spencer Beggs <[email protected]>
…to-install With autoInstallPeers off (the dedupe-peer-dependents hoist), a semver peer range that no preferred version satisfies fell through to the dedupe-to-highest branch and could still hoist a version the range rejects. Leave the peer missing instead — the ordinary missing-peer warning applies. Raised by CodeRabbit on pnpm#12932. Signed-off-by: C. Spencer Beggs <[email protected]>
Rust CI / Test / ubuntu hit the optimistic-repeat-install mtime race tracked in pnpm#12730 (stale_pin_dedupe); no rerun rights on the failed job, so an empty commit retriggers the run. Signed-off-by: C. Spencer Beggs <[email protected]>
Code Review by Qodo
Context used✅ Compliance rules (platform):
18 rules 1. Missing trailing comma in params
|
PR Code Suggestions ✨Warning
No code suggestions found for the PR.
|
…cks into named helpers The workspace-root-deps construction in resolveRootDependencies moves into getHoistableRootDeps, whose doc comment carries the lockfile-reuse fallback rationale. The alias-or-real-name peer check duplicated at the importer level and at descent time in resolve_peers.rs becomes a single Walker::is_peer_relevant method; it also short-circuits before pkg_name_version's allocations when the alias alone matches. No behavior change in either stack. Co-Authored-By: Claude Fable 5 <[email protected]>
|
Code review by qodo was updated up to the latest commit ea6b790 |
PR Code Suggestions ✨Warning
No code suggestions found for the PR.
|
Confidence Score: 4/5Safe to merge. The change is well-scoped, both stacks are updated together, and the regression tests cover the fixed cases directly. The deduplication logic change is a deliberate behavior break for lockfiles that previously relied on maxSatisfying(versions, '*') for non-exact peer ranges — existing tests were updated to match the corrected expectations. The getHoistableRootDeps helper introduces a new code path for the lockfile-reuse case exercised only by the new e2e test. Both are high-confidence fixes with clear regression coverage, but the behavior change to the else branch is subtle and touches core resolution logic in both stacks. resolveDependencies.ts (getHoistableRootDeps) deserves a second look: when a root dep is reused from the lockfile its fallback normalizedBareSpecifier is the raw wanted range rather than the exact locked version, which causes re-resolution against the lockfile rather than pinning. This is the intended design but differs subtly from a fully-resolved address entry. Reviews (1): Last reviewed commit: "refactor(resolver): extract the root-dep..." | Re-trigger Greptile |
Carries the merged readPackage resolvedDir hook (pnpm/pnpm#12936) plus the hoisted-peer range fix (pnpm/pnpm#12932). The resolvedDir hook resolves the injected workspace-sibling failures under BIT_FEATURES=deps-graph — the deps-graph e2e suite drops from 3 failing to 1. The remaining failure is the separate lockfile resolution-reuse gap, not the manifest-injection path. Co-Authored-By: Claude Fable 5 <[email protected]>
Summary
Related to #12847 and #12921. Continues the same cleanup as #12927: #12847 was our fix, and this addresses the remaining correctness gap it did not close. The change is independent of #12927 (verified: the two touch disjoint product code, and the reproduction measures the same 46 poisoned snapshots with or without it), so it targets
maindirectly and can land before or after the deadlock fix.First, an apology: #12847's two-pass split hung
pnpm installfor every[email protected]user until #12927. We are sorry for the disruption that caused.What was still broken after #12847
hoistPeersonly checked preferred versions against the wanted peer range when the range was an exact version. For an ordinary semver range (^1.0.0), it deduplicated ontosemver.maxSatisfying(versions, '*')— the highest preferred version overall, with the declared range never consulted.In a multi-importer workspace,
allPreferredVersionsaggregates versions contributed by every importer. So importer A depending on[email protected]put2.0.0into the candidate set, and a package deep inside importer B's self-contained1.xclosure — declaringpeerDependencies: { foo: "^1.0.0" }— was handed2.0.0, because it is numerically highest and'*'matches anything. pnpm then only warned about the violation, so the incoherent peer graph shipped silently and failed at runtime. This happens upstream ofresolvePeers, so #12847 (single-importer case, fixed) and #12927 (deadlock, orthogonal) do not reach it.Measured on a minimal 4-file reproduction (two importers,
autoInstallPeers: true): 46 poisoned snapshots on pnpm 11.11.0 → 0 with this change, on both the TypeScript CLI and the Rust port.The fix
hoistPeers/hoist_peersnow validate the wanted range withsemver.validRange(not justsemver.valid) and dedupe onto the highest preferred version that satisfies the range. When preferred versions exist but none satisfies, the range itself is resolved from the registry instead of installing a version the peer explicitly rejects. Non-semver specifiers (workspace:,npm:aliases, dist-tags) cannot be range-checked and keep the dedupe-to-highest behavior.resolve_peersindexed a node's children intoParentRefsonly by install alias, so an npm-alias child could never provide a peer under its real package name below the importer level. Descent-time children are now indexed by both alias and real name, matchingresolvePeers.ts.Why we believe this matches pnpm's intended behavior
'*'match.Follow-up: re-resolve consistency (second commit)
Investigating the two-pass behavior surfaced a second, related defect in the TypeScript CLI. On a fresh install, a missing peer that a workspace-root dependency provides is hoisted to that root dependency's own specifier. On a re-resolve with an existing lockfile, root dependencies reused from the lockfile skip full resolution and were invisible to that branch, so the hoist could pick a different version than a fresh install of the same manifest — the lockfile depended on how you arrived at it. The old
'*'-dedupe made the two flows coincidentally identical, which is why this was never visible before. The hoist's root-dep table now falls back to the importer's wanted specifiers, its entry type is narrowed to the exact fields the hoist reads (the same shape as the Rust port'sWorkspaceRootDep), and both stacks carry a regression test pinning the shared expectation: adding a dependent to an existing lockfile binds the same peer provider as a fresh install. The Rust port already behaved correctly in both flows (its peers dry-run sees providers regardless of lockfile reuse) and needed no product change.Squash Commit Body
Checklist
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-fable-5).
Signed-off-by: C. Spencer Beggs [email protected]
Summary by CodeRabbit