Skip to content

Vendor patched npm packages in Rush monorepos - #2134

Merged
Mikola Lysenko (mikolalysenko) merged 4 commits into
mainfrom
feat/rush-vendored-mode
Nov 18, 2026
Merged

Mikola Lysenko (mikolalysenko) merged 4 commits into
mainfrom
feat/rush-vendored-mode

Conversation

@mikolalysenko

@mikolalysenko Mikola Lysenko (mikolalysenko) commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

What this does

scan --mode vendored and vendor now work in a Rush monorepo on pnpm 9 or newer (lockfileVersion 9.0), subspaces included. Until now every Rush repository was refused with vendor_rush_unsupported.

Why it was refused, and what actually blocks it

The refusal said a relative file: spec cannot survive Rush's copy of the lock into common/temp. It can: the spec only has to be relative to that folder.

The real blocker is Rush's own stale-lock check. rush install compares each project's package.json with its lock importer and looks overrides up by bare dependency name. The plain pnpm backend writes a name@version override, which rewrites the specifier of every project that depends on the package directly. rush update accepts that lock, and rush install then rejects it on every run ("Dependencies of project X do not match the current shrinkwrap").

How a Rush repo is wired

Rush is a layout of the pnpm v9 backend (vendor::pnpm_lock::rush, ledger flavor rush-pnpm). For each Rush pnpm lock that installs the package:

  • Lock. The same fragments as a plain pnpm project, with paths relative to the folder Rush installs that lock from (file:../../.socket/vendor/…, one level more in a subspace).
  • Transitive dependents. One parent-scoped entry each, "<parent>@<version>><name>@<version>", in pnpm-config.json's globalOverrides and in the overrides: of every lock that reads that config. Rush hands these to pnpm, so the patch survives rush update and rush update --full.
  • Direct dependents. The project's package.json spec moves to file:<path from the project>. This is the one edit that is specific to Rush, and only Rush repositories get it. The run names the files it edited (vendor_rush_package_json_edited).

A plain name@version key is never written. Besides tripping Rush's check, pnpm matches it against every dependent whose declared range merely includes the version, wherever that dependent is locked.

vendor --revert, remove, vex, vendor --check and takeover to and from hosted mode work on the result.

Refused before anything is written

  • A Rush repo that installs with npm or yarn, one with no pnpm lock yet, or installs without pnpm workspaces: vendor_rush_unsupported.
  • pnpm 8 and older locks: vendor_lockfile_version_unsupported.
  • A project package.json that no longer matches the lock: vendor_rush_project_manifest.
  • A project that lists the package under peerDependencies: vendor_rush_project_manifest. pnpm locks a workspace project's own peer dependency under dependencies, with or without a devDependencies spec beside it, so the project has no spec to move.
  • ensureConsistentVersions with direct dependents at different folder depths, whose file: specs differ, or with a preferredVersions entry for the package: vendor_rush_inconsistent_versions. Listing the specs under allowedAlternativeVersions lets the next run through.
  • Two subspaces that read one pnpm-config.json and resolve the same dependent to different releases of the package: vendor_rush_unsupported. The override one of them needs would move the other to the vendored release on its next rush update. Giving one subspace its own pnpm-config.json lets it through.
  • A pnpm-config.json with extends and no globalOverrides table of its own: vendor_rush_unsupported. Rush replaces the inherited table with one declared in the file, so a first table would drop every inherited override. Adding the table lets it through.

vendor --revert refuses (vendor_lock_still_wired_revert_blocked) while a Rush lock the vendoring never wrote, such as a subspace added since, still installs the tarball.

Warnings: a project the repo publishes is named in vendor_rush_package_json_edited (a published file: dependency cannot be installed by consumers); vendor_rush_repo_state_stale says rush update must refresh a hash in repo-state.json (the lock hash when preventManualShrinkwrapChanges is on, or the injected-dependencies hash when an edited project is behind an injected workspace dependency); vendor_pnpm_build_approval_lost names a build decision that stops matching the vendored id.

How it was tested

Against real Rush 5.182.1, with the built binary and the real minimist patches, on pnpm 9.15.9, 10.34.9, 11.28.12 and 12.21.0:

  • the lock is byte-identical to what rush update writes from the same config and manifests;
  • a fresh clone's rush install installs the patched files and vex attests them;
  • rush update --full changes nothing;
  • vendor --revert restores the baseline byte for byte.

The same holds for two subspaces (with their own config, and sharing one), two patched versions of one package, pre-existing user overrides, a sibling version that sorts after the patched one, and a re-run after a later rush update brought in new dependents.

In this PR's CI: the new suite e2e_vendor_rush drives real Rush on pnpm 10.34.9 and 11.28.12 (vendor, rush update must rewrite nothing, fresh-checkout rush install, vendor --check, rush update --full, revert). It is a Linux row of the e2e job on every pull request, and rides the hosted Rush rows on Windows and macOS.

Fixtures: the before/after files real Rush wrote are under crates/socket-patch-core/tests/fixtures/vendor/rush; 34 tests replay them and cover the refusals. The core library suite (7,943 tests), the CLI unit suite, the CI clippy command and fmt are clean.

Code review (/code-review high)

Fixed: a pnpm-config.json that several subspaces share (the override now reaches every lock that reads it); scoped package names in the override check; revert when a later rush update had resolved the registry entry again; revert with references pnpm added since; the hosted to vendored dry-run preview skipping Rush refusals; a duplicate JSON-with-comments reader.

Not fixed, and why:

  • Windows and macOS legs have not run. Under the lean CI scope those rows run nightly and on dispatch, not on pull requests. The first such run is the first time real Rush runs on Windows here.
  • Build decisions are not carried over. The plain pnpm backend adds the vendored id next to a build approval. In a Rush repo that means editing arrays and maps in pnpm-config.json, which this PR does not do; it warns and names the id instead.
  • The plan still runs up to three times per package (the download plan, the pre-flight, the wiring). The lock's split and rebase is memoized; carrying the plan from the pre-flight to the wiring needs the tarball's digest, which is only known after staging.
  • Paths are rebased by rewriting the lock's lines, not by passing an install base to the ownership parse. That keeps the plain backend's splices, reverters and discovery untouched; the round trip is checked on every read and refuses a line it cannot rebase.

Second review (Cursor Bugbot, Codex, a Claude sub-agent)

All three read the PR at ee2917433; f5f48b59b has the fixes. Each finding was checked against Rush 5.182.1's source or a real Rush repository before it was fixed.

Fixed:

  • Cleanup did not read Rush's wiring files (found by all three). repair's orphan sweep and the ledger-missing gates scanned root lockfiles only, so a repository that lost state.json could lose a tarball rush install still needs. They now read the Rush locks, the pnpm-config.json files and the project manifests. Checked on a real repo: with the ledger deleted, vendor --check and repair report vendor_ledger_missing and the tarball stays.
  • A shared override could move another subspace's dependent (Codex, Claude). Reproduced with real Rush: two subspaces share a config, optimist@0.6.1 resolves minimist 0.0.8 in one and 0.0.10 in the other; with the override for 0.0.8 in the config, rush update moved the second to the vendored 0.0.8. Now refused.
  • extends in pnpm-config.json (Codex, Claude): refused unless the file has its own globalOverrides table.
  • Revert deleting a tarball an unrecorded lock installs (Codex): refused.
  • A quoted lock specifier ('*') read as a stale manifest (Claude).
  • preferredVersions and the subspace's own common-versions.json in the consistency check (Codex, Claude).
  • The injected-dependencies hash in repo-state.json (Claude): a warning.
  • The CLI's next steps named no install command and no config or manifest to commit (Claude): rush install, and the three kinds of file.
  • A leftover lock at another folder depth got an override path it cannot use (Claude): left alone.
  • A panic on a snapshot key with a multi-byte first character (Claude).

Dismissed: Bugbot's second finding said a peer dependency leaves a dangling lock importer entry. It does not: real Rush locks a project's own peer dependency under dependencies, and vendoring refuses before any write. The refusal's remedy ("run rush update") was wrong for that case, and now names the reason.

Not fixed, and why:

  • A project's own peer dependency is refused, not wired. With a file: spec under devDependencies, Rush moves the lock importer entry from dependencies to devDependencies. Wiring that needs a move between importer sections and a byte-exact way back. A follow-up.
  • A globalOverrides table written on one line ({}) comes back on two lines after a revert, and one created flag covers every config an entry edits. Both leave valid, equivalent JSON.
  • An unrecorded lock that only mirrors the overrides keeps them after a revert. Rush then asks for rush update, which removes them.
  • Each vendored package re-reads and re-scans every lock, and the Rush module has its own block scanners beside the plain backend's. Neither changes behaviour; both are worth a later pass.

Not in this PR

  • The plain pnpm backend still writes name@version overrides. With two vendored versions of one package and a dependent whose range includes both, the lock it writes fails pnpm install --frozen-lockfile. That is a separate fix.
  • The ensureConsistentVersions case could be made to work by writing allowedAlternativeVersions; it is refused for now.

🤖 Generated with Claude Code

`scan --mode vendored` and `vendor` refused every Rush repository
(`vendor_rush_unsupported`), saying a relative `file:` spec cannot survive
Rush's copy of the lock into `common/temp`. It can: the spec only has to be
relative to that folder. What actually stops the plain pnpm shape is Rush's
own stale-lock check. `rush install` compares each project's package.json
with its lock importer and looks overrides up by bare dependency name, so a
versioned override that rewrites a direct dependency's `specifier` makes
`rush install` fail on every run, right after `rush update` wrote that lock.

Rush is now a layout of the pnpm v9 backend (`vendor::pnpm_lock::rush`,
ledger flavor `rush-pnpm`). For each Rush pnpm lock that installs the
package (the common one and every subspace's):

- the lock gets the same fragments as a plain pnpm project. Its lines are
  edited as pnpm would spell them from the repository root and written back
  relative to Rush's temp folder, so the plain backend's splices and record
  reverters run unchanged. A rekeyed entry is moved to where pnpm's sorted
  serializer keeps it.
- transitive dependents get one parent-scoped override each
  (`<parent>@<version>><name>@<version>`) in `pnpm-config.json`'s
  `globalOverrides` (JSON with comments, edited as a span) and in the
  lock's `overrides:`. A plain `name@version` key is never written: pnpm
  matches it against every dependent whose declared range includes the
  version, and it rewrites project importers.
- a project that depends on the package directly gets its package.json
  spec moved to `file:<path from the project>`, announced as
  `vendor_rush_package_json_edited`. Only Rush repositories get this edit.

Refused before any write: a repository that installs with npm or yarn,
no pnpm lock yet, installs without pnpm workspaces
(`vendor_rush_unsupported`), pre-9.0 locks, a project manifest the lock
does not match (`vendor_rush_project_manifest`), and specs that
`ensureConsistentVersions` would reject
(`vendor_rush_inconsistent_versions`).

Only the vendor router yields the new flavor; the lock probe still finds
no root lock in a Rush repository, which the lock inventory relies on. Vex
discovery rebases a Rush lock's vendored paths before it parses them, and
the ledger's wiring validation knows the Rush record kinds.

The fixtures under tests/fixtures/vendor/rush are the files real Rush
5.182.1 wrote: each `after` lock is byte-identical to what `rush update`
resolves from the `after` config and manifests (pnpm 10.34.9 and 11.28.12).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
`e2e_vendor_rush` drives the real `@microsoft/rush` 5.182.1 (fetched with
`npm x`), which downloads and runs the pnpm that rush.json pins, over a
three-project repository: two projects depend on minimist@0.0.8 directly,
at folder depth 1 and 2, and a third reaches it through mkdirp@0.5.1.

Each leg (pnpm 10.34.9 and 11.28.12) vendors the package, then checks:

- `rush update` rewrites none of the wired files: Rush resolves the same
  lock from the config and manifests vendoring wrote;
- a fresh checkout's `rush install` passes Rush's stale-lock check, lands
  the patched bytes for both direct dependents and for mkdirp's copy, and
  leaves the lock as committed;
- `vendor --check` verifies the commit, and `rush update --full` keeps it;
- `vendor --revert` restores every file byte for byte, and `rush install`
  lands the registry bytes again.

The suite runs on every pull request as a Linux row of the `e2e` job, and
beside the hosted Rush suite in the Windows and macOS rows. pnpm 11 needs
Node >= 22.13, so the rows that run it get the Node 24 the named pnpm legs
use.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
- A config several subspaces share. Rush and pnpm compare a lock's
  `overrides:` with the configured ones, so every lock that reads a
  `pnpm-config.json` now carries the overrides vendoring adds to it,
  whether or not it installs the package. Before, a subspace without a
  matching dependent was left out and `rush install` would have rejected
  its lock. Verified against real Rush (two subspaces on the shared
  config); the new `subspaces-shared-config` fixture is its output.
- Scoped packages. `is_own_override` cut a scoped tarball's leaf at the
  scope and never recognised this layout's own override, so any re-run
  was refused with `vendor_override_conflict`.
- Revert with the registry entry back. After a later `rush update`
  resolved the registry entry again beside the vendored one, the restore
  left two blocks under one key, which pnpm cannot parse. The duplicate
  goes now.
- Revert with references pnpm added since. A new peer variant of a
  dependent the override covers got a vendored ref no record names; the
  revert refused on it, and the suggested remedy brought it back. Such
  refs follow the entry back to the registry release.
- The hosted to vendored dry-run preview skipped a Rush repository's
  refusals (it looked for a root pnpm-lock.yaml and the plain pnpm
  flavor).
- A build decision in `pnpm-config.json` that names the registry package
  stops matching the vendored id. It is not carried over; the run now
  says so (`vendor_pnpm_build_approval_lost`). A config dependency's own
  copy is named as in the plain backend.
- `jsonc::to_value` duplicated `formats::package_json::parse`: removed.
- Each Rush lock's split and rebase is memoized by its bytes, and
  `resort_block` no longer allocates a spelling per block key.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review November 18, 2026 19:09
@cursor

cursor Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes committed lockfiles, override semantics, and install-time paths in monorepos; risk is mitigated by extensive Rush/pnpm fixtures and real-Rush e2e legs, but incorrect wiring could break rush install or leave unpatched packages.

Overview
Rush monorepos can now use vendor / scan --mode vendored instead of always failing with vendor_rush_unsupported. The vendor router recognizes a new rush-pnpm npm flavor and routes through pnpm_lock::rush, wiring Rush’s common/subspace pnpm-lock.yaml files, pnpm-config.json globalOverrides, and direct-dependent package.json specs so rush install and stale-shrinkwrap checks stay satisfied.

Wiring uses paths relative to each lock’s install folder (common/temp, deeper for subspaces), parent-scoped overrides (parent@ver>pkg@ver) in every lock that shares a config, and a dedicated JSON-with-comments editor (jsonc) so Rush config edits preserve comments and formatting. VEX discovery rebases Rush lock file: paths accordingly and rejects root-relative vendored paths that would resolve under common/temp.

CI adds the e2e_vendor_rush matrix leg (Linux PR, Windows/macOS with Rush sim) with Node 24 where needed. Contract/docs document the rush-pnpm matrix row and new vendor_rush_* refusal/warning codes. Coverage includes fixture repos under tests/fixtures/vendor/rush and a real @microsoft/rush e2e capstone (pnpm 10/11).

Reviewed by Cursor Bugbot for commit ee29174. Configure here.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit ee29174. Configure here.

Cursor Bugbot, Codex and a Claude sub-agent reviewed the PR. Confirmed
findings, each checked against Rush 5.182.1's source or a real Rush
repository:

- The orphan sweep and the ledger-missing gate did not read Rush's wiring
  files, so a repository that lost state.json could lose a tarball that
  `rush install` still needs. `vendor::rush_wiring_files` lists the Rush
  locks, the pnpm-config.json files and the project manifests, and the
  CLI scan reads them.
- Two subspaces that read one pnpm-config.json and resolve the same
  dependent to different releases: the override one needs moved the
  other to the vendored release on its next `rush update` (reproduced:
  0.0.10 became the vendored 0.0.8). Refused before any write.
- A pnpm-config.json with `extends` and no `globalOverrides` of its own:
  Rush replaces the inherited table, so a first table dropped every
  inherited override. Refused; a table the file already has is used.
- `vendor --revert` deleted a tarball that a lock added since the
  vendoring (and so not recorded) still installed. Refused with
  `vendor_lock_still_wired_revert_blocked`.
- A specifier the lock quotes (`'*'`) was compared with the quotes on,
  and refused as a stale manifest.
- `preferredVersions` counts in Rush's consistency check, and Rush reads
  common-versions.json from the subspace's own folder only.
- `repo-state.json`'s `packageJsonInjectedDependenciesHash` goes stale
  when a hashed manifest field is edited: now a warning.
- The CLI named no install command and no config or manifest to commit
  for a Rush run.
- A leftover lock at another folder depth that only mirrors the config's
  overrides is left alone instead of getting a path it cannot use.
- A snapshot key with a multi-byte first character panicked.

A project's own peer dependency is still refused, now with the reason:
pnpm locks it under `dependencies`, with or without a devDependencies
spec beside it, and Rush moves the entry once the spec is a `file:` one.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Merged via the queue into main with commit 911bf16 Nov 18, 2026
55 checks passed
@mikolalysenko
Mikola Lysenko (mikolalysenko) deleted the feat/rush-vendored-mode branch November 18, 2026 20:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants