Repository navigation
Vendor patched npm packages in Rush monorepos - #2134
Conversation
`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>
PR SummaryMedium Risk Overview Wiring uses paths relative to each lock’s install folder ( CI adds the Reviewed by Cursor Bugbot for commit ee29174. Configure here. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.
❌ 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>

What this does
scan --mode vendoredandvendornow work in a Rush monorepo on pnpm 9 or newer (lockfileVersion 9.0), subspaces included. Until now every Rush repository was refused withvendor_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 intocommon/temp. It can: the spec only has to be relative to that folder.The real blocker is Rush's own stale-lock check.
rush installcompares each project'spackage.jsonwith its lock importer and looks overrides up by bare dependency name. The plain pnpm backend writes aname@versionoverride, which rewrites thespecifierof every project that depends on the package directly.rush updateaccepts that lock, andrush installthen 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 flavorrush-pnpm). For each Rush pnpm lock that installs the package:file:../../.socket/vendor/…, one level more in a subspace)."<parent>@<version>><name>@<version>", inpnpm-config.json'sglobalOverridesand in theoverrides:of every lock that reads that config. Rush hands these to pnpm, so the patch survivesrush updateandrush update --full.package.jsonspec moves tofile:<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@versionkey 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 --checkand takeover to and from hosted mode work on the result.Refused before anything is written
vendor_rush_unsupported.vendor_lockfile_version_unsupported.package.jsonthat no longer matches the lock:vendor_rush_project_manifest.peerDependencies:vendor_rush_project_manifest. pnpm locks a workspace project's own peer dependency underdependencies, with or without adevDependenciesspec beside it, so the project has no spec to move.ensureConsistentVersionswith direct dependents at different folder depths, whosefile:specs differ, or with apreferredVersionsentry for the package:vendor_rush_inconsistent_versions. Listing the specs underallowedAlternativeVersionslets the next run through.pnpm-config.jsonand 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 nextrush update. Giving one subspace its ownpnpm-config.jsonlets it through.pnpm-config.jsonwithextendsand noglobalOverridestable 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 --revertrefuses (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 publishedfile:dependency cannot be installed by consumers);vendor_rush_repo_state_stalesaysrush updatemust refresh a hash inrepo-state.json(the lock hash whenpreventManualShrinkwrapChangesis on, or the injected-dependencies hash when an edited project is behind an injected workspace dependency);vendor_pnpm_build_approval_lostnames 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:
rush updatewrites from the same config and manifests;rush installinstalls the patched files andvexattests them;rush update --fullchanges nothing;vendor --revertrestores 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 updatebrought in new dependents.In this PR's CI: the new suite
e2e_vendor_rushdrives real Rush on pnpm 10.34.9 and 11.28.12 (vendor,rush updatemust rewrite nothing, fresh-checkoutrush install,vendor --check,rush update --full, revert). It is a Linux row of thee2ejob 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.jsonthat several subspaces share (the override now reaches every lock that reads it); scoped package names in the override check; revert when a laterrush updatehad 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:
pnpm-config.json, which this PR does not do; it warns and names the id instead.Second review (Cursor Bugbot, Codex, a Claude sub-agent)
All three read the PR at
ee2917433;f5f48b59bhas the fixes. Each finding was checked against Rush 5.182.1's source or a real Rush repository before it was fixed.Fixed:
repair's orphan sweep and the ledger-missing gates scanned root lockfiles only, so a repository that loststate.jsoncould lose a tarballrush installstill needs. They now read the Rush locks, thepnpm-config.jsonfiles and the project manifests. Checked on a real repo: with the ledger deleted,vendor --checkandrepairreportvendor_ledger_missingand the tarball stays.optimist@0.6.1resolves minimist 0.0.8 in one and 0.0.10 in the other; with the override for 0.0.8 in the config,rush updatemoved the second to the vendored 0.0.8. Now refused.extendsinpnpm-config.json(Codex, Claude): refused unless the file has its ownglobalOverridestable.'*') read as a stale manifest (Claude).preferredVersionsand the subspace's owncommon-versions.jsonin the consistency check (Codex, Claude).repo-state.json(Claude): a warning.rush install, and the three kinds of file.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 ("runrush update") was wrong for that case, and now names the reason.Not fixed, and why:
file:spec underdevDependencies, Rush moves the lock importer entry fromdependenciestodevDependencies. Wiring that needs a move between importer sections and a byte-exact way back. A follow-up.globalOverridestable written on one line ({}) comes back on two lines after a revert, and onecreatedflag covers every config an entry edits. Both leave valid, equivalent JSON.rush update, which removes them.Not in this PR
name@versionoverrides. With two vendored versions of one package and a dependent whose range includes both, the lock it writes failspnpm install --frozen-lockfile. That is a separate fix.ensureConsistentVersionscase could be made to work by writingallowedAlternativeVersions; it is refused for now.🤖 Generated with Claude Code