Skip to content

Commit 447e822

Browse files
Pin no pnpm lock that a Bazel hub would reject with pnpm 11 (#2213)
* Test hosted mode on a rules_js hub that keeps the lock up to date with pnpm 11 With `update_pnpm_lock = True`, aspect_rules_js runs a pnpm of its own during the build whenever the lock or a `package.json` differs from the hashes it keeps under `.aspect/`: `pnpm install --lockfile-only`, in a directory that holds the lock, the `package.json` of each importer and the files the hub lists as `data`, and nothing else of the checkout (rules_js 3.6.0, npm/private/npm_translate_lock_state.bzl). Hosted mode pins the lock and writes `trustLockfile: true` to `pnpm-workspace.yaml`, the setting without which pnpm 11 and later reject a lock whose tarball URL is not the registry's. A hub that does not list that file as `data` hides the setting from the pnpm Bazel runs. The new flow `npm::hosted_update_pnpm_lock_on_pnpm_11` holds what the command does there today, on real Bazel: the fixture's hub with `update_pnpm_lock = True` and no `data`, and a `pnpm.pnpm` tag that states pnpm 11.28.10. The first build passes and prints the unpatched marker; `scan --mode hosted --yes` exits 0 and reports the patch applied; the next `bazel build` fails with ERR_PNPM_TARBALL_URL_MISMATCH. Measured on Bazel 9.3.2 with the product code as it is. A command that exits 0 and leaves a failing build is what the next commit removes; this one only records it. The flow edits the `MODULE.bazel` of its workspace copy, so the fixture and the three existing flows are as they were. The pnpm that Bazel runs gets the stand-in as its registry through `pnpm_config_registry` (and `npm_config_registry`, which pnpm 10 reads), and the stand-in serves the package's registry document, because pnpm 11 holds every lock entry to what the registry publishes before it does anything else. The pnpm itself is the one download the flow adds to a leg: the `pnpm` package of the public registry, about 5 MB, held to the checksum rules_js has for it. The workflow's header says so. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * Pin no pnpm lock that a Bazel hub would reject with pnpm 11 `scan --mode hosted` exited 0, reported the patch applied, and the next `bazel build` failed with ERR_PNPM_TARBALL_URL_MISMATCH, in a workspace whose `npm.npm_translate_lock` has `update_pnpm_lock = True`, runs pnpm 11 or later and does not list `pnpm-workspace.yaml` as `data` (measured on Bazel 9.3.2 with aspect_rules_js 3.6.0 and pnpm 11.28.10; the previous commit holds it). rules_js runs that pnpm in a directory with the lock, the `package.json` files and the hub's `data` only, so it never reads the `trustLockfile: true` hosted mode writes, and pnpm 11 rejects a lock whose tarball URL is not the registry's. Hosted mode now writes nothing for the pnpm lock of such a project. The run exits 0 with status `success`, each package is a `skipped` event (`redirect_unconfirmed`), and one warning, `redirect_pnpm_bazel_workspace_hidden`, names the call by file and line and the way on: list the label of `pnpm-workspace.yaml` in the `data` of that call and run the command again. `scan`, its dry run and `get --mode hosted` behave alike, and a vendored patch that a hosted scan would take over stays vendored. In a project that also has a lock of npm's, that lock is not pinned either: the pnpm lock still names the registry's tarball, so the package is skipped as `redirect_unattributable`. The way on has three more forms: - The project has no `pnpm-workspace.yaml`: create it first (a comment line is enough). Hosted mode would create it, but `rollback` removes a file hosted mode created, and a hub that names a missing file fails the build (measured). - The file would be nothing but what hosted mode creates once the setting is in it (an empty file, one with only `packages:` and `- '.'`, a file of an earlier hosted run): add a comment line first. `rollback` cannot tell such a file from one it created and removes it (measured on Bazel 9.3.2: the build then fails on the missing file). - `data` is not written out as a list of strings: write it out as one that holds the label. The value may list the file already, and adding the label somewhere else would change nothing. The answer is in a file of its own, bazel/pnpm.rs, and reads the workspace only through the existing reader. It needs one call that names the project's `pnpm-lock.yaml` in a plain string, and for that call: - `update_pnpm_lock` is `True`; - `data` does not list the `pnpm-workspace.yaml` beside the lock; - the pnpm it runs is stated as 11 or later. rules_js takes that pnpm from the repository the call's `use_pnpm` names (`@pnpm` without one), which a `pnpm.pnpm` tag of that `name` makes from `pnpm_version` or from the `packageManager` of the `package.json` that `pnpm_version_from` names (npm/private/pnpm_extension.bzl at 3.6.0). A workspace that states no release gets the pnpm rules_js picks: its newest pnpm 10 at 3.x and 4.0.0-alpha.1, its newest pnpm 8 at 2.x. Those take the pinned lock (measured for 3.6.0 on Bazel 9.3.2), so nothing is withheld there. A `use_pnpm` is a label of the root module, so it is followed to a tag only where a `use_repo` takes its repository by position, under the tag's own name, and, unless that name is `pnpm`, a tag makes it. With `use_repo(pnpm, eleven = "pnpm")` and `use_pnpm = "@eleven//..."`, Bazel runs the pnpm 11 of the tag `pnpm` (measured on 9.3.2, where that build fails on a pinned lock), and a repository of another extension or of a repository rule can be any pnpm: both are read as a release that is not written out, and withhold. One case is still read as the pnpm rules_js picks: a `use_pnpm` that names `@pnpm` where another extension makes a repository of that name. The docs list it under what is not read. What a call does not write out counts against writing, because a failing build is worse than a patch that a warning explains: an `update_pnpm_lock` that is not `True` or `False`, a `data` that is not a list of strings, an attribute a `**` may pass, a release that is no version (`latest`, a constant, a `package.json` that cannot be read), a `use_pnpm` that is not followed, a call that is not a statement of its own. So a hub whose `data` is a constant gets no new pin until the list is written out in the call, also where the constant lists the file and the build would take the pin (measured), and a hub whose `update_pnpm_lock` is a constant is taken as one that keeps the lock up to date; a lock that is pinned already stays pinned. What the reader may not have seen at all (an included file that is missing, a `WORKSPACE` file) withholds nothing: a project whose lock no listed call names is pinned as before. Nothing changes for a hub without `update_pnpm_lock`, one that runs pnpm 10, one that lists the file, a project whose lock no hub names and a project in no Bazel workspace: tests hold each of those runs to the run of the same checkout without its `MODULE.bazel`, both streams byte for byte and every file. For a project without a root `pnpm-lock.yaml` (one with npm's lock, say) no Bazel file is read at all. The in-memory engine gives the same answer for the same files (a parity test holds it to the disk run). For that, path selection now asks for the `MODULE.bazel` beside a `pnpm-lock.yaml`. A hub in a file that `MODULE.bazel` includes, and a Bazel root above the project, are not seen in memory. The flow of the previous commit now holds the new behaviour on real Bazel: the scan pins nothing and warns, the same build passes on the upstream package, and after exactly what the warning says (the file and the label) the same scan ends in the patched build; `rollback` then leaves the user's file, and the build is the upstream one again. A second flow is the same hub with the pnpm rules_js picks: pinned and patched as before, with no line added. Both also hold what rules_js does with its file of hashes: after the lock changed, a build under ASPECT_RULES_JS_FROZEN_PNPM_LOCK fails until one without it has rewritten that file. Unit cases hold each reading above, the three forms of the way on among them, and a test without Bazel holds the project with both locks. docs/ecosystems.md: the npm cell of the Bazel table carries the condition, a section "Bazel workspaces: npm" says when hosted mode withholds and what is not read, and the entry leaves the list of known problems. One entry joins that list, found on the way and not changed here: with `--no-trust-lockfile-config` the lock is pinned without the setting, and the pnpm of such a hub rejects it (measured by hand on 9.3.2). The size budget of the bazel group follows the new file. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * Close five ways a hosted pnpm pin could still fail a rules_js build, or miss one A review of the change that keeps hosted mode from pinning a pnpm lock which a Bazel hub would reject with pnpm 11 found cases it still let through, one it took a patch away in, and three places where the warning said the wrong thing. A hub that lists pnpm-workspace.yaml was passed over without a look at the file. Hosted mode now pins nothing beside a listed file in two cases: - It would not write `trustLockfile: true` to the file: the file sets the key to another value, which is left as the user's call, or it is YAML that a line cannot be added to. The pnpm of the hub reads the file and rejects the pinned lock all the same (ERR_PNPM_TARBALL_URL_MISMATCH). - The file would hold only what hosted mode writes: there is none, or it is empty, or holds the root-only `packages` alone, or is the file of an earlier hosted run. `rollback` removes such a file with the pin, because it cannot tell it from one hosted mode created, and a call that names a missing file fails the build. The warning names what the file needs. Where the hub does not list the file yet, the same step comes before the label, and the two wordings for "no file" and "a file of hosted mode's bytes" are one: during a takeover of a vendored patch the file is briefly gone while the hub is judged, and the old text then said to create a file the checkout has. Where no `pnpm.pnpm` tag states a release, rules_js runs a pnpm of its own choice. That was taken to be older than 11 for every release of the ruleset. It is known for the releases it was read in: the newest pnpm 8 through 2.9.3, the newest pnpm 10 from 3.0.0 through 3.6.0 and at 4.0.0-alpha.0 and 4.0.0-alpha.1 (DEFAULT_PNPM_VERSION in npm/private/pnpm_repository.bzl). The release is read from the root module's `bazel_dep` and `single_version_override` and from MODULE.bazel.lock where there is one; for any later release, a version that is not written out and a ruleset an override takes from elsewhere, the choice counts as a pnpm that may be 11 or later. The members' own locks of a workspace with `sharedWorkspaceLockfile: false` were no longer read once the hub stood against the root lock, so their pins, which no hub reads, were lost. They are read and pinned as on main; the root lock alone is left out, and the warning says "<lock> was not rewritten" where it said that no pnpm lock was. The warning also named the oldest of several pnpm 11 tags where rules_js runs the newest, called the hub `npm.npm_translate_lock` whatever the file calls its proxy, and gave paths from the Bazel root to a run in a project below it without saying so. The rule for a file that `rollback` removes is now one function, `hosted::guidance::is_trust_scaffold`, which the undo itself asks. Not changed: `--no-trust-lockfile-config` still pins without the setting (the reading step does not have the option; it stays a known problem in the docs), a hub that names a workspace member's lock is not read, and in memory a `pnpm_version_from` file outside the project's manifests reads as a release that is not written out. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
1 parent e0fac59 commit 447e822

12 files changed

Lines changed: 1996 additions & 21 deletions

File tree

‎.github/workflows/bazel-npm.yml‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,19 @@ name: Bazel patch compatibility (npm)
22

33
# The npm flows of the real-Bazel tests (`npm::` in `e2e_bazel_build`):
44
# hosted and vendored mode for a package that aspect_rules_js links from a
5-
# pnpm lock, and agent mode for the copy of it in `node_modules`, on each
6-
# Bazel release below. bazel-compatibility.yml holds the legs and what
5+
# pnpm lock, agent mode for the copy of it in `node_modules`, and hosted
6+
# mode on a hub that keeps the lock up to date with a pnpm of its own (a
7+
# pnpm 11, and the pnpm 10 that rules_js picks), on each Bazel release
8+
# below. bazel-compatibility.yml holds the legs and what
79
# every ecosystem shares; this file says when the npm legs run and on which
810
# releases.
911
#
10-
# Beyond what every leg needs, an npm leg downloads Node from nodejs.org and
11-
# ruleset archives from codeload.github.com; its repository cache holds them
12-
# and comes to about 100 MB. An npm tarball under test passes through that
12+
# Beyond what every leg needs, an npm leg downloads Node from nodejs.org,
13+
# ruleset archives from codeload.github.com and, for the hubs that keep
14+
# their lock up to date, the two pnpm releases that rules_js runs: the
15+
# `pnpm` package of registry.npmjs.org, about 5 MB each, held to the
16+
# checksums rules_js has for them. The repository cache of a leg holds them
17+
# and comes to about 110 MB. An npm tarball under test passes through that
1318
# cache as well: Bazel's downloader fetches it and keeps it under its
1419
# sha512. So a test builds the upstream tarball and each patched one anew,
1520
# with an id of the run in the entry file, and writes the upstream sum into

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2509,6 +2509,7 @@ command's integration tests check its output.
25092509
| `patch_fetch_failed` (eject) | `failed` | vendor eject (v5.0): a hosted pin's patch record could not be fetched from `…/patches/view/<uuid>`; the whole eject is refused (`eject_refused`), nothing touched, exit 1. |
25102510
| `redirect_pnpm_lockfile_elsewhere` / `redirect_workspace_lockfile_elsewhere` / `cargo_manifest_not_workspace_root` (hosted) | top-level `error.code` (`status: "error"`) | scan / get `--mode hosted` (v5.0): the project directory is a workspace member whose lock lives in another directory, so the rewriters, which read only the project directory, would pin nothing, or would pin a lock of its own that its package manager never reads (`redirect_workspace_lockfile_elsewhere`: a `pnpm-lock.yaml` in a member a `pnpm-workspace.yaml` lists, which pnpm ignores for the workspace's shared lock unless the workspace sets `sharedWorkspaceLockfile: false`, checked with pnpm 10.34 and 11.27; a yarn 1 `yarn.lock` in a `package.json` workspace member, which yarn 1.22 never reads; the message names the workspace root to run from) (pnpm: no npm-family lock here, and the nearest ancestor `pnpm-workspace.yaml` or the project's `lockfile-dir` (`.npmrc`) / `lockfileDir` (`pnpm-workspace.yaml`) puts `pnpm-lock.yaml` elsewhere; npm / yarn / Bun, `redirect_workspace_lockfile_elsewhere`: no npm-family lock here, and the nearest ancestor `package.json` whose `workspaces` (array, or the object form's `packages`) matches the directory holds `package-lock.json`, `npm-shrinkwrap.json`, `yarn.lock`, `bun.lock` or `bun.lockb`; a matching root with none of them that is itself listed by an outer root's `workspaces` hands the check to that root; vlt, same code: the nearest ancestor `vlt.json` whose `workspaces` (a string, an array, or an object of groups) matches the directory holds `vlt-lock.json`, or, as vlt falls back to it when `vlt.json` has no `workspaces` field, the `package.json` `workspaces` root above holds `vlt-lock.json`, and the nearer of a `vlt.json` and a `package.json` root is named; `workspaces` patterns use the glob grammar the package managers share: `*`, `?`, `**`, brace sets and sequences (`{a,b}`, `{1..3}`) and character classes (`[a-c]`, `[!a]`), read the way the root's lock's package manager reads them (#1097): extglobs (`@(a|b)`, `?(…)`, `*(…)`, `+(…)`, `!(…)`) match for npm and yarn but not Bun or vlt; for Bun and vlt, `*`, `?` and `**` never match a directory whose name starts with `.` (`packages/*` does not list `packages/.tools`, #1542, #1631) unless the pattern spells the dot (`packages/.tools`, `packages/.*`), while a `!` pattern still excludes one; yarn berry (picomatch) also reads regex groups (`packages/(a|b)`; a group without `|` only in a pattern fast-glob deems dynamic, or in a `!` pattern), the regex quantifiers `?` / `+` after a group, `+` after a class and `+` inside a group, POSIX classes (`[[:alpha:]]`) and `..` segments in a static pattern or after a static prefix (`packages/a/../b` lists `packages/b`; literal in a `!` pattern); a group alternative holding `/` (`(packages/ui|apps/web)`) is matched across components, and a `?` or `+` quantifying such a group fails closed (the pattern lists every directory, and excludes none as a `!` pattern) (#1490); so does a pattern with extglob or regex groups that is past what socket-patch works out — a brace alternative longer than 4,096 characters or with more than 64 groups, or one whose matching against a directory takes more than about a million steps (an ambiguous group such as `*(a|aa)` repeated dozens of times against a name hundreds of characters long) — while a pattern without groups is read whatever its length, and a brace set is expanded to at most 4,096 alternatives and a megabyte of text; a `!` pattern excludes what earlier patterns matched for npm, Bun 1.3+ (a `bun.lock` with a top-level `configVersion`) and vlt, excludes whatever the order for yarn berry (a `yarn.lock` with `__metadata`, where a leading `!(` is an extglob), and is ignored by yarn classic and older Bun (a `bun.lock` without `configVersion`, or a `bun.lockb` alone without the trailing `cNfGvRsN` config-version extension, its binary twin, #1492); only the root's locks whose package manager lists the directory govern it (and are named), and a lockless root lists it when any of them would; when a pnpm workspace also governs the directory, the nearer root is named and a tie goes to `redirect_pnpm_lockfile_elsewhere`; uv (pypi, #1138), `redirect_workspace_lockfile_elsewhere`: the directory holds a `pyproject.toml`, and the nearest ancestor `pyproject.toml` declaring `[tool.uv.workspace]` lists it in `members` (and not in `exclude`), with no standalone project (`[project]`, no workspace) in between, so uv installs it from that root's `uv.lock` (a `uv.lock`, `poetry.lock`, `pdm.lock`, `Pipfile.lock` or pylock left in the member is never read and does not exempt it); the message says uv workspaces are not patched from their root yet either, and vendored refuses the same layout with `pypi_uv_workspace_unsupported` instead of rewriting a member with Hatch configuration as a lockless Hatch project; a directory whose own locks are all ones its manager never reads inside a workspace member is refused the same way, naming the ignored locks: `package-lock.json` / `npm-shrinkwrap.json` when its `package.json` `workspaces` root holds `package-lock.json` or `npm-shrinkwrap.json` (npm, #1094), `bun.lock` / `bun.lockb` when that root holds `bun.lock` or `bun.lockb` (Bun, #1101), and `vlt-lock.json` in a directory with no `vlt.json` of its own when its vlt workspace root (as above) holds `vlt-lock.json` (vlt, #1134), or, listed or not, when vlt's project root for the directory is another directory holding `vlt-lock.json` (vlt, #1584: the nearest ancestor `vlt.json`, else the outermost directory holding a `package.json` or `node_modules`, the walk ending at a directory holding `.git` and below the home directory, as vlt's own `find("project")` does; the message names that root and says a `vlt.json` in the directory makes it a project of its own); vendored refuses it with `vendor_lockfile_missing`, and `vex` reads the ignored lock as absent, with one `patched_ref_unattributable` warning naming it when it holds Socket references) or rewrite the member as a lockless project (cargo: the vendored workspace-root check). Refused before any takeover or write, `--dry-run` included; the message names the directory to run from; exit 1. Disk runs only (an in-memory project has no ancestors). |
25112511
| `redirect_pnpm_settings_elsewhere` | top-level `error.code` (`status: "error"`) | scan / get `--mode hosted`: the project directory is a pnpm workspace member (listed by the `packages:` globs of the nearest ancestor `pnpm-workspace.yaml`) with its own v9 `pnpm-lock.yaml` (`sharedWorkspaceLockfile: false`) and no `pnpm-workspace.yaml` of its own, so its pnpm settings come from that ancestor file, which pnpm reads alone (a member's own file is ignored). A directory those globs do not list (no `packages:`, an empty list, a non-matching or `!`-excluded path) is a standalone project on pnpm 11.28+/12 that reads only its own file: it is pinned and gets its own `pnpm-workspace.yaml` like any single project. A root file that does not parse, or whose patterns use braces, classes or extglobs, counts as listing the project. When that file neither carries `trustLockfile: true` nor explicitly sets another value, the trust auto-config has nowhere to go: refused before any takeover or write, `--dry-run` included; the message names the root file to add `trustLockfile: true` to (or `--no-trust-lockfile-config` pins without it); exit 1. Once the root file trusts the lock (or opts out), the member is pinned and no nested `pnpm-workspace.yaml` is created; the `redirect_pnpm_trust_lockfile` warning names the root file. In memory, a member whose lock is demoted into its workspace root (#492) is never refused; one whose lock is not (the workspace root's files do not confirm it pins or ignores that lock, or socket.yml leaves the root out) is refused with this code as its project error, nothing written for it, whenever its lock is v9, the trust auto-config is on and that file may list it (listed, unreadable, or not readable as globs), whatever it says about `trustLockfile`. |
2512+
| `redirect_pnpm_bazel_workspace_hidden` | `warnings[]` (warning, one per run) | scan / get `--mode hosted`, dry and wet, and the in-memory engine: the project is in a Bazel workspace where one `npm.npm_translate_lock` call of aspect_rules_js names its `pnpm-lock.yaml` in a plain string, keeps it up to date (`update_pnpm_lock` is `True` or not written out as `True` or `False`), does not list the `pnpm-workspace.yaml` beside the lock in a `data` that is a list of strings (or lists a file that would hold only what hosted mode writes, or one hosted mode does not write `trustLockfile: true` to), and runs a pnpm that the workspace states as 11 or later or in a way that is no version, or states none under a release of aspect_rules_js whose own choice is not known (any but 1.x to 3.x, 4.0.0-alpha.0 and 4.0.0-alpha.1, by `bazel_dep`, a `single_version_override` and `MODULE.bazel.lock`) (the `pnpm_version`, or the `packageManager` of the `pnpm_version_from` file, of the `pnpm.pnpm` tag whose `name` is the repository of the call's `use_pnpm`, `pnpm` without one; a `use_pnpm` whose repository no `use_repo` takes by position under that name, or that no such tag makes unless it is `pnpm`, is no version). The pnpm that Bazel runs would not read the `trustLockfile: true` hosted mode writes, would reject the pinned lock (`ERR_PNPM_TARBALL_URL_MISMATCH`), and `bazel build` would fail. Every root pnpm lock is left untouched and no npm pin is confirmed from it; the members' own locks of a workspace with `sharedWorkspaceLockfile: false` are pinned as without Bazel (in the root lock each package is a `skipped` event: `redirect_unconfirmed`, or `redirect_unattributable` where another npm lock of the project names it, which is then not pinned either), exit 0, `status: "success"`. The detail starts with the file and the line of the call, named as the file writes it (`MODULE.bazel:7: this `npm.npm_translate_lock` …`; `MODULE.bazel:7, with paths from the root of the Bazel workspace: …` for a project below that root) and ends with what to do: `; pnpm-lock.yaml was not rewritten — list `//:pnpm-workspace.yaml` in the `data` of that call and re-run`, with the label of the file beside the lock. Before the label, or alone where the call lists the file: where the file would hold only what hosted mode writes (none, an empty file, the root-only `packages` scaffold, a file of an earlier hosted run), `put a comment line in pnpm-workspace.yaml (create the file where there is none: …)`, because `rollback` removes such a file and the call would name a missing one; where the file says `trustLockfile:` with another value than `true`, or is YAML a line cannot be added to, to set `trustLockfile: true` in it. Where `data` is not written out as a list of strings, the last step is to write it out as one that holds the label. A hub without `update_pnpm_lock`, one that runs pnpm 10 or states no release under a release of the ruleset whose choice is known, one that lists a file of the user's own that takes the setting, a project whose lock no call names and a project in no Bazel workspace are not affected. See docs/ecosystems.md, "Bazel workspaces: npm". |
25122513
| `eject_refused` | top-level `error.code` (`status: "error"`) | vendor eject (v5.0): a record fetch failed or a pin's upstream restore was refused while planning; nothing was changed, exit 1. |
25132514
| `eject_planned` | `applied` (reason) | vendor eject `--dry-run` (v5.0): the pin would be restored upstream and vendored; nothing written. |
25142515
| `eject_rolled_back` | warning; `skipped` event | vendor eject (v5.0): a package failed after the restore began; every touched file was put back from the pre-eject snapshot, so the project is still hosted; `partialFailure`, exit 1. Also the `errorCode` of the `skipped` event re-reporting each package the eject had vendored before it was rolled back (not counted in `summary.applied`). |

0 commit comments

Comments
 (0)