Skip to content

fix(resolver): install a dependency that is also an optional peer - #15503

Merged
zkochan merged 3 commits into
mainfrom
fix/optional-peer-also-dep
Sep 24, 2026
Merged

zkochan merged 3 commits into
mainfrom
fix/optional-peer-also-dep

Conversation

@zkochan

@zkochan zkochan commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

Summary

Fixes a dependency going missing when a package declares it both in dependencies and as an optional peer, the shape vite uses for lightningcss (the reproduction in #8912).

With autoInstallPeers on, both resolvers removed every name listed in peerDependencies from the package's own dependencies, 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 from dependencies only when an ancestor already provides it, the same rule autoInstallPeers: false uses. Otherwise it stays a regular dependency and keeps its own range.

  • v11: pnpm11/installing/deps-resolver/src/resolveDependencies.ts
  • v12: peer_shadowed_dependencies in pnpm/crates/resolving-deps-resolver/src/parent_pkg_aliases.rs

It 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-deps pins @pnpm.e2e/[email protected] as a dependency and ^1.0.0 as an optional peer, and 1.1.0 exists, so the tests also check which range wins. Both stacks test autoInstallPeers true and false, including a second resolve that reuses the lockfile. With the resolver reverted to main, the true case fails in both stacks and the false case passes.

Closes #8912

Squash Commit Body

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/pnpm#8912

Checklist

  • I checked the referenced issue and verified that none of the PRs
    already linked to it solves it.
  • New features are implemented only in the Rust pnpm v12 CLI. Bug fixes
    are implemented in every affected version.
  • Added a changeset (pnpm changeset) if this PR changes any published
    package. Keep it short and written for pnpm users — it becomes a release note.
  • Added or updated tests.

Written by an agent (Claude Code, claude-opus-5-5).

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Summary by CodeRabbit

  • Bug Fixes
    • Optional peer dependencies that are also regular dependencies are now installed and remain available in node_modules, whether automatic peer installation is enabled or disabled.
    • Existing dependency versions are preserved when installing additional packages.

zkochan and others added 2 commits September 24, 2026 08:41
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]>
@coderabbitai

coderabbitai Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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 configuration

Configuration used: Repository: pnpm/pnpm/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: edb1bb21-59c5-481f-9e99-a5ed88a3f307

📥 Commits

Reviewing files that changed from the base of the PR and between 0f2e8d7 and 33c89e3.

📒 Files selected for processing (2)
  • pnpm/crates/cli/tests/suite/install/peers.rs
  • pnpm11/installing/deps-resolver/src/resolveDependencies.ts
💤 Files with no reviewable changes (1)
  • pnpm11/installing/deps-resolver/src/resolveDependencies.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • pnpm/crates/cli/tests/suite/install/peers.rs

Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The 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 autoInstallPeers settings and lockfile reuse after adding another dependency.

Changes

Optional peer dependency installation

Layer / File(s) Summary
Optional peer handling in dependency resolution
pnpr/.fixtures/packages/@pnpm.e2e/has-optional-peer-also-in-deps/1.0.0/package.json, pnpm/crates/resolving-deps-resolver/src/parent_pkg_aliases.rs, pnpm11/installing/deps-resolver/src/resolveDependencies.ts, pnpm/crates/resolving-deps-resolver/src/parent_pkg_aliases/tests.rs
The Rust and TypeScript resolvers check optional-peer metadata before removing a peer from regular dependencies. The fixture and resolver test cover a package that declares the same package as a dependency and an optional peer.
Install regression coverage and release metadata
pnpm/crates/cli/tests/suite/install/peers.rs, pnpm11/installing/deps-installer/test/install/peerDependencies.ts, .changeset/optional-peer-also-a-dependency.md, cspell.json
Install tests check the lockfile and installed package directory with automatic peer installation enabled and disabled, including after another dependency is added. A changeset declares patch releases, and the spelling dictionary adds lightningcss.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix · Severity of issue fixed: Medium

Assessment against linked issues

Objective Addressed Explanation
Install lightningcss as a dependency of vite so it is present in the package’s installed directory [#8912] ✅

Suggested labels: product: pnpm@11, product: pacquet, product: pnpr

Merge Risk: ⚪ Minimal · up to 33c89

The change can proceed through normal checks; no actionable merge-blocking issue is established.

✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov-commenter

codecov-commenter commented Sep 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.83%. Comparing base (b809cfd) to head (33c89e3).
⚠️ Report is 14 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Micro-Benchmark Results

Linux

group                                            main                                   pr
-----                                            ----                                   --
lockfile/parse_pnpm_lock                         1.00     11.5±0.06ms    32.7 MB/sec    1.10     12.6±0.54ms    29.7 MB/sec
packument/parse                                  1.00     39.0±0.14µs  1699.7 MB/sec    1.07     41.8±0.37µs  1586.0 MB/sec
tarball/download_dependency                      1.00      4.1±0.08ms  1066.7 KB/sec    1.01      4.1±0.21ms  1060.0 KB/sec
tarball_batch/cold_store_many_medium_tarballs    1.00    184.9±5.53ms 86.5 KElem/sec    1.12   207.5±10.24ms 77.1 KElem/sec
workspace_resolution/hoist_heavy                 1.00    247.8±5.48ms        ? ?/sec    1.40   346.1±35.51ms        ? ?/sec
workspace_sort/chained_projects                  1.00     13.7±0.97ms        ? ?/sec    1.04     14.3±1.63ms        ? ?/sec

@zkochan
zkochan marked this pull request as ready for review September 24, 2026 07:00
@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Same-run regression check

HEAD 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.

Scenario Engine main median HEAD median Change Tolerance Result
isolated-fresh-restore-cold-cache-cold-store pacquet 2625.72 ms 2566.53 ms -2.3% 131.29 ms Within tolerance
isolated-fresh-restore-cold-cache-cold-store pnpr 1402.05 ms 1470.30 ms 4.9% 70.10 ms Within tolerance
isolated-fresh-restore-hot-cache-hot-store pacquet 237.40 ms 260.25 ms 9.6% 11.87 ms Inconclusive (overlapping samples)
isolated-fresh-restore-hot-cache-hot-store pnpr 259.64 ms 258.48 ms -0.4% 12.98 ms Within tolerance
isolated-repeat-install-hot-cache-hot-store pacquet 7.79 ms 7.44 ms -4.6% 2.00 ms Within tolerance
isolated-repeat-install-hot-cache-hot-store pnpr 13.62 ms 12.74 ms -6.5% 2.00 ms Within tolerance
isolated-repeat-install-cold-cache-hot-store pacquet 8.74 ms 8.53 ms -2.3% 2.00 ms Within tolerance
isolated-repeat-install-cold-cache-hot-store pnpr 9.14 ms 8.57 ms -6.3% 2.00 ms Within tolerance
isolated-fresh-install-cold-cache-cold-store pacquet 2451.03 ms 2474.64 ms 1.0% 122.55 ms Within tolerance
isolated-fresh-install-cold-cache-cold-store pnpr 1508.70 ms 1598.80 ms 6.0% 75.43 ms Inconclusive (overlapping samples)
isolated-fresh-install-hot-cache-hot-store pacquet 567.20 ms 587.54 ms 3.6% 28.36 ms Within tolerance
isolated-fresh-install-hot-cache-hot-store pnpr 364.76 ms 349.05 ms -4.3% 18.24 ms Within tolerance
isolated-fresh-install-cold-cache-hot-store pacquet 1606.18 ms 1614.78 ms 0.5% 80.31 ms Within tolerance
isolated-fresh-install-cold-cache-hot-store pnpr 271.93 ms 280.87 ms 3.3% 13.60 ms Within tolerance
isolated-fresh-resolve-hot-cache-offline pacquet 239.96 ms 338.44 ms 41.0% 12.00 ms Inconclusive (overlapping samples)
isolated-fresh-resolve-hot-cache-offline pnpr 101.40 ms 93.70 ms -7.6% 5.07 ms Within tolerance
isolated-peer-heavy-resolve-hot-cache-offline pacquet 760.77 ms 702.69 ms -7.6% 38.04 ms Within tolerance
isolated-linked-workspace-resolve-hot-cache-offline pacquet 167.12 ms 166.49 ms -0.4% 8.36 ms Within tolerance
isolated-fresh-restore-cold-cache-cold-store-cold-pnpr pacquet 4631.55 ms 4689.85 ms 1.3% 231.58 ms Within tolerance
isolated-fresh-restore-cold-cache-cold-store-cold-pnpr pnpr 3576.27 ms 3526.42 ms -1.4% 178.81 ms Within tolerance
gvs-fresh-restore-hot-cache-hot-store pacquet 178.89 ms 148.68 ms -16.9% 8.94 ms Within tolerance
gvs-fresh-restore-hot-cache-hot-store pnpr 198.51 ms 259.39 ms 30.7% 9.93 ms Inconclusive (overlapping samples)

Integrated-Benchmark Report (Linux)

Commit: 33c89e31319b

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 2.574 ± 0.122 2.358 2.823 1.80 ± 0.14
pacquet@main 2.575 ± 0.131 2.376 2.735 1.80 ± 0.14
pnpr@HEAD 1.456 ± 0.120 1.303 1.605 1.02 ± 0.11
pnpr@main 1.427 ± 0.088 1.307 1.594 1.00
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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 262.9 ± 26.5 229.5 312.1 1.10 ± 0.15
pacquet@main 238.4 ± 20.3 210.7 271.8 1.00
pnpr@HEAD 259.0 ± 10.4 242.0 275.6 1.09 ± 0.10
pnpr@main 262.3 ± 18.0 243.6 302.6 1.10 ± 0.12
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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 7.7 ± 0.9 6.6 11.8 1.00
pacquet@main 8.5 ± 1.7 6.6 17.2 1.09 ± 0.25
pnpr@HEAD 13.0 ± 2.0 9.7 20.5 1.69 ± 0.33
pnpr@main 13.8 ± 2.7 9.2 30.3 1.78 ± 0.41
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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 8.8 ± 1.2 7.1 14.4 1.00
pacquet@main 9.1 ± 1.3 7.1 14.7 1.03 ± 0.21
pnpr@HEAD 8.9 ± 1.4 6.9 14.5 1.01 ± 0.21
pnpr@main 9.3 ± 1.4 7.1 15.5 1.06 ± 0.21
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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 2.539 ± 0.155 2.446 2.941 1.66 ± 0.17
pacquet@main 2.460 ± 0.030 2.435 2.542 1.61 ± 0.13
pnpr@HEAD 1.581 ± 0.134 1.374 1.742 1.03 ± 0.12
pnpr@main 1.533 ± 0.121 1.417 1.723 1.00
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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 584.5 ± 18.0 543.6 616.4 1.66 ± 0.07
pacquet@main 561.0 ± 22.6 527.0 597.3 1.59 ± 0.08
pnpr@HEAD 352.0 ± 11.3 339.1 380.1 1.00
pnpr@main 425.7 ± 108.7 346.6 596.6 1.21 ± 0.31
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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 1.615 ± 0.010 1.596 1.627 5.93 ± 0.31
pacquet@main 1.632 ± 0.087 1.554 1.865 6.00 ± 0.44
pnpr@HEAD 0.279 ± 0.006 0.264 0.285 1.03 ± 0.06
pnpr@main 0.272 ± 0.014 0.252 0.292 1.00
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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 342.8 ± 26.3 302.0 391.9 3.63 ± 0.34
pacquet@main 255.9 ± 41.6 216.1 329.4 2.71 ± 0.46
pnpr@HEAD 94.5 ± 5.0 87.6 107.0 1.00
pnpr@main 101.0 ± 3.2 93.8 106.6 1.07 ± 0.07
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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 714.3 ± 72.6 630.5 875.7 1.00
pacquet@main 755.8 ± 102.6 606.3 874.2 1.06 ± 0.18
pnpm@HEAD 3520.2 ± 106.2 3370.6 3693.4 4.93 ± 0.52
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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 168.2 ± 7.1 158.6 182.2 1.01 ± 0.06
pacquet@main 166.6 ± 8.0 157.9 180.9 1.00
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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 4.723 ± 0.171 4.519 4.976 1.32 ± 0.06
pacquet@main 4.672 ± 0.174 4.470 5.053 1.31 ± 0.06
pnpr@HEAD 3.567 ± 0.099 3.480 3.797 1.00
pnpr@main 3.611 ± 0.134 3.453 3.865 1.01 ± 0.05
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 store

Same 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.

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 154.9 ± 16.0 139.6 204.9 1.00
pacquet@main 193.9 ± 26.5 162.7 250.0 1.25 ± 0.21
pnpr@HEAD 258.9 ± 19.3 230.9 301.9 1.67 ± 0.21
pnpr@main 222.0 ± 42.6 179.5 283.4 1.43 ± 0.31
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
    }
  ]
}

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Preserve dependencies also declared as optional peers

🐞 Bug fix 🧪 Tests 🕐 20-40 Minutes

Grey Divider

AI Description

• Preserve regular dependencies also declared as optional peers when no ancestor supplies them.
• Apply consistent resolution behavior across TypeScript and Rust resolver implementations.
• Add fresh, lockfile-reuse, and configuration-matrix regression coverage.
Diagram

graph TD
  M["Package manifest"] --> T["TypeScript resolver"] --> O{"Optional peer?"}
  M --> R["Rust resolver"] --> O
  O -->|Yes| A{"Ancestor provides?"} -->|No| K["Keep own range"]
  O -->|No| U{"Auto-install enabled?"} -->|No| A
  A -->|Yes| D["Use peer edge"]
  U -->|Yes| D
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Treat the optional peer as required
  • ➕ Reuses existing required-peer auto-install behavior.
  • ➕ Avoids retaining a nested regular dependency.
  • ➖ Changes the package author's optional-peer semantics.
  • ➖ Selects using the peer range instead of the dependency range.
  • ➖ Can install a newer version than the package explicitly requires.
2. Auto-install all optional peers
  • ➕ Prevents missing optional peers in this specific manifest shape.
  • ➕ Simplifies shadowing by treating all peers uniformly.
  • ➖ Globally changes optional-peer behavior.
  • ➖ Installs packages consumers did not request.
  • ➖ Increases dependency trees and risks compatibility regressions.

Recommendation: The PR's conditional shadowing approach is best. It preserves optional-peer semantics and the package's dependency range while still using an ancestor-provided peer when available, and applying the same rule in both resolver stacks prevents behavioral divergence.

Files changed (8) +190 / -19

Bug fix (2) +29 / -19
parent_pkg_aliases.rsPreserve out-of-scope optional peers as regular dependencies +17/-6

Preserve out-of-scope optional peers as regular dependencies

• Reads 'peerDependenciesMeta' when calculating peer-shadowed dependencies. Optional peers are now removed from regular dependencies only when the parent scope already provides them, while required peers retain existing auto-install behavior.

pnpm/crates/resolving-deps-resolver/src/parent_pkg_aliases.rs

resolveDependencies.tsExclude optional peers from unconditional dependency shadowing +12/-13

Exclude optional peers from unconditional dependency shadowing

• Updates pnpm v11 resolution so automatic peer installation only shadows non-optional peers. Optional peers continue as regular dependencies unless an ancestor alias already satisfies them.

pnpm11/installing/deps-resolver/src/resolveDependencies.ts

Tests (4) +153 / -0
peers.rsAdd Rust CLI regression coverage for dual-declared optional peers +103/-0

Add Rust CLI regression coverage for dual-declared optional peers

• Tests installs with 'autoInstallPeers' enabled and disabled, verifies the dependency uses its exact regular range, and confirms a second lockfile-backed resolve preserves the package. Adds a helper for inspecting the fixture snapshot dependencies.

pnpm/crates/cli/tests/suite/install/peers.rs

tests.rsTest optional peer shadowing against parent scope +15/-0

Test optional peer shadowing against parent scope

• Adds a unit test proving that an in-scope optional peer shadows its regular dependency while an out-of-scope optional peer remains a dependency under automatic peer installation.

pnpm/crates/resolving-deps-resolver/src/parent_pkg_aliases/tests.rs

peerDependencies.tsAdd pnpm v11 optional-peer installation regression test +20/-0

Add pnpm v11 optional-peer installation regression test

• Exercises both 'autoInstallPeers' settings and confirms the fixture installs 'bravo-dep' at its regular dependency version. It also verifies that adding an unrelated package does not remove the dependency from the reused lockfile snapshot.

pnpm11/installing/deps-installer/test/install/peerDependencies.ts

package.jsonAdd a dual-declared optional peer registry fixture +15/-0

Add a dual-declared optional peer registry fixture

• Introduces a package that pins 'bravo-dep' at '1.0.0' as a dependency while also declaring '^1.0.0' as an optional peer. The differing ranges allow tests to verify that the regular dependency range wins.

pnpr/.fixtures/packages/@pnpm.e2e/has-optional-peer-also-in-deps/1.0.0/package.json

Documentation (1) +7 / -0
optional-peer-also-a-dependency.mdDocument the optional peer dependency installation fix +7/-0

Document the optional peer dependency installation fix

• Adds patch release notes for the TypeScript resolver, pnpm, and pacquet. Explains that dependencies also declared as optional peers are now installed instead of disappearing from node_modules.

.changeset/optional-peer-also-a-dependency.md

Other (1) +1 / -0
cspell.jsonAllow the lightningcss package name +1/-0

Allow the lightningcss package name

• Adds 'lightningcss' to the spell-check dictionary for the new release note and resolver documentation.

cspell.json

@qodo-code-review

qodo-code-review Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (2) 📜 Skill insights (0)

Grey Divider


Informational

1. Two multiline calls miss final commas 📘 Rule violation ⚙ Maintainability
Description
omit(...) leaves pkg.dependencies without a trailing comma, and the new multiline test call
likewise ends with testDefaults({ autoInstallPeers }) without one. Both additions create
TypeScript multiline argument lists whose final items violate the required collection formatting and
make later argument additions noisier.
Code

pnpm11/installing/deps-resolver/src/resolveDependencies.ts[R2283-2285]

+        dependencies: omit(
+          Object.keys(pkg.peerDependencies).filter((peerDep) => isAutoInstalledPeer(peerDep) || options.parentPkgAliases[peerDep]),
+          pkg.dependencies
Relevance

● Weak

Recent PR #15340 rejected trailing-comma requests for equivalent multiline TypeScript calls; this
convention is not enforced consistently.

PR-#15340
PR-#14175

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
Compliance rule 713434 requires trailing commas on final items in multiline TypeScript argument
lists. The added production and test calls both omit the comma from their last argument.

Rule 713434: Require trailing commas in TypeScript collections and multi-line constructs
pnpm11/installing/deps-resolver/src/resolveDependencies.ts[2283-2285]
pnpm11/installing/deps-installer/test/install/peerDependencies.ts[2661-2665]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Two newly added multiline TypeScript argument lists omit the required comma after their final argument.

## Fix Focus Areas
- pnpm11/installing/deps-resolver/src/resolveDependencies.ts[2283-2285]
- pnpm11/installing/deps-installer/test/install/peerDependencies.ts[2661-2665]

## Recommended Fix
Add a trailing comma after `pkg.dependencies` in the `omit` call and after `testDefaults({ autoInstallPeers })` in the test's `addDependenciesToPackage` call.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. One changeset mixes both release lines 📘 Rule violation § Compliance
Description
optional-peer-also-a-dependency.md lists pnpm and pacquet in the same front matter even though
the PR changes both release lines. Future release-line-specific edits remain coupled to one release
note because the version targets cannot be maintained independently.
Code

.changeset/optional-peer-also-a-dependency.md[R3-4]

+"pnpm": patch
+"pacquet": patch
Relevance

● Weak

Recent PR #15480 rejected the same pnpm/pacquet combined-changeset pattern under release-line
separation rules.

PR-#15480

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
Compliance rule 713436 requires separate changeset files when one PR changes both the TypeScript v11
and Rust v12 implementations. The added front matter combines the v11 pnpm target and v12
pacquet target in one file.

Rule 713436: Changesets for pnpm v11 vs v12 (pacquet) must target the correct package and bump type
.changeset/optional-peer-also-a-dependency.md[1-7]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The shared bug fix changes both pnpm v11 and v12, but one changeset combines their package targets despite the required per-version separation.

## Fix Focus Areas
- .changeset/optional-peer-also-a-dependency.md[1-7]

## Recommended Fix
Replace the combined changeset with two files. Target `@pnpm/installing.deps-resolver` and `pnpm` in the v11 changeset, and target only `pacquet` in the v12 changeset; retain release-note wording that accurately describes each implementation.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Context sources
✅ Compliance rules (platform): 74 rules
✅ Skills: review-code
Review mode: ⏭️ Skipped: The latest push only removes comments and has no semantic or behavioral changes.

Grey Divider

Tip of the day
💡 Did you know, you can choose which labels appear on a finding, and whether they show icons or text

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

@github-actions github-actions Bot added the reviewed: coderabbit CodeRabbit submitted an approving review label Sep 24, 2026
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 33c89e3

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

u9g pushed a commit to u9g/pnpm that referenced this pull request Sep 25, 2026
…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
zkochan pushed a commit that referenced this pull request Oct 6, 2026
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

transitive dependencies not installed for pkg.pr.new

2 participants