Skip to content

Commit d11dbb5

Browse files
mikolalysenkoclaude
andcommitted
Say what the offline commands and the in-memory engine do not see
Two limits of the pnpm registry route in a Bazel workspace were true of the code and missing from the docs. repair, scan --prune without a mode, rollback and remove read no Bazel file. Under a hub whose data lists a pnpm-workspace.yaml that a routed scan created, they still delete that file with the last of the route, and the build is then handed a missing file. The docs now say so where those commands are described, with the way round it. The route is taken "only where it is certain that no hub reads the lock". In memory that is certain of the files the engine was handed, and a Bazel root above the project is not among them, for the route as for the pin. The docs and the module docs say that beside the claim. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
1 parent eab6067 commit d11dbb5

3 files changed

Lines changed: 22 additions & 8 deletions

File tree

‎crates/socket-patch-cli/CLI_CONTRACT.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ The declaration is what pnpm verifies the lock entries against; the override is
335335

336336
The route is taken only when **all** of these hold; otherwise the run takes the `trustLockfile` path below with the locks in the plain shape (a lock half routed would fail to install): (1) the project's own root file is the one pnpm reads (not a workspace member whose settings live in an ancestor file, #880), every governing lock is lockfileVersion 9 (Rush and legacy locks keep their own guidance); (2) every Socket-hosted tarball the governing locks record after the run has a registry: this run was granted it **with** a registry address, or an earlier run routed it, this run was **not** granted it, and the files still route it (the lock keys the release by a registry of the CLI's, the workspace file has its override to that registry, and the registry's address is the directory the tarball is served from). So a run granted only part of the project's patches (a scan of one subtree of a monorepo with one root lock, a search that lists fewer patches than the lock pins) leaves the rest routed and rewrites nothing for them. A pin this run was granted **without** an address is never kept that way (the grant overrules the files), and neither is an ungranted pin the files do not route: either one puts the whole lock on `trustLockfile` and is named. A pin on a patch mirror (`--patch-mirror-url`, experimental) has no address either, whatever its grant carries: see "Patch mirror (experimental)". A tarball is Socket-hosted when this run pinned it or its URL has the patch server's path shape, and every other tarball is the user's own; (3) every pnpm pin of the project (the sources of the #734 rule below, at least one present) proves pnpm 11.20 or newer: the lowest version it admits is 11.20 or higher (`11.28.13`, `^11.20.0`, `>=11.20`, `12`, `>=12`, `12 || 13`, `11.20.0 - 13.0.0`; `>` is read as `>=`, so `>11.19` proves nothing), since older releases write another lock for the same override; a range that reaches below it (`>=11`, `^11`), one the CLI cannot read, or pins that disagree prove nothing; (4) the workspace file can be read, is not a keyless file beside a lock that lists workspace members (#1096), and is a shape a line splice can extend (not a flow-style or indented root, several documents, a `namedRegistries` or `overrides` value on one line, a repeated key, an entry that is not a one-line `key: value`); (5) no override of the user's targets a patched package, by any selector (`<name>`, `<name>@<range>`, `<parent>><name>`): pnpm applies one override per dependency, so the CLI's would lose to it or displace it, and the user's is never overwritten. It is looked for in pnpm-workspace.yaml, the one place the gated pnpm releases read overrides from (`pnpm.overrides` and `resolutions` in package.json are not read by pnpm 11.20 and later, measured through 12.22.0); (6) each lock is one the rewrite was captured against: the release is not a `pnpm patch` copy or an npm alias, an importer that depends on it asks through a plain semver range that admits it (not a tag, `catalog:`, `workspace:`, `npm:` or a URL), no importer locks another version of the package through a range that admits the patched one, no package is installed both with and without the release as its peer (pnpm 11 and 12 lock that differently), the release is not installed as another package's optional peer (pnpm resolves that copy around an override, so it would stay unpatched), and every entry of the lock is one run of lines (a `deprecated:` message of several paragraphs, or one that keeps its trailing line breaks, is written with empty lines inside its entry; a message of several lines without one is a block the routed entry simply loses); (7) no package version is pinned to two patches (an override routes a package version to one registry, and a registry serves one patch); (8) `--no-trust-lockfile-config` is not set, or the file already holds the route exactly; (9) in a Bazel workspace, it is certain that no rules_js hub reads a governing lock. One reads it when an `npm.npm_translate_lock` call of aspect_rules_js names it in a plain string, or has a `pnpm_lock` that is not written out as one, whatever else the call says. And one may read it wherever the workspace was not read whole: a file that `MODULE.bazel` includes and that is missing or unreadable, a use of the extension that is not a plain call of a tag, a `WORKSPACE` file that cannot be read or that brings in rules_js (a `load` from `@aspect_rules_js`, a `load` of `npm_translate_lock` from anywhere, or a call of that rule under any name a `load` gives it). A `WORKSPACE` file that is about something else, an `http_archive` of another ruleset say, defines no hub of a pnpm lock and blocks nothing (see "In a Bazel workspace" below). The write respects `--dry-run` and is refused through a symlink.
337337

338-
**In a Bazel workspace.** The lock reader of rules_js takes a routed lock (measured on macOS: rules_js 3.6.0 on Bazel 9.3.2 builds one for a hub without `update_pnpm_lock`, and the built packages hold the patched bytes; rules_js 2.9.3 on Bazel 8.8.2 does too). What holds the route back is the pnpm a hub runs with `update_pnpm_lock`: it sees pnpm-workspace.yaml only where the call lists it, and may be older than pnpm 11.20 (rules_js picks a pnpm 10 where the workspace states none). Run as the hub runs it (`pnpm install --lockfile-only` beside the lock and `package.json`, without the workspace file), pnpm 11.28.13 and 12.22.0 reject a routed lock (`ERR_PNPM_MISSING_NAMED_REGISTRY`, measured). No Bazel leg builds a routed lock with `update_pnpm_lock` yet, so for now every lock that a hub reads is pinned as on a patch service that offers no registry, the files byte for byte, which is the pin the Bazel legs build, and the warning names the call ("… because a Bazel hub reads the pnpm lock (MODULE.bazel:7), and a lock that a hub reads is not routed yet …"; for a project below the Bazel root, "(MODULE.bazel:7, with paths from the root of the Bazel workspace)"); a project routed before the hub was there leaves the route whole on its next scan, the locks and the workspace file together. Under such a hub a hosted scan never deletes pnpm-workspace.yaml, whose label the hub's `data` may name: where the last of a route leaves a file that a routed run created, the file stays as its `packages` list (`packages:` and `- '.'`), and the entries go as elsewhere. Where the hub also hides pnpm-workspace.yaml from a pnpm 11 (`redirect_pnpm_bazel_workspace_hidden`), that answer comes first, while the files are read, and the root lock is not part of the run: nothing in it is pinned or routed, the members' own locks of a workspace with `sharedWorkspaceLockfile: false` are pinned on `trustLockfile`, and a route an earlier run set up is left exactly as it is, in the workspace file and in every lock, because the root lock records the same overrides and is not written. The workspace file is then byte for byte the one it was: the registries still verify the routed releases, so no `trustLockfile: true` is added for them (it would switch the verification off for every entry). Only a release this run pins in the plain shape beside them, in a member's lock, brings the key. A hosted scan takes no unused entry out there either, and what it does to the files does not turn on what it was granted: with a patch for a package of the lock, with none, and with nothing crawled, it leaves the lock and the workspace file as they are and reports `redirect_pnpm_bazel_workspace_hidden` (a run with no npm patch reports it only for a project that holds something of a route; any other project it leaves without a word, as before). The commands that settle a route from the lockfiles alone pin nothing and work as without Bazel: `repair`, `scan --prune` with no mode, `rollback` and `remove`. A pnpm-workspace.yaml that holds nothing but a route and that a hub lists is one of the files `redirect_pnpm_bazel_workspace_hidden` asks for a comment line in: the scan that leaves the route would otherwise leave a file that `rollback` removes.
338+
**In a Bazel workspace.** The lock reader of rules_js takes a routed lock (measured on macOS: rules_js 3.6.0 on Bazel 9.3.2 builds one for a hub without `update_pnpm_lock`, and the built packages hold the patched bytes; rules_js 2.9.3 on Bazel 8.8.2 does too). What holds the route back is the pnpm a hub runs with `update_pnpm_lock`: it sees pnpm-workspace.yaml only where the call lists it, and may be older than pnpm 11.20 (rules_js picks a pnpm 10 where the workspace states none). Run as the hub runs it (`pnpm install --lockfile-only` beside the lock and `package.json`, without the workspace file), pnpm 11.28.13 and 12.22.0 reject a routed lock (`ERR_PNPM_MISSING_NAMED_REGISTRY`, measured). No Bazel leg builds a routed lock with `update_pnpm_lock` yet, so for now every lock that a hub reads is pinned as on a patch service that offers no registry, the files byte for byte, which is the pin the Bazel legs build, and the warning names the call ("… because a Bazel hub reads the pnpm lock (MODULE.bazel:7), and a lock that a hub reads is not routed yet …"; for a project below the Bazel root, "(MODULE.bazel:7, with paths from the root of the Bazel workspace)"); a project routed before the hub was there leaves the route whole on its next scan, the locks and the workspace file together. Under such a hub a hosted scan never deletes pnpm-workspace.yaml, whose label the hub's `data` may name: where the last of a route leaves a file that a routed run created, the file stays as its `packages` list (`packages:` and `- '.'`), and the entries go as elsewhere. Where the hub also hides pnpm-workspace.yaml from a pnpm 11 (`redirect_pnpm_bazel_workspace_hidden`), that answer comes first, while the files are read, and the root lock is not part of the run: nothing in it is pinned or routed, the members' own locks of a workspace with `sharedWorkspaceLockfile: false` are pinned on `trustLockfile`, and a route an earlier run set up is left exactly as it is, in the workspace file and in every lock, because the root lock records the same overrides and is not written. The workspace file is then byte for byte the one it was: the registries still verify the routed releases, so no `trustLockfile: true` is added for them (it would switch the verification off for every entry). Only a release this run pins in the plain shape beside them, in a member's lock, brings the key. A hosted scan takes no unused entry out there either, and what it does to the files does not turn on what it was granted: with a patch for a package of the lock, with none, and with nothing crawled, it leaves the lock and the workspace file as they are and reports `redirect_pnpm_bazel_workspace_hidden` (a run with no npm patch reports it only for a project that holds something of a route; any other project it leaves without a word, as before). The commands that settle a route from the lockfiles alone pin nothing and work as without Bazel: `repair`, `scan --prune` with no mode, `rollback` and `remove`. **They read no Bazel file**, on this route as for every other hosted pin. So under a hub whose `data` lists a pnpm-workspace.yaml that a routed run created, they still delete that file with the last of the route (as `rollback` deletes a `trustLockfile` file hosted mode created), and the build is then handed a missing file. A hosted scan says so before it comes to that (`redirect_pnpm_bazel_workspace_hidden` asks for a comment line in such a file) and never deletes the file itself. **In memory**, "certain" is certain of the files the engine was handed: the Bazel files at the project's own root (`MODULE.bazel`, the `*.MODULE.bazel` files it can include and the `WORKSPACE` files, beside a `pnpm-lock.yaml` or a `pnpm-workspace.yaml`). A Bazel root above the project is not seen there, for the route as for the pin, so a project in a directory of a Bazel workspace is routed in memory where a checkout is not. A pnpm-workspace.yaml that holds nothing but a route and that a hub lists is one of the files `redirect_pnpm_bazel_workspace_hidden` asks for a comment line in: the scan that leaves the route would otherwise leave a file that `rollback` removes.
339339

340340
**What the warning says.** A patch service that gives no pin of the project a registry address offers no route, and the run and its warning are exactly what they were. As soon as one pin has an address, a run that still ends on `trustLockfile` says why, in one sentence of the `redirect_pnpm_trust_lockfile` warning ("Per-package registry verification was not set up because …"): the hosted packages the patch service gave no address for, by `name@version` (the first five, then "and N more"), since one of them puts the whole lock on `trustLockfile`; the hosted packages pinned on a patch mirror, named the same way; pins that do not prove pnpm 11.20; a Bazel hub that reads the lock (9), by the file and line of its call, or what of the Bazel workspace was not read so that one may ("… because a Bazel hub may read the pnpm lock (WORKSPACE:3: it brings in rules_js, and a hub that this file defines is not read) …"); and whichever of (4) to (7) applied, naming the file, the override or the lock entry. With no pnpm pin at all (and not under `--no-trust-lockfile-config`) the sentence is instead that pinning pnpm 11.20 or later (for example with package.json `packageManager`) and re-running the scan switches the project to per-package registry verification. On the route the warning's detail says the file declares the patch server's registry of each patched package (the `socket-<id>` entries, one per patch) and routes each patched release to its own, to commit it alongside the lock, and keeps the rebuild-the-lockfile and clean-reinstall cautions; it carries no whole-lock tradeoff note. **A newer release in range (a note, never a refusal).** An override keyed `<name>@<version>` applies to every dependency whose range admits that version, and a lock records what a transitive dependent resolved, not the range it asked through. So when a governing lock also holds a newer release of a routed package within the routed release's caret range (the same major, or the same minor below 1.0), on the default registry, the detail ends with a note that names the package and both versions: "pnpm-lock.yaml also locks `<name>` at `<other>`, which a range that admits `<version>` may admit too: a package that depends on `<name>` through such a range moves to the patched `<name>@<version>` the next time pnpm resolves (`pnpm add`, `update`, `dedupe`), …". The lock is written as it is (pnpm installs it frozen, and re-locks it unchanged, until a command resolves the project again: see the [pnpm compatibility notes](../../docs/testing/pnpm-compatibility.md) for what each command does). The note is reported on every run that leaves the project routed, a re-run that changes nothing included (in human mode after the one-line reminder), and changes neither the route nor the exit code.
341341

‎crates/socket-patch-core/src/bazel/pnpm.rs‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,12 @@
5454
//! the pnpm 11 of the tag `pnpm` under the name `eleven`).
5555
//!
5656
//! In memory the workspace is the project's own files: path selection
57-
//! asks for the `MODULE.bazel` beside a `pnpm-lock.yaml`, for the files
58-
//! one can include and for the `WORKSPACE` files, and the answer is the
59-
//! one of a checkout with the same files. A Bazel root above the project
60-
//! is not seen there. A
57+
//! asks for the `MODULE.bazel` beside a `pnpm-lock.yaml` or a
58+
//! `pnpm-workspace.yaml`, for the files one can include and for the
59+
//! `WORKSPACE` files, and the answer is the one of a checkout with the
60+
//! same files. A Bazel root above the project is not seen there, for
61+
//! either answer of this module: a project in a directory of a Bazel
62+
//! workspace is pinned, and routed, in memory as if it were in none. A
6163
//! `pnpm_version_from` file that was not handed in (one outside the
6264
//! project's own manifests) and `MODULE.bazel.lock` are not there either:
6365
//! the first reads as a release that is not written out, so a lock that a
@@ -164,6 +166,11 @@ pub enum Reader {
164166
/// taking the route costs no patch: the project gets the pin it gets
165167
/// today. So the route is taken only where it is certain that no hub
166168
/// reads a lock.
169+
///
170+
/// Certain of the files that were read, that is. On disk those are the
171+
/// files of the Bazel workspace the project is in. In memory they are
172+
/// the project's own, so a hub in a Bazel root above the project is
173+
/// seen by neither answer there (the module docs).
167174
Unseen(String),
168175
}
169176

‎docs/ecosystems.md‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2401,6 +2401,11 @@ what hosted mode writes. That holds for every hosted scan, whatever it was grant
24012401
with a patch for a package of the lock, one with none and one that crawled nothing all
24022402
leave the files and give the same warning. `repair`, `scan --prune` with no mode,
24032403
`rollback` and `remove` settle a route from the lockfiles alone and work as without Bazel.
2404+
They read no Bazel file, for this route as for any other hosted pin: under a hub whose
2405+
`data` lists a `pnpm-workspace.yaml` that a routed scan created, they still delete that
2406+
file with the last of the route, and the build is then handed a missing file. Put a
2407+
comment line in the file first, as the warning of a hosted scan says; a hosted scan itself
2408+
never deletes the file under a hub that reads, or may read, the lock.
24042409

24052410
The file the hub lists has to be one that a pin and its undo leave standing, so hosted mode
24062411
also writes nothing for a hub that lists it in two cases, and the warning then names what
@@ -2461,9 +2466,11 @@ build fails as above. Not read either is a `trustLockfile` that reaches the pnpm
24612466
build another way (`pnpm_config_trust_lockfile` in Bazel's environment): hosted mode
24622467
withholds there as well. Not read either: a hub that names the lock of a workspace member
24632468
(`pnpm_lock = "//packages/a:pnpm-lock.yaml"`), which is pinned as without Bazel. The
2464-
in-memory engine reads the Bazel files beside the lock (`MODULE.bazel`, the
2465-
`*.MODULE.bazel` files it can include and the `WORKSPACE` files) and gives the answer of a
2466-
checkout with the same files; it sees no Bazel root above the project and no
2469+
in-memory engine reads the Bazel files beside the lock or beside a `pnpm-workspace.yaml`
2470+
(`MODULE.bazel`, the `*.MODULE.bazel` files it can include and the `WORKSPACE` files) and
2471+
gives the answer of a checkout with the same files; it sees no Bazel root above the
2472+
project, for the pin and for the route through a named registry alike (a project in a
2473+
directory of a Bazel workspace is routed in memory where a checkout is not), and no
24672474
`MODULE.bazel.lock`, and a `pnpm_version_from` file that is not among the project's own
24682475
manifests reads there as a release that is not written out, so a lock that a checkout pins
24692476
can be left as it is in memory. Nor does hosted mode look at `--no-trust-lockfile-config`

0 commit comments

Comments
 (0)