Repository navigation
Commit 447e822
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
- crates
- socket-patch-cli
- tests
- e2e_bazel_build
- socket-patch-core/src
- bazel
- hosted
- memory
- patch/redirect/upstream
- docs
- scripts
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | | - | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
7 | 9 | | |
8 | 10 | | |
9 | 11 | | |
10 | | - | |
11 | | - | |
12 | | - | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
13 | 18 | | |
14 | 19 | | |
15 | 20 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2509 | 2509 | | |
2510 | 2510 | | |
2511 | 2511 | | |
| 2512 | + | |
2512 | 2513 | | |
2513 | 2514 | | |
2514 | 2515 | | |
| |||
0 commit comments