Repository navigation
fix(pnpm): stop the lockfile carrying shard hosts, at write time - #77
Conversation
`.pnpmfile.cjs` drops the rotating `ms-feed-N.pkgs.visualstudio.com`
tarball URLs in `afterAllResolved`, which runs on the in-memory lockfile
before pnpm serializes it. The hosts are therefore never written rather
than removed afterwards.
That distinction is the whole point. `scripts/strip-lockfile-hosts.mjs`
can only repair a lockfile someone remembered to run it against, and
Dependabot cannot be asked to run anything: every dependency PR arrived
with ~1720 host-pinned entries and failed CI, six of them open at once.
A hook travels with the repository, so it applies to whoever resolves.
It cannot be a `postinstall` hook, which is the obvious thing to reach
for: pnpm rejects a recorded host BEFORE lifecycle scripts run, so the
install is already dead by then. `afterAllResolved` is part of
resolution, which is earlier.
The pattern moves to `scripts/lockfile-shard-hosts.cjs`, shared with the
repair script. They had already drifted -- the hook matched the whole
`pkgs.visualstudio.com` domain while the script matched numbered shards
only -- and one of them would have kept a URL the other dropped. They
cannot share the edit, since one holds an object and the other holds
lines, so they share the only thing that must agree.
Tested, and two of these changed the code:
fresh resolution from no lockfile 0 hosts, byte-identical to the
committed file (~1740 without it)
install --force 0 hosts, lockfile unchanged
add / update / dedupe / install 0 hosts
frozen install, clean lockfile passes
frozen install, poisoned lockfile STILL FAILS -- resolution is
skipped so the hook never runs.
CI must keep normalising before
it installs.
pnpmfile edited, not re-resolved every frozen install fails with
ERR_PNPM_LOCKFILE_CONFIG_MISMATCH
until the lockfile is re-resolved
lockfile with no `packages` map warns instead of silently doing
nothing
`packages: null` threw, because typeof null is
"object" -- would have failed
every install. Now guarded.
git and GitHub-release tarballs kept, as before
verify:workspace passes and the container suite is 15/15. The one
lockfile change is `pnpmfileChecksum`.
Not verified from here: that Dependabot's updater honours the pnpmfile.
pnpm loads it from the workspace root without configuration, so it
should, but the proof is the next dependency PR arriving clean. The
frozen-install result above is why that does not matter much either way
-- CI normalises regardless.
be9ff56 to
561524d
Compare
The rule justified it by rotating hosts, which .pnpmfile.cjs now keeps out of the lockfile at write time. The reason it is still required is the one that was never written down: it fails when the lockfile disagrees with the manifests, where a plain install silently re-resolves and rewrites. specifiers in the lockfile don't match specifiers in package.json: * 1 dependencies were added: [email protected] Confirmed both ways -- frozen refuses, plain install accepts and adds the dependency to the lockfile.
|
Tested the hook against the cases we need to cover. Two of them changed the code.
Two fixes came out of that: The null crash. Found only by testing the resilience path I'd added — the guard I wrote to make a shape change safe was itself the thing that would have broken installs. A drift between the two removers. The hook matched the whole On
|
Closes #26. pnpm 11 defaults `verifyDepsBeforeRun` to `install`, so every `pnpm run`, `pnpm test` and `pnpm --filter ... run ...` silently performs a full install first. That install re-resolves, and re-resolution re-records the rotating `ms-feed-N` tarball hosts -- all 1721 of them -- that scripts/strip-lockfile-hosts.mjs exists to remove. The effect is that stripping the lockfile and then running literally any script put every host straight back, so the next --frozen-lockfile install rejected the lockfile: the Docker test image, and CI. Working on this repo meant re-stripping after almost every command, and forgetting once produced a failure that reads like a dependency break rather than like a stale lockfile. `warn` keeps the check the default exists for -- it still reports a node_modules that has drifted from the lockfile -- and does not write. Verified: with the setting in place, `pnpm run verify:workspace`, `pnpm --filter maximal-site run build`, `pnpm test` and a full container suite all leave the lockfile byte-identical, with zero recorded hosts. Without it, one `pnpm run` re-adds 1721. Rebased after #77 landed, which changes what this is for. `.pnpmfile.cjs` now drops the shard hosts as the lockfile is written, so an implicit install no longer poisons anything and the acute failure is gone. The setting is still worth having, for the smaller reason it was always also true: a `pnpm run` should not resolve and rewrite the tree behind the script it was asked to run. The prose in SOURCES.md and pnpm-workspace.yaml says that rather than the pre-#77 rationale, and the first of the two caveats below is now obsolete -- kept as the record of why the hook exists. Two things this does NOT fix, recorded so the next person does not go looking: The tarball URLs themselves. The proxy serves tarballs from ms-feed-N.pkgs.visualstudio.com while the registry is packagefeedproxy.microsoft.io, and pnpm records a tarball URL whenever it cannot rebuild it from registry + name + version -- which it never can when the hosts differ. `lockfileIncludeTarballUrl` does not help: it only drops URLs that ARE reconstructible. There is no setting to disable the check. pnpm/pnpm#13619 reproduces this against this exact proxy and these exact hosts. (Superseded by #77: the pnpmfile hook drops them at write time instead.) The need to strip after a deliberate `pnpm install`. That is unchanged, and SOURCES.md already documents it. What changes is that it is now needed after an install rather than after every command.
Answers "can we just run strip on install?" — yes, and better than that: at
write time, so the hosts are never in the lockfile at all.
.pnpmfile.cjsdrops the rotatingms-feed-N.pkgs.visualstudio.comtarball URLsin
afterAllResolved, which runs on the in-memory lockfile before pnpmserializes it.
Why this beats the strip script
scripts/strip-lockfile-hosts.mjscan only repair a lockfile someone rememberedto run it against. Dependabot cannot be asked to run anything — every
dependency PR arrived with ~1720 host-pinned entries and failed CI; six were open
at once. A hook travels with the repository, so it applies to whoever resolves.
It also cannot be a
postinstallhook, which is the obvious thing to reach for:pnpm's check rejects a recorded host before lifecycle scripts run, so the
install is already dead by the time a hook would fire.
afterAllResolvedisearlier than that — it is part of resolution, not a lifecycle script.
Scoped to the shard hosts deliberately. A tarball URL that is genuinely not
reconstructible — a git dependency, a GitHub release — is pinned there on
purpose, and blanking it would break resolution rather than harden it. Same rule
the script follows.
Verification
pnpm install --forceover the whole workspace: drops 1740 URLs, lockfilebyte-identical, zero hosts.
pnpm runand a second forced install: unchanged.verify:workspacepasses; container suite 15/15, which exercises--frozen-lockfilewith the hook present.The single lockfile change is
pnpmfileChecksum— pnpm hashing the hook so thelockfile re-resolves if it is edited.
What I could not verify from here
That Dependabot's updater honours the pnpmfile. pnpm loads
.pnpmfile.cjsfrom the workspace root without configuration, so it should, but the proof is the
next dependency PR arriving clean.
Until that is observed, #76 (CI-side normalisation) is worth keeping as a
backstop — and its main-only assertion is what would tell us if this hook ever
stops applying. If the next Dependabot PR comes through clean, #76 becomes
belt-and-braces rather than load-bearing.
On
stripvs the settings pnpm offersSince it came up — they are not equivalent, and neither pnpm setting does what
this hook does:
trustLockfilelockfileIncludeTarballUrltrustLockfileonly silences the mismatch error; it leaves the churn and givesup the binding. Only four shards answer anonymously, so a recorded one going away
is a live failure mode, not a theoretical one.