Skip to content

fix(bins): hold back missing bins in the hoisted linker's nested .bin - #15563

Merged
zkochan merged 2 commits into
mainfrom
fix/hoisted-nested-bin-holdback
Sep 24, 2026
Merged

zkochan merged 2 commits into
mainfrom
fix/hoisted-nested-bin-holdback

Conversation

@zkochan

@zkochan zkochan commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

Summary

Follow-up to #15511, which listed this gap as a known limit.

Under nodeLinker: hoisted, a dependency nested in another package's node_modules runs its lifecycle scripts with that package's node_modules/.bin on PATH. The hoisted linker links every nested .bin before builds run and never again. So a nested dependency whose preinstall creates its own bin (the node package's pattern, #15501) found a shim of the missing file on PATH. #15511 fixed this for the project's .bin only, because the post-build relink covers project .bin directories and nothing covered the nested ones.

Both stacks now:

  • Hold back missing-target bins in nested .bin directories as well.
  • Record the directories that held something back.
  • Link those directories again after the builds. A bin whose target is still missing then gets its dependent shim, so the installed result matches today's. The only change is that no shim sits on PATH during the build.

Only the recorded directories are relinked, so a warm hoisted install with no missing targets does no extra work.

Changes:

  • pnpm11/bins/linker: a heldBackBinsDirs option collects the .bin directories that held a bin back.
  • pnpm11/installing/deps-restorer: linkHoistedModules holds back missing-target bins at every level (the flag is renamed to holdBackMissingBins) and returns the nested directories. The headless install relinks them after buildModules.
  • pnpm/crates/cmd-shim: link_bins_of_packages_cached returns whether it held a bin back.
  • pnpm/crates/deps-restorer: link_hoisted_modules returns the nested directories, HoistedLinkerOutput and LinkPhaseOutput carry them, and run_build_phase relinks them before the project .bin pass.
  • pnpr/.fixtures: @pnpm.e2e/[email protected], and @pnpm.e2e/[email protected], which depends on 1.0.0. With 2.0.0 at the root, the hoisted linker nests 1.0.0 under it.

No changeset: #15511 has not been released. Its pending pnpm 12 changeset ("pnpm install no longer puts a dependency's bin on PATH for that dependency's own lifecycle scripts before the bin's file exists") already describes this. In pnpm 11 the nested exposure came from #15511 itself, because cmd-shim used to throw on a missing target.

Squash Commit Body

Under nodeLinker: hoisted, a dependency nested in another package's
node_modules has that package's node_modules/.bin on PATH during its
lifecycle scripts. The hoisted linker links every nested .bin while it
imports the tree, before builds, and never again, so a nested
dependency whose preinstall creates its own bin found a shim of the
missing file on PATH. pnpm/pnpm#15511 held such bins back only in a
project's .bin, which the post-build relink covers.

Both stacks now hold back missing-target bins in nested .bin
directories too, record the directories that held something back, and
link those again after the builds. A bin whose target is still missing
then gets its dependent shim, so the result matches the previous one,
minus the shim on PATH during the build. Only recorded directories are
relinked.

pnpm 11: linkBins reports such directories through a heldBackBinsDirs
option, linkHoistedModules returns them, and the headless install
relinks them after buildModules.

pnpm 12: link_bins_of_packages_cached returns whether it held a bin
back, link_hoisted_modules returns the directories, and they reach
run_build_phase through the link phase output.

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. Not needed: this completes the unreleased fix(bins): link a dependency's bin before its target exists #15511, whose pending changeset covers it.
  • Added or updated tests.

Verification

  • pnpm 12:
    • own_bin_is_not_on_path_before_preinstall_creates_it_when_nested_by_hoisted_linker failed before the change, with the shim in nests-own-bin-created-by-preinstall/node_modules/.bin. It passes now.
    • With the relink of recorded directories disabled, the same test fails on the missing nested bin.
    • 1317 tests pass across pnpm-cmd-shim, pnpm-deps-restorer, and the CLI lifecycle-script, bin, hoist, allow-build, rebuild and patch suites. Clippy and dylint are clean.
  • pnpm 11:
    • The new nested e2e passes, along with the other three own-bin e2e tests.
    • It fails with the nested hold-back removed from the bundle.
    • @pnpm/bins.linker tests: 44 passed.
  • Not run locally: Windows. Windows CI runs the e2e tests; the fixture checks .cmd and .ps1 shims there.

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
    • Hoisted installs now defer executable links when their targets are missing and retry linking after package build scripts finish. This prevents unavailable commands from appearing on PATH before they exist.
    • Fixed nested and bundled dependencies so their executable links are handled consistently during installation.

The hoisted linker links every `node_modules/.bin` while it imports the
tree, before builds run. A dependency nested under another package also
has that package's `node_modules/.bin` on PATH during its lifecycle
scripts, so a shim of a bin its preinstall has yet to create shadowed
the command there, as it did in a project's `.bin` before
#15511. Nothing linked those nested directories again after
the builds, so they could not simply hold the bins back.

Both stacks now hold back missing-target bins in nested directories
too, record the directories that held something back, and link them
again once the builds ran. A bin whose target is still missing then gets
its dependent shim, so the result matches the previous behavior, minus
the shim on PATH during the build.

In pnpm 11 `linkBins` reports such directories through a new
`heldBackBinsDirs` option, `linkHoistedModules` returns them, and the
headless install relinks them after `buildModules`. In pnpm 12
`link_bins_of_packages_cached` returns whether it held a bin back,
`link_hoisted_modules` returns the directories, and `run_build_phase`
relinks them.

Adds `@pnpm.e2e/[email protected]` and
`@pnpm.e2e/nests-own-bin-created-by-preinstall`, which nests 1.0.0
under the hoisted linker, and an e2e per stack.

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: 1c4c1329-74ee-4d1c-9f41-588e3be5de81

📥 Commits

Reviewing files that changed from the base of the PR and between e9dd9b7 and 7d73e2c.

📒 Files selected for processing (21)
  • pnpm/crates/cli/tests/suite/lifecycle_scripts/dependency_build_scripts.rs
  • pnpm/crates/cmd-shim/src/link_bins.rs
  • pnpm/crates/cmd-shim/src/link_bins/tests/behavior.rs
  • pnpm/crates/deps-restorer/src/install_frozen_lockfile/build_phase.rs
  • pnpm/crates/deps-restorer/src/install_frozen_lockfile/build_phase/tests.rs
  • pnpm/crates/deps-restorer/src/install_frozen_lockfile/hoisted.rs
  • pnpm/crates/deps-restorer/src/install_frozen_lockfile/hoisted/direct_links.rs
  • pnpm/crates/deps-restorer/src/install_frozen_lockfile/materialization.rs
  • pnpm/crates/deps-restorer/src/link_bins/direct.rs
  • pnpm/crates/deps-restorer/src/link_hoisted_modules.rs
  • pnpm/crates/deps-restorer/src/link_hoisted_modules/tests.rs
  • pnpm/crates/deps-restorer/src/linking.rs
  • pnpm/crates/package-manager/src/install_with_fresh_lockfile/on_disk.rs
  • pnpm11/bins/linker/src/index.ts
  • pnpm11/bins/linker/test/index.ts
  • pnpm11/installing/deps-restorer/src/index.ts
  • pnpm11/installing/deps-restorer/src/linkHoistedModules.ts
  • pnpm11/pnpm/test/install/lifecycleScripts.ts
  • pnpr/.fixtures/packages/@pnpm.e2e/nests-own-bin-created-by-preinstall/1.0.0/package.json
  • pnpr/.fixtures/packages/@pnpm.e2e/own-bin-created-by-preinstall/2.0.0/create-bin.js
  • pnpr/.fixtures/packages/@pnpm.e2e/own-bin-created-by-preinstall/2.0.0/package.json

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


📝 Walkthrough

Walkthrough

The Rust and TypeScript hoisted linkers now report directories where bins were held back because targets are missing. Install build phases retain those directories and link their dependency bins after build processing. Tests cover the linker behavior and nested preinstall-created binaries.

Changes

Held-back bin relinking

Layer / File(s) Summary
Report held-back bins
pnpm/crates/cmd-shim/src/link_bins.rs, pnpm/crates/cmd-shim/src/link_bins/tests/behavior.rs, pnpm/crates/deps-restorer/src/link_bins/direct.rs, pnpm/crates/deps-restorer/src/install_frozen_lockfile/hoisted/direct_links.rs, pnpm11/bins/linker/src/index.ts, pnpm11/bins/linker/test/index.ts
The Rust bin-linking APIs return whether they held back a bin. The TypeScript linker can record the affected .bin directory.
Collect held-back directories
pnpm/crates/deps-restorer/src/link_hoisted_modules.rs, pnpm/crates/deps-restorer/src/link_hoisted_modules/tests.rs, pnpm/crates/deps-restorer/src/install_frozen_lockfile/hoisted.rs, pnpm/crates/deps-restorer/src/linking.rs, pnpm11/installing/deps-restorer/src/linkHoistedModules.ts
The Rust and TypeScript hoisted linkers collect directories with held-back bins and return them through linker outputs. The Rust test checks a bundled package with a missing bin target.
Relink bins after builds
pnpm/crates/deps-restorer/src/install_frozen_lockfile/build_phase.rs, pnpm/crates/deps-restorer/src/install_frozen_lockfile/build_phase/tests.rs, pnpm/crates/deps-restorer/src/install_frozen_lockfile/materialization.rs, pnpm/crates/package-manager/src/install_with_fresh_lockfile/on_disk.rs, pnpm11/installing/deps-restorer/src/index.ts
The Rust build phase and TypeScript install flow receive the collected directories and link their dependency bins after build processing.
Verify nested preinstall behavior
pnpm/crates/cli/tests/suite/lifecycle_scripts/dependency_build_scripts.rs, pnpm11/pnpm/test/install/lifecycleScripts.ts, pnpr/.fixtures/packages/@pnpm.e2e/nests-own-bin-created-by-preinstall/1.0.0/package.json, pnpr/.fixtures/packages/@pnpm.e2e/own-bin-created-by-preinstall/2.0.0/*
Rust and TypeScript tests cover default and hoisted linker installs, including nested packages whose preinstall scripts create their bin targets. The fixtures define the nested dependency and bin-creating package.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant link_hoisted_modules
  participant LinkPhaseOutput
  participant run_build_phase
  participant link_held_back_bins
  link_hoisted_modules->>LinkPhaseOutput: held-back bin directories
  LinkPhaseOutput->>run_build_phase: held_back_bins_dirs
  run_build_phase->>run_build_phase: process dependency builds
  run_build_phase->>link_held_back_bins: link bins after build processing
Loading

Suggested reviewers: altaywtf, efedurmaz16

Merge Risk: ⚪ Minimal · up to 7d73e

The reviewed install paths relink deferred bins after dependency builds. No issue requiring a pre-merge fix was 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

Warning

Some tools did not complete. Review the errors below.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

pnpm11/bins/linker/src/index.ts

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.

pnpm11/bins/linker/test/index.ts

ESLint skipped: the matched ESLint configuration already failed (missing-dependency).

pnpm11/installing/deps-restorer/src/index.ts

ESLint skipped: the matched ESLint configuration already failed (missing-dependency).

  • 5 others

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.

@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     14.3±0.68ms    26.2 MB/sec    1.00     14.3±0.77ms    26.1 MB/sec
packument/parse                                  1.00     44.5±2.37µs  1492.0 MB/sec    1.01     45.1±4.38µs  1472.4 MB/sec
tarball/download_dependency                      1.00      5.1±0.50ms   852.9 KB/sec    1.06      5.4±0.65ms   802.0 KB/sec
tarball_batch/cold_store_many_medium_tarballs    1.00   255.6±14.22ms 62.6 KElem/sec    1.02   260.5±11.66ms 61.4 KElem/sec
workspace_resolution/hoist_heavy                 1.00   332.9±14.26ms        ? ?/sec    1.05   350.8±37.10ms        ? ?/sec
workspace_sort/chained_projects                  1.00     20.3±3.23ms        ? ?/sec    1.01     20.5±2.55ms        ? ?/sec

@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.80%. Comparing base (e9dd9b7) to head (7d73e2c).

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #15563   +/-   ##
=======================================
  Coverage   91.80%   91.80%           
=======================================
  Files        1427     1427           
  Lines      192704   192755   +51     
=======================================
+ Hits       176917   176967   +50     
- Misses      15787    15788    +1     

☔ 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

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 2833.96 ms 2976.65 ms 5.0% 141.70 ms Inconclusive (overlapping samples)
isolated-fresh-restore-cold-cache-cold-store pnpr 1512.85 ms 1494.52 ms -1.2% 75.64 ms Within tolerance
isolated-fresh-restore-hot-cache-hot-store pacquet 246.51 ms 262.10 ms 6.3% 12.33 ms Inconclusive (overlapping samples)
isolated-fresh-restore-hot-cache-hot-store pnpr 318.47 ms 291.16 ms -8.6% 15.92 ms Within tolerance
isolated-repeat-install-hot-cache-hot-store pacquet 13.37 ms 10.39 ms -22.3% 2.00 ms Within tolerance
isolated-repeat-install-hot-cache-hot-store pnpr 14.08 ms 14.75 ms 4.7% 2.00 ms Within tolerance
isolated-repeat-install-cold-cache-hot-store pacquet 12.95 ms 12.59 ms -2.7% 2.00 ms Within tolerance
isolated-repeat-install-cold-cache-hot-store pnpr 12.99 ms 11.15 ms -14.2% 2.00 ms Within tolerance
isolated-fresh-install-cold-cache-cold-store pacquet 2817.28 ms 2901.88 ms 3.0% 140.86 ms Within tolerance
isolated-fresh-install-cold-cache-cold-store pnpr 1597.45 ms 1652.63 ms 3.5% 79.87 ms Within tolerance
isolated-fresh-install-hot-cache-hot-store pacquet 545.20 ms 579.62 ms 6.3% 27.26 ms Inconclusive (overlapping samples)
isolated-fresh-install-hot-cache-hot-store pnpr 387.59 ms 325.92 ms -15.9% 19.38 ms Within tolerance
isolated-fresh-install-cold-cache-hot-store pacquet 1695.35 ms 1858.00 ms 9.6% 84.77 ms Inconclusive (overlapping samples)
isolated-fresh-install-cold-cache-hot-store pnpr 371.87 ms 298.19 ms -19.8% 18.59 ms Within tolerance
isolated-fresh-resolve-hot-cache-offline pacquet 496.23 ms 536.26 ms 8.1% 24.81 ms Inconclusive (overlapping samples)
isolated-fresh-resolve-hot-cache-offline pnpr 122.32 ms 127.22 ms 4.0% 6.12 ms Within tolerance
isolated-peer-heavy-resolve-hot-cache-offline pacquet 1054.52 ms 885.70 ms -16.0% 52.73 ms Within tolerance
isolated-linked-workspace-resolve-hot-cache-offline pacquet 197.15 ms 187.76 ms -4.8% 9.86 ms Within tolerance
isolated-fresh-restore-cold-cache-cold-store-cold-pnpr pacquet 4525.03 ms 4747.36 ms 4.9% 226.25 ms Within tolerance
isolated-fresh-restore-cold-cache-cold-store-cold-pnpr pnpr 3615.92 ms 3523.66 ms -2.6% 180.80 ms Within tolerance
gvs-fresh-restore-hot-cache-hot-store pacquet 201.18 ms 178.27 ms -11.4% 10.06 ms Within tolerance
gvs-fresh-restore-hot-cache-hot-store pnpr 242.58 ms 231.78 ms -4.5% 12.13 ms Within tolerance

Integrated-Benchmark Report (Linux)

Commit: 7d73e2c0d28c

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.995 ± 0.111 2.835 3.210 1.99 ± 0.16
pacquet@main 2.799 ± 0.155 2.516 3.028 1.86 ± 0.17
pnpr@HEAD 1.519 ± 0.135 1.368 1.707 1.01 ± 0.11
pnpr@main 1.508 ± 0.107 1.354 1.656 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.99537147278,
      "stddev": 0.11142008639555889,
      "median": 2.97665005638,
      "user": 2.97587874,
      "system": 2.4570804799999992,
      "min": 2.8347885913799997,
      "max": 3.21017202138
    },
    {
      "command": "pacquet@main",
      "mean": 2.79885465578,
      "stddev": 0.15499645053397795,
      "median": 2.83396000738,
      "user": 2.7800571400000003,
      "system": 2.2743852799999997,
      "min": 2.51571083638,
      "max": 3.02756804738
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.5193998046800001,
      "stddev": 0.13466405736418674,
      "median": 1.49451790588,
      "user": 1.71002774,
      "system": 1.6382372800000002,
      "min": 1.36807272838,
      "max": 1.70747574738
    },
    {
      "command": "pnpr@main",
      "mean": 1.5077464135800003,
      "stddev": 0.10659396832501387,
      "median": 1.5128469773800002,
      "user": 1.7371572399999997,
      "system": 1.64497118,
      "min": 1.35434123038,
      "max": 1.65623997638
    }
  ]
}

Scenario: Isolated linker: fresh restore, hot cache + hot store

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 260.5 ± 12.9 241.4 280.4 1.03 ± 0.09
pacquet@main 252.1 ± 19.4 227.1 286.9 1.00
pnpr@HEAD 309.9 ± 56.0 253.0 453.4 1.23 ± 0.24
pnpr@main 318.9 ± 36.1 261.6 397.7 1.27 ± 0.17
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.26052572002,
      "stddev": 0.012870920978060774,
      "median": 0.26210038722,
      "user": 0.29792752,
      "system": 0.60608842,
      "min": 0.24138307022000002,
      "max": 0.28041789922000004
    },
    {
      "command": "pacquet@main",
      "mean": 0.25206522082,
      "stddev": 0.019435521531377575,
      "median": 0.24651169072,
      "user": 0.26914942,
      "system": 0.60071702,
      "min": 0.22712722022,
      "max": 0.28687321922000003
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.30990091062,
      "stddev": 0.05601337724063494,
      "median": 0.29116008672000004,
      "user": 0.32397631999999993,
      "system": 0.6652249200000001,
      "min": 0.25299175522,
      "max": 0.45339397822000005
    },
    {
      "command": "pnpr@main",
      "mean": 0.31889484382000005,
      "stddev": 0.036110174340821824,
      "median": 0.31847406922000004,
      "user": 0.33584522,
      "system": 0.66056152,
      "min": 0.26161843422000003,
      "max": 0.39772161222
    }
  ]
}

Scenario: Isolated linker: repeat install, hot cache + hot store

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 10.5 ± 1.9 7.1 16.3 1.00
pacquet@main 14.0 ± 4.2 6.8 30.8 1.34 ± 0.47
pnpr@HEAD 15.4 ± 3.3 10.5 28.3 1.48 ± 0.42
pnpr@main 14.6 ± 3.2 10.0 25.8 1.39 ± 0.40
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.010454824144549768,
      "stddev": 0.0019434982795738776,
      "median": 0.0103853335,
      "user": 0.006147420473933644,
      "system": 0.004978316398104266,
      "min": 0.007098334500000001,
      "max": 0.0163394855
    },
    {
      "command": "pacquet@main",
      "mean": 0.013959267946601933,
      "stddev": 0.004208546049200363,
      "median": 0.013371075,
      "user": 0.008144539417475727,
      "system": 0.006636957475728157,
      "min": 0.006827366500000001,
      "max": 0.0307917455
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.015433222136363632,
      "stddev": 0.0033203473089167064,
      "median": 0.0147453595,
      "user": 0.008648241590909088,
      "system": 0.0076685100000000025,
      "min": 0.0104848995,
      "max": 0.028280225500000002
    },
    {
      "command": "pnpr@main",
      "mean": 0.014573933121951222,
      "stddev": 0.0032382448589543607,
      "median": 0.014080785000000002,
      "user": 0.008622491544715448,
      "system": 0.006826440813008128,
      "min": 0.0099641735,
      "max": 0.025781296500000002
    }
  ]
}

Scenario: Isolated linker: repeat install, cold cache + hot store

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 14.5 ± 6.0 7.9 44.6 1.24 ± 0.59
pacquet@main 13.3 ± 2.9 7.9 21.6 1.14 ± 0.35
pnpr@HEAD 11.6 ± 2.6 7.5 18.9 1.00
pnpr@main 13.6 ± 3.0 8.7 21.4 1.17 ± 0.37
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.014451420683870968,
      "stddev": 0.006032261470163156,
      "median": 0.0125921238,
      "user": 0.007266491225806449,
      "system": 0.008009307612903227,
      "min": 0.007900666800000001,
      "max": 0.0446466058
    },
    {
      "command": "pacquet@main",
      "mean": 0.013271761204040403,
      "stddev": 0.002851548504837084,
      "median": 0.0129477858,
      "user": 0.007107814343434343,
      "system": 0.0069638154545454585,
      "min": 0.0078840618,
      "max": 0.021624252800000004
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.011608462866115709,
      "stddev": 0.0025715783871800182,
      "median": 0.0111507933,
      "user": 0.00647469818181818,
      "system": 0.005854533553719007,
      "min": 0.007526486800000001,
      "max": 0.018862212800000003
    },
    {
      "command": "pnpr@main",
      "mean": 0.013590701067857147,
      "stddev": 0.0030204091974647008,
      "median": 0.0129934143,
      "user": 0.006238490833333334,
      "system": 0.008119173928571427,
      "min": 0.008708306800000001,
      "max": 0.021415131800000004
    }
  ]
}

Scenario: Isolated linker: fresh install, cold cache + cold store

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 2.915 ± 0.063 2.834 3.071 1.76 ± 0.16
pacquet@main 2.823 ± 0.066 2.730 2.938 1.70 ± 0.15
pnpr@HEAD 1.659 ± 0.134 1.497 1.862 1.00 ± 0.12
pnpr@main 1.656 ± 0.141 1.506 1.880 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.91536748362,
      "stddev": 0.0634567133315992,
      "median": 2.90188094262,
      "user": 2.9883244199999996,
      "system": 2.5315403400000003,
      "min": 2.8341873986199997,
      "max": 3.07072788462
    },
    {
      "command": "pacquet@main",
      "mean": 2.8227673862200002,
      "stddev": 0.06561181468277177,
      "median": 2.81727521812,
      "user": 2.7454780199999997,
      "system": 2.3645273399999995,
      "min": 2.72950536362,
      "max": 2.93813877562
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.6587777560199999,
      "stddev": 0.13444165786247536,
      "median": 1.65262601412,
      "user": 1.6699401200000001,
      "system": 1.8268740400000003,
      "min": 1.4969868176199999,
      "max": 1.86203774562
    },
    {
      "command": "pnpr@main",
      "mean": 1.6557621064199999,
      "stddev": 0.14125117951236837,
      "median": 1.59744914562,
      "user": 1.6042955200000002,
      "system": 1.8158718400000002,
      "min": 1.5064917756199998,
      "max": 1.87962187962
    }
  ]
}

Scenario: Isolated linker: fresh install, hot cache + hot store

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 595.4 ± 72.0 510.9 722.3 1.83 ± 0.25
pacquet@main 534.6 ± 60.6 450.2 636.6 1.64 ± 0.21
pnpr@HEAD 325.7 ± 20.4 288.3 364.6 1.00
pnpr@main 398.1 ± 59.5 338.7 483.3 1.22 ± 0.20
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.5954247477600001,
      "stddev": 0.07202718594480387,
      "median": 0.5796210794600001,
      "user": 0.86067932,
      "system": 0.8990924799999999,
      "min": 0.51091853046,
      "max": 0.7223324654600001
    },
    {
      "command": "pacquet@main",
      "mean": 0.5346023711599999,
      "stddev": 0.060570118919034695,
      "median": 0.54520194846,
      "user": 0.7652450199999998,
      "system": 0.8278118799999999,
      "min": 0.45016167946,
      "max": 0.63662340246
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.32571634575999997,
      "stddev": 0.02043985685793263,
      "median": 0.32591664146,
      "user": 0.26902061999999993,
      "system": 0.57623088,
      "min": 0.28825011146,
      "max": 0.36463906346
    },
    {
      "command": "pnpr@main",
      "mean": 0.3980547763600001,
      "stddev": 0.05952596419002698,
      "median": 0.38758759696,
      "user": 0.3375316199999999,
      "system": 0.69481068,
      "min": 0.33865897146,
      "max": 0.48330069546000004
    }
  ]
}

Scenario: Isolated linker: fresh install, cold cache + hot store

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 1.873 ± 0.135 1.710 2.052 6.01 ± 0.73
pacquet@main 1.720 ± 0.083 1.647 1.936 5.52 ± 0.60
pnpr@HEAD 0.312 ± 0.030 0.279 0.375 1.00
pnpr@main 0.408 ± 0.091 0.311 0.561 1.31 ± 0.32
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 1.8730010628200002,
      "stddev": 0.13476837270405334,
      "median": 1.85800014822,
      "user": 1.28274534,
      "system": 1.14149388,
      "min": 1.70988069472,
      "max": 2.0518344667200004
    },
    {
      "command": "pacquet@main",
      "mean": 1.71963461062,
      "stddev": 0.08300101278053909,
      "median": 1.69535266872,
      "user": 0.9959588399999999,
      "system": 0.88072948,
      "min": 1.6468859007199999,
      "max": 1.93624174072
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.31159915022000007,
      "stddev": 0.030299879197736825,
      "median": 0.29818986672000003,
      "user": 0.25708724,
      "system": 0.56076758,
      "min": 0.27877997472,
      "max": 0.37547915072
    },
    {
      "command": "pnpr@main",
      "mean": 0.40836061012,
      "stddev": 0.09082472201645768,
      "median": 0.37187098422,
      "user": 0.34586453999999994,
      "system": 0.7167085799999999,
      "min": 0.31103975372,
      "max": 0.5613650707200001
    }
  ]
}

Scenario: Isolated linker: fresh resolve, hot cache, offline

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 586.3 ± 113.9 487.3 804.8 4.72 ± 1.08
pacquet@main 511.3 ± 76.7 399.3 657.9 4.12 ± 0.79
pnpr@HEAD 136.9 ± 25.8 112.3 204.2 1.10 ± 0.25
pnpr@main 124.1 ± 14.8 106.1 157.6 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.58632001308,
      "stddev": 0.11393421886183426,
      "median": 0.53625888198,
      "user": 0.5865399,
      "system": 0.1929699,
      "min": 0.48734948448000004,
      "max": 0.8047813744800001
    },
    {
      "command": "pacquet@main",
      "mean": 0.51133538568,
      "stddev": 0.07670066055317296,
      "median": 0.49623074948,
      "user": 0.5305978,
      "system": 0.16627139999999999,
      "min": 0.39932800248,
      "max": 0.65794333248
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.13686566248000004,
      "stddev": 0.025754237555137248,
      "median": 0.12721682648000002,
      "user": 0.06989465714285714,
      "system": 0.026379342857142857,
      "min": 0.11230271048,
      "max": 0.20419444548000001
    },
    {
      "command": "pnpr@main",
      "mean": 0.12410005326260871,
      "stddev": 0.014844700683603215,
      "median": 0.12231769448,
      "user": 0.0569603652173913,
      "system": 0.026108678260869562,
      "min": 0.10605134848,
      "max": 0.15763225148
    }
  ]
}

Scenario: Isolated linker: peer-heavy resolve, hot cache, offline

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 895.2 ± 95.5 770.9 1070.1 1.00
pacquet@main 999.4 ± 202.9 623.9 1247.7 1.12 ± 0.26
pnpm@HEAD 4127.6 ± 443.0 3782.5 5053.9 4.61 ± 0.70
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.8951649573422222,
      "stddev": 0.09547869745027374,
      "median": 0.8856992621200002,
      "user": 0.937677671111111,
      "system": 0.20877238000000004,
      "min": 0.7708909531200001,
      "max": 1.0701467331199999
    },
    {
      "command": "pacquet@main",
      "mean": 0.9993604107866667,
      "stddev": 0.2028603820987724,
      "median": 1.05451803312,
      "user": 1.0448760044444443,
      "system": 0.22861826888888886,
      "min": 0.6239138921200001,
      "max": 1.24769794112
    },
    {
      "command": "pnpm@HEAD",
      "mean": 4.127619569231111,
      "stddev": 0.44296472604256987,
      "median": 3.89128135812,
      "user": 6.366152448888889,
      "system": 0.3269441577777778,
      "min": 3.78245952512,
      "max": 5.05389635012
    }
  ]
}

Scenario: Isolated linker: linked-workspace resolve, hot cache, offline

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 189.4 ± 10.2 175.9 214.4 1.00
pacquet@main 197.4 ± 5.3 187.7 204.1 1.04 ± 0.06
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.18937733378000002,
      "stddev": 0.010238451946990891,
      "median": 0.18776427398,
      "user": 0.14926302666666666,
      "system": 0.08408313333333334,
      "min": 0.17589841298,
      "max": 0.21436625298
    },
    {
      "command": "pacquet@main",
      "mean": 0.19739021358,
      "stddev": 0.00532046676444642,
      "median": 0.19715036798,
      "user": 0.15006062666666667,
      "system": 0.09760106666666668,
      "min": 0.18769597798,
      "max": 0.20407742198
    }
  ]
}

Scenario: Isolated linker: fresh restore, cold cache + cold store + cold pnpr

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 4.897 ± 0.425 4.554 6.020 1.38 ± 0.12
pacquet@main 4.554 ± 0.089 4.450 4.688 1.29 ± 0.04
pnpr@HEAD 3.536 ± 0.087 3.407 3.693 1.00
pnpr@main 3.609 ± 0.167 3.390 3.846 1.02 ± 0.05
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 4.8966752385,
      "stddev": 0.4252330245607307,
      "median": 4.7473558553999995,
      "user": 2.41676368,
      "system": 1.95713844,
      "min": 4.5542238394,
      "max": 6.0202529324
    },
    {
      "command": "pacquet@main",
      "mean": 4.5541917738999995,
      "stddev": 0.08931943631532609,
      "median": 4.5250292994,
      "user": 2.0609455799999994,
      "system": 1.7408729400000003,
      "min": 4.4500886844,
      "max": 4.6880671774
    },
    {
      "command": "pnpr@HEAD",
      "mean": 3.5360893763999997,
      "stddev": 0.08698743456398483,
      "median": 3.5236616419000004,
      "user": 1.61547888,
      "system": 1.57241834,
      "min": 3.4070703414000003,
      "max": 3.6927770594
    },
    {
      "command": "pnpr@main",
      "mean": 3.6092724159,
      "stddev": 0.16738536870187545,
      "median": 3.6159232639,
      "user": 1.60462688,
      "system": 1.57493004,
      "min": 3.3902495784,
      "max": 3.8456817694
    }
  ]
}

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 184.5 ± 21.4 155.5 225.0 1.00
pacquet@main 225.4 ± 59.5 163.1 367.3 1.22 ± 0.35
pnpr@HEAD 228.8 ± 43.1 153.0 306.7 1.24 ± 0.27
pnpr@main 248.2 ± 42.7 202.1 330.9 1.35 ± 0.28
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.18450978583142857,
      "stddev": 0.021405084503536682,
      "median": 0.17826817376000004,
      "user": 0.2250311857142857,
      "system": 0.16880804285714285,
      "min": 0.15551384226,
      "max": 0.22496389226000002
    },
    {
      "command": "pacquet@main",
      "mean": 0.22540570184333333,
      "stddev": 0.05947747209036149,
      "median": 0.20118075876000002,
      "user": 0.2705999,
      "system": 0.17465831666666665,
      "min": 0.16309360526000002,
      "max": 0.36726679126
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.22877498726,
      "stddev": 0.0430898446386717,
      "median": 0.23177945026000002,
      "user": 0.2562861692307693,
      "system": 0.19415597692307693,
      "min": 0.15296600926,
      "max": 0.30665958726
    },
    {
      "command": "pnpr@main",
      "mean": 0.24816822453272727,
      "stddev": 0.042708097679792195,
      "median": 0.24258266626000002,
      "user": 0.2993532181818182,
      "system": 0.16313735454545453,
      "min": 0.20213309126,
      "max": 0.33093002126
    }
  ]
}

@zkochan
zkochan marked this pull request as ready for review September 24, 2026 14:55
@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Hold back nested hoisted bins until dependency builds complete

🐞 Bug fix 🧪 Tests 🕐 40+ Minutes

Grey Divider

AI Description

• Prevent nested missing-target bin shims from entering lifecycle-script PATHs during hoisted
 installs.
• Track affected .bin directories and relink only them after dependency builds.
• Add pnpm 11 and Rust regression coverage using nested-version fixtures.
Diagram

sequenceDiagram
    participant HL as Hoisted Linker
    participant BL as Bin Linker
    participant HD as Held-back Dirs
    participant BP as Build Phase
    participant NB as Nested Bins
    HL->>BL: Link bins before builds
    BL-->>HL: Report missing targets
    HL->>HD: Record nested directories
    HL->>BP: Pass recorded directories
    BP->>BP: Run lifecycle builds
    BP->>NB: Relink recorded directories
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Relink every nested bin directory
  • ➕ Simpler state propagation between linking and build phases.
  • ➕ Avoids changing the bin-linker return contract.
  • ➖ Adds unnecessary filesystem work to every warm hoisted install.
  • ➖ Scales with the entire dependency tree rather than actual missing targets.
2. Defer all nested bins until after builds
  • ➕ Eliminates all pre-build missing-target shims without tracking affected directories.
  • ➕ Simplifies missing-target detection during initial linking.
  • ➖ Removes valid dependency commands from lifecycle-script PATHs.
  • ➖ Changes established installation behavior for bins whose targets already exist.

Recommendation: Use the PR's targeted tracking approach. It preserves existing pre-build PATH behavior for valid bins, avoids unnecessary warm-install work, and restores only directories proven to contain deferred targets; the additional cross-phase state is justified by those correctness and performance properties.

Files changed (20) +279 / -68

Bug fix (11) +152 / -58
link_bins.rsReport whether cached bin linking deferred a target +10/-4

Report whether cached bin linking deferred a target

• Changes the cached bin-linking API and implementation to return whether any selected bin was held back because its target was missing. Existing non-reporting callers continue receiving a unit result.

pnpm/crates/cmd-shim/src/link_bins.rs

build_phase.rsRelink held-back nested bins after lifecycle builds +19/-0

Relink held-back nested bins after lifecycle builds

• Extends build-phase inputs with recorded nested bin directories. Relinks their direct dependency bins after builds and before the existing importer-level bin pass.

pnpm/crates/deps-restorer/src/install_frozen_lockfile/build_phase.rs

hoisted.rsPropagate held-back directories from the hoisted linker +7/-4

Propagate held-back directories from the hoisted linker

• Captures the directories returned by hoisted module linking and exposes them through 'HoistedLinkerOutput' for later build-phase processing.

pnpm/crates/deps-restorer/src/install_frozen_lockfile/hoisted.rs

materialization.rsPass deferred nested bins into the frozen build phase +1/-0

Pass deferred nested bins into the frozen build phase

• Forwards held-back directories from link-phase output into frozen-lockfile build processing.

pnpm/crates/deps-restorer/src/install_frozen_lockfile/materialization.rs

direct.rsExpose missing-target holdback status for direct bins +18/-11

Expose missing-target holdback status for direct bins

• Changes internal direct-bin linking to return the cached linker's held-back status. Public callers that do not need reporting retain unit-returning behavior.

pnpm/crates/deps-restorer/src/link_bins/direct.rs

link_hoisted_modules.rsTrack nested hoisted directories with deferred bins +58/-29

Track nested hoisted directories with deferred bins

• Holds back missing-target bins at every hoisted tree level and aggregates affected nested directories across parallel traversal. Returns each directory with the dependency names required for post-build relinking while excluding project roots already covered by the existing pass.

pnpm/crates/deps-restorer/src/link_hoisted_modules.rs

linking.rsCarry held-back bin directories through link output +4/-0

Carry held-back bin directories through link output

• Adds held-back nested directories to 'LinkPhaseOutput', initializes them for isolated linking, and forwards hoisted-linker results.

pnpm/crates/deps-restorer/src/linking.rs

on_disk.rsPass deferred bins into fresh-install build processing +1/-0

Pass deferred bins into fresh-install build processing

• Supplies held-back directory data to the build phase on the fresh-lockfile installation path.

pnpm/crates/package-manager/src/install_with_fresh_lockfile/on_disk.rs

index.tsCollect directories where bin targets were held back +6/-0

Collect directories where bin targets were held back

• Adds an optional 'heldBackBinsDirs' collector and records the current '.bin' directory whenever missing-target filtering defers at least one command.

pnpm11/bins/linker/src/index.ts

index.tsRelink pnpm 11 nested bins after builds +11/-2

Relink pnpm 11 nested bins after builds

• Collects nested directories returned by hoisted linking and relinks them after dependency builds. Renames the option to reflect that missing bins are now held back at every hierarchy level.

pnpm11/installing/deps-restorer/src/index.ts

linkHoistedModules.tsHold back and report nested bins in pnpm 11 +17/-8

Hold back and report nested bins in pnpm 11

• Enables missing-target holdback throughout recursive hoisted linking and records affected nested '.bin' directories. Returns the deduplicated directory list for post-build relinking.

pnpm11/installing/deps-restorer/src/linkHoistedModules.ts

Refactor (1) +1 / -0
direct_links.rsAdapt direct links to the reporting bin-link API +1/-0

Adapt direct links to the reporting bin-link API

• Discards the new held-back status where direct-link processing only needs successful completion.

pnpm/crates/deps-restorer/src/install_frozen_lockfile/hoisted/direct_links.rs

Tests (5) +92 / -10
dependency_build_scripts.rsCover nested missing-bin lifecycle behavior in Rust CLI tests +36/-9

Cover nested missing-bin lifecycle behavior in Rust CLI tests

• Generalizes the fixture installer to select package versions and expected bin paths. Adds a hoisted-linker regression test proving both root and nested bins are absent before preinstall creates their targets and linked afterward.

pnpm/crates/cli/tests/suite/lifecycle_scripts/dependency_build_scripts.rs

behavior.rsTest held-back status reporting from the bin linker +29/-0

Test held-back status reporting from the bin linker

• Verifies that cached linking reports a held-back bin while its target is missing and reports none after the build output is created.

pnpm/crates/cmd-shim/src/link_bins/tests/behavior.rs

tests.rsInitialize held-back bin inputs in build-phase tests +1/-0

Initialize held-back bin inputs in build-phase tests

• Updates the existing build-phase test fixture to provide an empty held-back directory list.

pnpm/crates/deps-restorer/src/install_frozen_lockfile/build_phase/tests.rs

index.tsVerify pnpm 11 held-back directory collection +3/-1

Verify pnpm 11 held-back directory collection

• Extends the missing-target holdback test to assert that the affected '.bin' directory is reported to the caller.

pnpm11/bins/linker/test/index.ts

lifecycleScripts.tsAdd pnpm 11 nested hoisted-bin regression coverage +23/-0

Add pnpm 11 nested hoisted-bin regression coverage

• Adds an end-to-end hoisted install with conflicting package versions that force the lifecycle-built dependency to nest. Verifies no premature shim appears on PATH and both final bin locations exist.

pnpm11/pnpm/test/install/lifecycleScripts.ts

Other (3) +34 / -0
package.jsonAdd fixture forcing a nested lifecycle-built dependency +7/-0

Add fixture forcing a nested lifecycle-built dependency

• Defines a fixture package depending on version 1.0.0 of the bin-producing package so a root-level 2.0.0 dependency forces nested placement.

pnpr/.fixtures/packages/@pnpm.e2e/nests-own-bin-created-by-preinstall/1.0.0/package.json

create-bin.jsAdd lifecycle fixture detecting premature bin shims +17/-0

Add lifecycle fixture detecting premature bin shims

• Fails preinstall if any shim for its command is already present on PATH, then creates the declared bin target for post-build linking.

pnpr/.fixtures/packages/@pnpm.e2e/own-bin-created-by-preinstall/2.0.0/create-bin.js

package.jsonDefine versioned preinstall-created bin fixture +10/-0

Define versioned preinstall-created bin fixture

• Adds version 2.0.0 of the fixture package with a declared bin whose target is generated by its preinstall script.

pnpr/.fixtures/packages/@pnpm.e2e/own-bin-created-by-preinstall/2.0.0/package.json

@qodo-code-review

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

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. Builds still see missing bin shims ✓ Resolved 📘 Rule violation ⌂ Architecture
Description
link_hierarchy_bins sends only graph-derived dep_names through
link_direct_dep_bins_before_builds, while its separate bundled-dependency pass still uses ordinary
link_bins and cannot add that directory to the returned holdback record. When a bundled dependency
declares a bin whose target is absent until its parent builds, Rust writes the nested shim before
lifecycle scripts and never relinks it, whereas the TypeScript stack holds back the whole nested
directory.
Code

pnpm/crates/deps-restorer/src/link_hoisted_modules.rs[R328-329]

+    let held_back = !dep_names.is_empty()
+        && crate::link_direct_dep_bins_before_builds(&modules_dir, &dep_names, opts.link_options)
Relevance

●●● Strong

Accepted precedent confirms nested bin holdbacks must be recorded and relinked; bundled dependencies
are otherwise omitted.

PR-#15511

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The shared-stack alignment rules require equivalent behavior in pnpm v11 and v12. Rust records
holdbacks only from graph-derived dependency names and then links bundled dependencies through an
unrecorded ordinary pass, while pnpm v11 applies holdback to the complete nested directory and
relinks every recorded directory after builds.

Rule 713428: Keep pnpm v11 and v12 observable behavior aligned when fixing shared bugs
Rule 3102961: Keep pnpm v11 and v12 bug-fix code paths functionally aligned
pnpm/crates/deps-restorer/src/link_hoisted_modules.rs[328-347]
pnpm11/installing/deps-restorer/src/linkHoistedModules.ts[247-255]
pnpm11/installing/deps-restorer/src/index.ts[797-803]

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 Rust hoisted linker applies missing-target holdback only to graph-derived dependencies. Bundled dependencies use the ordinary bin-linking path, so their missing-target shims can remain visible during lifecycle builds and are not recorded for post-build relinking.

## Fix Focus Areas
- pnpm/crates/deps-restorer/src/link_hoisted_modules.rs[328-347]
- pnpm/crates/deps-restorer/src/link_hoisted_modules/tests.rs[207-284]

## Recommended Fix
Link bundled dependency bins through the build-pending cached path, include their directory in the returned holdback record when any target is missing, and add a regression test proving the shim is absent during the build and linked afterward.

ⓘ 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
✅ Cross-repo context — repo relationships
Review mode: ⚖️ Balanced: This behavioral installer change affects lifecycle PATH exposure and adds filesystem bin-scanning work, warranting a careful review for correctness and performance.

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

Previous reviews

Review updated until commit 7d73e2c ⚖️ Balanced

Results up to commit af6e852 🧠 Deep


🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)


Remediation recommended
1. Builds still see missing bin shims ✓ Resolved 📘 Rule violation ⌂ Architecture
Description
link_hierarchy_bins sends only graph-derived dep_names through
link_direct_dep_bins_before_builds, while its separate bundled-dependency pass still uses ordinary
link_bins and cannot add that directory to the returned holdback record. When a bundled dependency
declares a bin whose target is absent until its parent builds, Rust writes the nested shim before
lifecycle scripts and never relinks it, whereas the TypeScript stack holds back the whole nested
directory.
Code

pnpm/crates/deps-restorer/src/link_hoisted_modules.rs[R328-329]

+    let held_back = !dep_names.is_empty()
+        && crate::link_direct_dep_bins_before_builds(&modules_dir, &dep_names, opts.link_options)
Relevance

●●● Strong

Accepted precedent confirms nested bin holdbacks must be recorded and relinked; bundled dependencies
are otherwise omitted.

PR-#15511

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The shared-stack alignment rules require equivalent behavior in pnpm v11 and v12. Rust records
holdbacks only from graph-derived dependency names and then links bundled dependencies through an
unrecorded ordinary pass, while pnpm v11 applies holdback to the complete nested directory and
relinks every recorded directory after builds.

Rule 713428: Keep pnpm v11 and v12 observable behavior aligned when fixing shared bugs
Rule 3102961: Keep pnpm v11 and v12 bug-fix code paths functionally aligned
pnpm/crates/deps-restorer/src/link_hoisted_modules.rs[328-347]
pnpm11/installing/deps-restorer/src/linkHoistedModules.ts[247-255]
pnpm11/installing/deps-restorer/src/index.ts[797-803]

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 Rust hoisted linker applies missing-target holdback only to graph-derived dependencies. Bundled dependencies use the ordinary bin-linking path, so their missing-target shims can remain visible during lifecycle builds and are not recorded for post-build relinking.

## Fix Focus Areas
- pnpm/crates/deps-restorer/src/link_hoisted_modules.rs[328-347]
- pnpm/crates/deps-restorer/src/link_hoisted_modules/tests.rs[207-284]

## Recommended Fix
Link bundled dependency bins through the build-pending cached path, include their directory in the returned holdback record when any target is missing, and add a regression test proving the shim is absent during the build and linked afterward.

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


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.

The hoisted linker's bundled-dependency pass linked a bundling
package's `node_modules/.bin` with the ordinary linker, so a bundled
bin whose target was missing got its shim before builds and was never
recorded for the post-build relink. pnpm 11's hoisted pass scans the
whole directory, so it already held such bins back.

The bundled pass now marks its packages build pending, links them
through the reporting linker, and returns the directories that held a
bin back, with the bundled package names, for the build phase to link
again.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@zkochan

zkochan commented Sep 24, 2026

Copy link
Copy Markdown
Member Author

Qodo's finding Builds still see missing bin shims is valid. Fixed in 7d73e2c. The hoisted linker's bundled-dependency pass now works like the graph pass: it marks bundled packages build pending, links them through link_bins_of_packages_cached, and returns the bundling package's node_modules with the bundled package names when it held a bin back, so run_build_phase links them again. pnpm 11 already covered this, because its hoisted pass scans the whole directory. The new unit test bundled_bin_with_missing_target_is_held_back fails without the change. The existing bundled_bins_are_linked_under_the_hoisted_linker e2e still passes.


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

@qodo-code-review

Copy link
Copy Markdown

Qodo's finding Builds still see missing bin shims is valid. Fixed in 7d73e2c. The hoisted linker's bundled-dependency pass now works like the graph pass: it marks bundled packages build pending, links them through link_bins_of_packages_cached, and returns the bundling package's node_modules with the bundled package names when it held a bin back, so run_build_phase links them again. pnpm 11 already covered this, because its hoisted pass scans the whole directory. The new unit test bundled_bin_with_missing_target_is_held_back fails without the change. The existing bundled_bins_are_linked_under_the_hoisted_linker e2e still passes.


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

Thanks for the confirmation. Finding 1 appears addressed by 7d73e2c0d2: bundled dependencies now hold back missing-target bins and relink their .bin directory after builds, with coverage from bundled_bin_with_missing_target_is_held_back and the existing e2e test.

@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 7d73e2c

@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
@zkochan
zkochan merged commit 19fb59b into main Sep 24, 2026
65 checks passed
@zkochan
zkochan deleted the fix/hoisted-nested-bin-holdback branch September 24, 2026 15:25
u9g pushed a commit to u9g/pnpm that referenced this pull request Sep 25, 2026
…pnpm#15563)

Under nodeLinker: hoisted, a dependency nested in another package's
node_modules has that package's node_modules/.bin on PATH during its
lifecycle scripts. The hoisted linker links every nested .bin while it
imports the tree, before builds, and never again, so a nested
dependency whose preinstall creates its own bin found a shim of the
missing file on PATH. pnpm#15511 held such bins back only in a
project's .bin, which the post-build relink covers.

Both stacks now hold back missing-target bins in nested .bin
directories too, record the directories that held something back, and
link those again after the builds. A bin whose target is still missing
then gets its dependent shim, so the result matches the previous one,
minus the shim on PATH during the build. Only recorded directories are
relinked.

pnpm 11: linkBins reports such directories through a heldBackBinsDirs
option, linkHoistedModules returns them, and the headless install
relinks them after buildModules.

pnpm 12: link_bins_of_packages_cached returns whether it held a bin
back, link_hoisted_modules returns the directories, and they reach
run_build_phase through the link phase output.
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.

2 participants