Repository navigation
Pin no pnpm lock that a Bazel hub would reject with pnpm 11 - #2213
Conversation
…h 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>
`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>
…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>
PR SummaryMedium Risk Overview A new Docs, Reviewed by Cursor Bugbot for commit 92a71c6. Configure here. |
|
[agent] PR shepherd: review brief for the approver What it does: In a Bazel workspace where an aspect_rules_js Risk: medium. The change only holds pins back, and only when a project has a root pnpm lock and a matching hub. The worst a wrong reading can do is miss a patch, which the warning explains; it can't break a build that works on Look here:
Verified:
Changes I made: none. Open questions: decisions 2 and 3 in the description are product calls. Decision 2: a hub that lists a bare Generated by Claude Code |
Wenxin Jiang (Wenxin-Jiang)
left a comment
There was a problem hiding this comment.
[agent] Reviewed pnpm version and settings checks, both planner paths, and rollback ownership of the settings file. The guard leaves the affected root lock untouched.
Resolve scripts/loc-budget.json: main raised the bazel group to 2665 and this branch to 2773 from the same base; the merged tree counts 2952, so the bazel max is set to that. Assisted-by: Claude Code:claude-opus-5-5
Hosted mode no longer pins a pnpm lock that a Bazel hub would reject with pnpm 11: it skips the package, exits 0 and says which line to add to the hub.
Decisions for the maintainer
update_pnpm_lockor adatathat is a constant, and ause_pnpmwhose repository cannot be followed to apnpm.pnpmtag. The price: a hub whosedatais a constant that already lists the file built patched before and gets no new pin until the list is written out in the call. The warning says so. A lock that is pinned already stays pinned.pnpm-workspace.yamlthat would hold only what hosted mode writes: none, an empty one, one with the root-onlypackagesalone, the file of an earlier hosted run. Such a hub built patched before this change;rollbackthen removed the file, the call named a missing one, and the build failed. Now the pin waits for a comment line in the file. If a patch that builds today matters more than the undo, this half can go: it is onematcharm.pnpm.pnpmtag states the release. The other choice is to assume pnpm 10 for every release, which breaks the build on the first one that moves to 11.MODULE.bazelbeside apnpm-lock.yaml: one more text file per such root. Without it the in-memory engine would still pin such a lock. Dropping the lines inselect.rskeeps hosts as they are.--no-trust-lockfile-configthe lock is pinned without the setting, with the existing warning that pnpm 11 rejects it, and the pnpm of such a hub does reject it (measured with the option on Bazel 9.3.2). The step that leaves the lock out does not have that option. AtrustLockfile: falseof the project's own is no longer part of this: hosted mode pins nothing beside it.rollbackstill removes apnpm-workspace.yamlit cannot tell from one hosted mode created. No new pin is written beside such a file any more (decision 2), so this is left for a pin an earlier release wrote. Keeping a listed file on rollback would be a change torollback; it is in the docs' known problems.use_pnpmthat names@pnpmwhere another extension makes a repository of that name. If that pnpm is 11 or later the lock is pinned and the build fails. Closing it needs the workspace reader to say which extension ause_repobelongs to. The docs list it under what is not read.What the code does today
In a Bazel workspace whose
npm.npm_translate_lock(aspect_rules_js) hasupdate_pnpm_lock = True, rules_js runs a pnpm of its own during the build whenever the lock or apackage.jsondiffers from the hashes it keeps under.aspect/. It runspnpm install --lockfile-onlyin a directory that holds the lock, thepackage.jsonfiles and the files the call lists asdata, and nothing else of the checkout.Hosted mode pins the lock and writes
trustLockfile: truetopnpm-workspace.yaml, the setting without which pnpm 11 and later reject a lock whose tarball URL is not the registry's. When the hub does not list that file, its pnpm never reads the setting:socket-patch scan --mode hosted --yesexits 0 and reports the patch applied;bazel buildfails withERR_PNPM_TARBALL_URL_MISMATCH.Measured on Bazel 9.3.2 with aspect_rules_js 3.6.0 and pnpm 11.28.10. The first commit adds a test that holds exactly this, and passes on the product code as it is.
What changes
Hosted mode writes nothing for the project's root pnpm lock when one call names that lock in a plain string and all three hold for it:
update_pnpm_lockisTrue;datadoes not list thepnpm-workspace.yamlbeside the lock, or lists one that a pin and its undo would not leave standing (below);The run exits 0 with status
success. Each package is askippedevent:redirect_unconfirmed, orredirect_unattributablein a project that also has a lock of npm's, which is then not pinned either. One warning,redirect_pnpm_bazel_workspace_hidden, names the call by file and line, as the file writes it, and the way on:For a project below the Bazel root the warning starts
MODULE.bazel:7, with paths from the root of the Bazel workspace: …, because its paths are not the ones of a run in the project's directory.The file has to be one that a pin and its undo leave standing. Two cases need a step of their own, which comes before the label, or alone where the hub lists the file already:
packages:and- '.', or is the file of an earlier hosted run. The step isput a comment line in pnpm-workspace.yaml (create the file where there is none: …). Hosted mode would create or fill the file, butrollbackremoves a file that holds nothing else, and a hub that names a missing file fails the build (measured on Bazel 9.3.2). It is one wording for a missing file and a bare one: while a vendored patch is being taken over the file is briefly gone when the hub is judged, and the earlier text then told the user to create a file the checkout has.trustLockfile:with another value thantrue, which hosted mode leaves as the user's call, or it is YAML a line cannot be added to (a flow-style root, several documents). The pnpm of the hub would read the file and still reject the lock. The step is to settrustLockfile: truein it.One more form: where
datais not written out as a list of strings, the last step is to write it out as one that holds the label. The value may list the file already, and adding the label elsewhere would change nothing.Where the pnpm release is read: rules_js takes the pnpm from the repository the call's
use_pnpmnames (@pnpmwithout one). Apnpm.pnpmtag of thatnamemakes it frompnpm_version, or from thepackageManagerof thepackage.jsonthatpnpm_version_fromnames. Of several tags the newest release counts. A workspace that states no release gets the pnpm rules_js picks: its newest pnpm 8 through 2.9.3 (8.15.3 at 1.42.3), its 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_VERSIONinnpm/private/pnpm_repository.bzl, read at those tags). None rejects the lock, so nothing is withheld for those releases: the one the root module asks for withbazel_depor pins with asingle_version_override, and the oneMODULE.bazel.lockselected, where that file is there. For any later release, a version that is not written out and a ruleset that an override takes from elsewhere than a registry, the choice is not known and counts as a pnpm that may be 11 or later.A
use_pnpmis a label of the root module, so it is followed to a tag only where ause_repotakes its repository by position, under the tag's own name, and, unless that name ispnpm, a tag makes it. Withuse_repo(pnpm, eleven = "pnpm")anduse_pnpm = "@eleven//...", Bazel runs the pnpm 11 of the tagpnpm: measured on Bazel 9.3.2 on an earlier state of this branch, which pinned that lock, and the build failed. Such a rename, a repository of another extension and a repository of a repository rule are now read as a release that is not written out, and withhold.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_lockthat is notTrueorFalse, adatathat is not a list of strings, an attribute a**may pass, a release that is no version (latest, a constant, apackage.jsonthat cannot be read), ause_pnpmthat is not followed, and a call that is not a statement of its own. What the reader may not have seen at all (an included file that is missing, aWORKSPACEfile) withholds nothing.Nothing changes:
pnpm-lock.yaml, where no Bazel file is read at all;update_pnpm_lock, one that runs pnpm 10 or states no release under a release of the ruleset whose choice is known, and one that lists a file of the user's own that takes the setting;sharedWorkspaceLockfile: false, which no hub of this answer reads: they are pinned as on main while the root lock is left out.A vendored patch that a hosted scan would take over stays vendored. A lock that is pinned already stays pinned.
The in-memory engine gives the answer of a checkout with the same files. For that, path selection now asks for the
MODULE.bazelbeside apnpm-lock.yaml. It is not handedMODULE.bazel.lock, nor apnpm_version_fromfile outside the project's own manifests: such a file reads there as a release that is not written out, so a lock that a checkout pins can be left as it is in memory.Contents
crates/socket-patch-core/src/bazel/pnpm.rs, new: the answer, read only through the existing workspace readerhosted/engine.rs: one branch beside the existing pnpm refusals; member locks read beside ithosted/guidance.rs:is_trust_scaffold, which the undo inpatch/redirect/upstream/npm.rsnow asks toohosted/memory/select.rs,bazel/mod.rsbazel/pnpm.rs(8) and one inhosted/engine.rstests/e2e_bazel_build/npm.rs: two flows on real Bazel, five tests without Bazeltests/hosted_memory_parity.rs: one parity testdocs/ecosystems.md,CLI_CONTRACT.md.github/workflows/bazel-npm.yml, comments onlyscripts/loc-budget.json: the bazel group's cap, 2486 to 2773No fixture file is added: the flows edit
MODULE.bazelin their own workspace copy, so the three existing npm flows are as they were. 302 implementation code lines in all.In
docs/ecosystems.mdthe npm cell of the Bazel table carries the condition, the entry for this case leaves the list of known problems, two entries of that list say what is left (--no-trust-lockfile-config; therollbackof a pin an earlier release wrote beside a bare listed file), and a section "Bazel workspaces: npm" says when hosted mode withholds and what is not read.What it proves, and where
On real Bazel 9.3.2, 8.8.2 and 7.7.2 (macOS arm64, the whole npm leg, five flows, 40 to 44 s per release):
npm::hosted_update_pnpm_lock_on_pnpm_11: the scan pins nothing and warns; the same build passes on the upstream package; after exactly what the warning says (the file, then the label) the same scan pins the lock and the build is the patched one;rollbackleaves the user's file and the build is the upstream one again.npm::hosted_update_pnpm_lock_on_pnpm_10: the same hub with the pnpm rules_js picks. Pinned and patched as before, with no line added.ASPECT_RULES_JS_FROZEN_PNPM_LOCKfails until one without it has rewritten the file.Without Bazel:
get --mode hostedpin nothing, for a project at the root and for one in a directory of the workspace, with the warning's start and end held exactly;packagesalone and one that saystrustLockfile: false, each with the step the file needs and no label;redirect_unattributable, with no file changed;MODULE.bazel: exit code, both streams byte for byte, every file;redirectblock, for a hub that hides the file, one that lists a file of the user's own, and one that lists a bare file;sharedWorkspaceLockfile: falseare read and pinned while the root lock is left out (a unit test of the engine);use_repotakes,@pnpmand a named repository followed to a pnpm 10, the newest of several tags, the releases of the ruleset whose own pnpm is known and the ones it is not (bybazel_dep, by a pin, by an override, by Bazel's lock), each case of a listed file, and each form of the way on, including which filesrollbackwould remove.Checks of the tests themselves:
use_pnpmgive identical output and files, and the shapes above are withheld where the base pins.Not covered
WORKSPACEfile, and a hub whosepnpm_lockis not a plain string: not read, pinned as before.pnpm_lock = "//packages/a:pnpm-lock.yaml"): not read, pinned as before.--no-trust-lockfile-config(decision 5).pnpmthat another extension makes (decision 5): pinned as before.npm_package_lockoryarn_lock, where rules_js runspnpm import: not measured.MODULE.bazelincludes, a Bazel root above the project,MODULE.bazel.lock, and apnpm_version_fromfile outside the project's own manifests, which withholds there where a checkout pins.bazel/built.rs: time and tidiness, left for a change of their own.pnpm_config_trust_lockfilein Bazel's environment), whereASPECT_RULES_JS_DISABLE_UPDATE_PNPM_LOCKswitches the update off, and on Windows, where rules_js switches it off itself. The warning's way on works in each.use_pnpm, that workspace was run without Bazel only: the scan writes nothing there, so the build is the one before the scan. The comment-line form of the way on was likewise run without Bazel only.Code review
Nine findings on the first two commits, each checked against the code. The third commit takes them as follows.
Fixed, each with a test that fails without it:
trustLockfile: false, or that a line cannot be added to, the lock was pinned without the setting and the pnpm of the hub rejects it. Hosted mode now pins nothing there and says to set the key.rollbackwould remove. Beside a listed file with nothing of the user's own, the lock was pinned, and a laterrollbackremoved the file and left the call with a missing one. Now withheld until the file holds a comment line (decision 2).sharedWorkspaceLockfile: falsewere not read. They are read and pinned as on main.npm.npm_translate_lockwhatever the file calls it; and for a project below the Bazel root it gave paths from that root without saying so.rollbackremoves was written twice. It is one function now, which the undo asks too.Not fixed:
--no-trust-lockfile-configstill pins without the setting. The step that leaves the lock out is not handed that option, and handing it over changes about fifteen call sites. It stays a known problem in the docs (decision 5).pnpm_version_fromfile outside the project's manifests, so it withholds where a checkout pins. Path selection works on paths alone and cannot follow a label; the docs say so.bazel/built.rs. Time and tidiness only; sharing them touches files other open changes rewrite.Generated by Claude Code