Repository navigation
fix(resolver): install a dependency that is also an optional peer - #15503
Conversation
When autoInstallPeers is on, the resolver removed every name listed in a package's peerDependencies from its dependencies, expecting the peer to be auto-installed. Optional peers are never auto-installed, so a package that both depends on something and declares it as an optional peer (vite's lightningcss) ended up with neither. Such a dependency is now removed only when an ancestor already provides it, the same rule autoInstallPeers=false uses, so it keeps its own dependency range. Fixed in both the TypeScript and the Rust resolver, with a new registry fixture shaped like vite's manifest. Closes #8912 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: pnpm/pnpm/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
💤 Files with no reviewable changes (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe Rust and TypeScript dependency resolvers now preserve a regular dependency when the same package is declared as an optional peer, unless an ancestor provides it. Regression tests cover both ChangesOptional peer dependency installation
Priority: ➖ Normal Estimated code review effort: 3 (Moderate) | ~25 minutes Change: Bug fix · Severity of issue fixed: Medium Assessment against linked issues
Suggested labels: Merge Risk: ⚪ Minimal · up to The change can proceed through normal checks; no actionable merge-blocking issue is established. ✨ 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 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #15503 +/- ##
==========================================
+ Coverage 91.81% 91.83% +0.01%
==========================================
Files 1417 1419 +2
Lines 191085 191328 +243
==========================================
+ Hits 175451 175703 +252
+ Misses 15634 15625 -9 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Micro-Benchmark ResultsLinux |
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.57388485804,
"stddev": 0.12162136911426898,
"median": 2.5665260532399996,
"user": 1.8926771999999996,
"system": 1.6344388200000002,
"min": 2.35843909474,
"max": 2.82264842474
},
{
"command": "pacquet@main",
"mean": 2.57515602994,
"stddev": 0.13115890380609727,
"median": 2.62572120774,
"user": 1.7412214,
"system": 1.52851692,
"min": 2.37631472474,
"max": 2.73517859074
},
{
"command": "pnpr@HEAD",
"mean": 1.45595351524,
"stddev": 0.12024287744043644,
"median": 1.47029704324,
"user": 1.1960012,
"system": 1.25918942,
"min": 1.30329169474,
"max": 1.6051836407400002
},
{
"command": "pnpr@main",
"mean": 1.4268202487400001,
"stddev": 0.0882069085259805,
"median": 1.40204670874,
"user": 1.302286,
"system": 1.29844582,
"min": 1.30702255474,
"max": 1.59425358074
}
]
}Scenario: Isolated linker: fresh restore, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.26288548570000003,
"stddev": 0.026526072360254015,
"median": 0.2602469763,
"user": 0.28990538,
"system": 0.6393633,
"min": 0.22949669880000004,
"max": 0.3121016568
},
{
"command": "pacquet@main",
"mean": 0.23835617290000002,
"stddev": 0.020271360857271322,
"median": 0.23739616430000002,
"user": 0.25793278,
"system": 0.5802548,
"min": 0.21068350080000003,
"max": 0.2718060888
},
{
"command": "pnpr@HEAD",
"mean": 0.25897881120000005,
"stddev": 0.01035216007889288,
"median": 0.2584834573,
"user": 0.26307878,
"system": 0.5980652,
"min": 0.24196306180000002,
"max": 0.2756176848
},
{
"command": "pnpr@main",
"mean": 0.2623261324,
"stddev": 0.018004225081791135,
"median": 0.2596389008,
"user": 0.27478448000000005,
"system": 0.6050174999999999,
"min": 0.24356580980000003,
"max": 0.3025806908
}
]
}Scenario: Isolated linker: repeat install, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.007728297470647477,
"stddev": 0.0009274092989486632,
"median": 0.00744001978,
"user": 0.004606874532374096,
"system": 0.003667491942446042,
"min": 0.006608270280000001,
"max": 0.01182640928
},
{
"command": "pacquet@main",
"mean": 0.008451680414228183,
"stddev": 0.0016531191054563338,
"median": 0.007794942280000001,
"user": 0.004725328590604029,
"system": 0.004292308724832214,
"min": 0.00661962828,
"max": 0.01720574928
},
{
"command": "pnpr@HEAD",
"mean": 0.013032933056041661,
"stddev": 0.002048247500706874,
"median": 0.012736514280000001,
"user": 0.007517743124999998,
"system": 0.006373671458333335,
"min": 0.00969412228,
"max": 0.020452285280000003
},
{
"command": "pnpr@main",
"mean": 0.013793876889243701,
"stddev": 0.002718191746513232,
"median": 0.013622206780000002,
"user": 0.0077581072268907555,
"system": 0.00691530151260504,
"min": 0.00923085128,
"max": 0.03029558628
}
]
}Scenario: Isolated linker: repeat install, cold cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.008824422451764711,
"stddev": 0.0012043902008339092,
"median": 0.00853158604,
"user": 0.004658449117647062,
"system": 0.004785711764705884,
"min": 0.007070075540000001,
"max": 0.01439911854
},
{
"command": "pacquet@main",
"mean": 0.009053772406412206,
"stddev": 0.001340484712765607,
"median": 0.00873544854,
"user": 0.004735368549618319,
"system": 0.004923681679389311,
"min": 0.007067320540000001,
"max": 0.014728391540000002
},
{
"command": "pnpr@HEAD",
"mean": 0.008918729190602418,
"stddev": 0.0014135356864533259,
"median": 0.008568615540000001,
"user": 0.0050240844979919696,
"system": 0.004488903775100401,
"min": 0.00691489754,
"max": 0.01449866854
},
{
"command": "pnpr@main",
"mean": 0.009339080300869563,
"stddev": 0.0013630273950884458,
"median": 0.00914480104,
"user": 0.005183340579710145,
"system": 0.004732194782608693,
"min": 0.007062004540000001,
"max": 0.015485724540000002
}
]
}Scenario: Isolated linker: fresh install, cold cache + cold store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 2.53856065672,
"stddev": 0.15546172992524276,
"median": 2.4746429271199997,
"user": 2.02003902,
"system": 1.7088479199999997,
"min": 2.44572979262,
"max": 2.94136093562
},
{
"command": "pacquet@main",
"mean": 2.4602549239199996,
"stddev": 0.03000577593603676,
"median": 2.45103315062,
"user": 1.7697591199999998,
"system": 1.41723152,
"min": 2.43471564262,
"max": 2.54157143062
},
{
"command": "pnpr@HEAD",
"mean": 1.5810875972200003,
"stddev": 0.1337220983921828,
"median": 1.5988028111200001,
"user": 1.22420402,
"system": 1.23068582,
"min": 1.3743469586200001,
"max": 1.74241111962
},
{
"command": "pnpr@main",
"mean": 1.5326838017200002,
"stddev": 0.12146218015850768,
"median": 1.5086992541200002,
"user": 1.3184926199999996,
"system": 1.26838302,
"min": 1.4168292746200002,
"max": 1.7229178126200002
}
]
}Scenario: Isolated linker: fresh install, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.58448444292,
"stddev": 0.017981847762005752,
"median": 0.5875354178200001,
"user": 0.8116554399999998,
"system": 1.01644164,
"min": 0.5436086573200001,
"max": 0.6163820313200001
},
{
"command": "pacquet@main",
"mean": 0.5609992886200003,
"stddev": 0.022602478670347183,
"median": 0.56719648732,
"user": 0.81612084,
"system": 0.96124314,
"min": 0.5269518043200001,
"max": 0.5972979533200001
},
{
"command": "pnpr@HEAD",
"mean": 0.35197110992,
"stddev": 0.011315894464768385,
"median": 0.34905289682000007,
"user": 0.29956904,
"system": 0.71731454,
"min": 0.33914000932,
"max": 0.38008640732000004
},
{
"command": "pnpr@main",
"mean": 0.42574041212,
"stddev": 0.10866191874911627,
"median": 0.36476476582,
"user": 0.35105704000000004,
"system": 0.9122313400000002,
"min": 0.34659251032,
"max": 0.5966442753200001
}
]
}Scenario: Isolated linker: fresh install, cold cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 1.61453714508,
"stddev": 0.009938435788771871,
"median": 1.6147837168799999,
"user": 0.80001094,
"system": 0.77747976,
"min": 1.59607954838,
"max": 1.62668502038
},
{
"command": "pacquet@main",
"mean": 1.6320324756799998,
"stddev": 0.08681053379417616,
"median": 1.60618064788,
"user": 0.8751296399999997,
"system": 0.8092366599999998,
"min": 1.5536832403799998,
"max": 1.8647681133799998
},
{
"command": "pnpr@HEAD",
"mean": 0.2794331312800001,
"stddev": 0.006163569353838841,
"median": 0.28086876088,
"user": 0.22101273999999999,
"system": 0.53037876,
"min": 0.26432497738000005,
"max": 0.28477453538
},
{
"command": "pnpr@main",
"mean": 0.27217931298000003,
"stddev": 0.013949164293609578,
"median": 0.27192701488000004,
"user": 0.21402764,
"system": 0.49365316000000004,
"min": 0.25219441238,
"max": 0.29223244138000004
}
]
}Scenario: Isolated linker: fresh resolve, hot cache, offline
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.34275598138,
"stddev": 0.026261106510196492,
"median": 0.33844271857999997,
"user": 0.3508054,
"system": 0.16250312,
"min": 0.30204952007999997,
"max": 0.39190578308
},
{
"command": "pacquet@main",
"mean": 0.25592315217999995,
"stddev": 0.04161107990840154,
"median": 0.23995914358000003,
"user": 0.2728292,
"system": 0.10915181999999998,
"min": 0.21605063708000002,
"max": 0.32940447708
},
{
"command": "pnpr@HEAD",
"mean": 0.0945385333703226,
"stddev": 0.0049600140194312504,
"median": 0.09370077808,
"user": 0.03389388064516128,
"system": 0.017772119999999995,
"min": 0.08756427608,
"max": 0.10699040308
},
{
"command": "pnpr@main",
"mean": 0.10098970879428569,
"stddev": 0.003153057309240338,
"median": 0.10139544158000001,
"user": 0.038196157142857144,
"system": 0.022531191428571427,
"min": 0.09382471508000001,
"max": 0.10661188708000001
}
]
}Scenario: Isolated linker: peer-heavy resolve, hot cache, offline
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.7142937888555556,
"stddev": 0.07258484155079123,
"median": 0.7026928493000001,
"user": 0.7276626244444445,
"system": 0.19444892000000003,
"min": 0.6304688413,
"max": 0.8756627483000001
},
{
"command": "pacquet@main",
"mean": 0.7557812386333335,
"stddev": 0.10259268455342399,
"median": 0.7607680183000001,
"user": 0.7692145133333333,
"system": 0.20227380888888885,
"min": 0.6062800263000001,
"max": 0.8742078183
},
{
"command": "pnpm@HEAD",
"mean": 3.5201675104111114,
"stddev": 0.10620090244245078,
"median": 3.4750185843,
"user": 5.123999402222222,
"system": 0.3147761422222223,
"min": 3.3705762082999997,
"max": 3.6933629313
}
]
}Scenario: Isolated linker: linked-workspace resolve, hot cache, offline
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.16815280795333332,
"stddev": 0.00712564978895328,
"median": 0.16648589462000002,
"user": 0.12004275555555559,
"system": 0.08515842888888889,
"min": 0.15862090512,
"max": 0.18218088512
},
{
"command": "pacquet@main",
"mean": 0.16662063164941177,
"stddev": 0.008012649433260449,
"median": 0.16712464312,
"user": 0.12027034705882353,
"system": 0.08208274588235293,
"min": 0.15791237612,
"max": 0.18086361412
}
]
}Scenario: Isolated linker: fresh restore, cold cache + cold store + cold pnpr
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 4.7233758125000005,
"stddev": 0.17144636435150815,
"median": 4.6898547886,
"user": 2.40259228,
"system": 1.9341534800000002,
"min": 4.5193453616,
"max": 4.976472777600001
},
{
"command": "pacquet@main",
"mean": 4.6716443763,
"stddev": 0.17369340834501903,
"median": 4.6315520276,
"user": 2.24653768,
"system": 1.76673578,
"min": 4.4701270666,
"max": 5.0532187626
},
{
"command": "pnpr@HEAD",
"mean": 3.5667920975,
"stddev": 0.09886939677090331,
"median": 3.5264223590999997,
"user": 1.74414048,
"system": 1.6666792799999997,
"min": 3.4802461886,
"max": 3.7966346016
},
{
"command": "pnpr@main",
"mean": 3.611417383199999,
"stddev": 0.1342109773102486,
"median": 3.5762727000999996,
"user": 1.7302722799999999,
"system": 1.6921062800000002,
"min": 3.4528183506,
"max": 3.8647426726
}
]
}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.15489513597529414,
"stddev": 0.0160044466240417,
"median": 0.14868170474,
"user": 0.1892658211764706,
"system": 0.16925963764705876,
"min": 0.13963533174,
"max": 0.20489238574000002
},
{
"command": "pacquet@main",
"mean": 0.19389464627846154,
"stddev": 0.026467820618440684,
"median": 0.17888861974,
"user": 0.23475595692307688,
"system": 0.2053865969230769,
"min": 0.16271300974000003,
"max": 0.24999746774
},
{
"command": "pnpr@HEAD",
"mean": 0.25891397104,
"stddev": 0.01932160983869518,
"median": 0.25938999523999995,
"user": 0.28584797999999995,
"system": 0.26968492000000005,
"min": 0.23087315874000003,
"max": 0.30190264974
},
{
"command": "pnpr@main",
"mean": 0.22203363954000005,
"stddev": 0.042561957501878266,
"median": 0.19851229824000002,
"user": 0.27070567999999995,
"system": 0.21421592,
"min": 0.17949168774000002,
"max": 0.28339376274
}
]
} |
PR Summary by QodoPreserve dependencies also declared as optional peers
AI Description
Diagram
High-Level Assessment
Files changed (8)
|
Code Review by Qodo
1. Two multiline calls miss final commas
|
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
Code review by qodo was updated up to the latest commit 33c89e3 |
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
…pm#15503) When autoInstallPeers is on, the resolver removed every name listed in a package's peerDependencies from its dependencies, expecting the peer to be auto-installed. Optional peers are never auto-installed, so a package that both depends on something and declares it as an optional peer (vite's lightningcss) ended up with neither. Such a dependency is now removed only when an ancestor already provides it, the same rule autoInstallPeers=false uses, so it keeps its own dependency range. Fixed in both the TypeScript and the Rust resolver, with a new registry fixture shaped like vite's manifest. Closes pnpm#8912
…ge (#16658) 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
Summary
Fixes a dependency going missing when a package declares it both in
dependenciesand as an optional peer, the shape vite uses forlightningcss(the reproduction in #8912).With
autoInstallPeerson, both resolvers removed every name listed inpeerDependenciesfrom the package's owndependencies, expecting the peer edge to supply it through auto-install. Optional peers are never auto-installed, so the package ended up with neither. An optional peer is now removed fromdependenciesonly when an ancestor already provides it, the same ruleautoInstallPeers: falseuses. Otherwise it stays a regular dependency and keeps its own range.pnpm11/installing/deps-resolver/src/resolveDependencies.tspeer_shadowed_dependenciesinpnpm/crates/resolving-deps-resolver/src/parent_pkg_aliases.rsIt supersedes #8916. That PR marked the peer as required, which installs it with the peer range, not the dependency range. Its fixture also declared the dependency only in
peerDependenciesMeta, which never reaches the code that drops it.New fixture
@pnpm.e2e/has-optional-peer-also-in-depspins@pnpm.e2e/[email protected]as a dependency and^1.0.0as an optional peer, and1.1.0exists, so the tests also check which range wins. Both stacks testautoInstallPeerstrue and false, including a second resolve that reuses the lockfile. With the resolver reverted to main, thetruecase fails in both stacks and thefalsecase passes.Closes #8912
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).
🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Summary by CodeRabbit
node_modules, whether automatic peer installation is enabled or disabled.