Skip to content

Commit e44a2bd

Browse files
kanadguptaclaude
andauthored
chore(release): stop mutating global registry config in local-registry (#5922)
## What `pnpm local-registry` (the local Verdaccio helper for release testing) no longer redirects the global `npm` and `pnpm` registry config to `localhost:4873` on startup, and no longer needs to restore it on shutdown. The cleanup handler now just kills Verdaccio, and additionally handles `SIGHUP` so closing the terminal window doesn't orphan the server. `CONTRIBUTING.md` is updated to match, and the troubleshooting table now covers recovering from the stale override left behind by older versions of the script. ## Why The restore path had holes that could leave a developer's machine pointed at a dead localhost registry, making every subsequent `pnpm i` fail: - The Verdaccio-crash path called `process.exit(1)` without restoring the registry. - `SIGHUP` (closing the terminal) wasn't handled, so no cleanup ran at all. - A partial restore failure only printed a warning, right as the terminal session was being torn down. This bit for real: pnpm persists the override in its own global config (`~/Library/Preferences/pnpm/auth.ini` on macOS) rather than `~/.npmrc`, so an `~/.npmrc`-focused manual cleanup makes npm look healthy while pnpm silently keeps resolving from `localhost:4873`. The global redirect was also unnecessary: `local-release.ts` already passes `--registry` explicitly to every publish command and writes a scoped `.npmrc` (with the auth token) into its temp publish dir, and the suggested `npx` / `npm install -g` smoke-test commands carry the flag too. With the redirect gone, there is no cleanup left to get wrong — a crash or hard kill can no longer corrupt the developer's registry config. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
1 parent 11f31dd commit e44a2bd

2 files changed

Lines changed: 14 additions & 35 deletions

File tree

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ Test a real end-to-end publish and install of the CLI against a local npm regist
270270
pnpm local-registry
271271
```
272272

273-
This starts Verdaccio on `http://localhost:4873`, creates a publish user, and redirects the global `npm` and `pnpm` registry config to `localhost`. Press **Ctrl+C** when done — the original registry settings are restored automatically.
273+
This starts Verdaccio on `http://localhost:4873` and creates a publish user. Your global `npm` and `pnpm` registry config is never modified — every command that talks to the local registry passes `--registry` explicitly. Press **Ctrl+C** when done.
274274

275275
**Terminal 2 — build and publish:**
276276

@@ -310,7 +310,7 @@ supabase --version
310310
| `Error: Something is already running on port 4873` | Kill the leftover Verdaccio process (`lsof -ti:4873 \| xargs kill`) and retry |
311311
| `go not found in PATH` (legacy only) | Install Go from https://go.dev/dl/ |
312312
| `Error: Go CLI source not found` (legacy only) | Run `pnpm repos:install` to clone `apps/cli-go` |
313-
| Registry not restored after crash | Run `npm config set registry https://registry.npmjs.org/` and `pnpm config set registry https://registry.npmjs.org/` |
313+
| `npm` / `pnpm` tries to fetch from `localhost:4873` when no registry is running | Stale global registry override left behind by an older version of `local-registry.ts` (the current script never modifies global config). Run `npm config delete registry` and `pnpm config delete registry`. Note that pnpm stores the override in its own global config (`~/Library/Preferences/pnpm/auth.ini` on macOS, `~/.config/pnpm/` on Linux), not `~/.npmrc` — check there if the delete command fails |
314314
| `npx` resolves from npm instead of local | Pass `--registry http://localhost:4873` explicitly to `npx` / `npm install` |
315315

316316
## Using Nx

tools/release/local-registry.ts

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
*
66
* - Starts Verdaccio on http://localhost:4873
77
* - Creates a local publish user and stores the auth token in tmp/verdaccio-token
8-
* - Redirects the global npm and pnpm registry config to the local registry
9-
* - Restores the original registry config and kills Verdaccio on Ctrl+C / SIGTERM
8+
* - Kills Verdaccio on Ctrl+C / SIGTERM / SIGHUP
9+
*
10+
* Global npm/pnpm registry config is never modified — everything that talks to
11+
* the local registry passes --registry explicitly (see local-release.ts), so a
12+
* crash or hard kill cannot leave the developer's machine pointed at localhost.
1013
*/
1114

12-
import { $ } from "bun";
1315
import { openSync } from "node:fs";
1416
import { mkdir, rm, writeFile } from "node:fs/promises";
1517
import path from "node:path";
@@ -80,15 +82,6 @@ async function createUser(): Promise<string> {
8082
return body.token;
8183
}
8284

83-
async function getRegistryConfig(tool: "npm" | "pnpm"): Promise<string> {
84-
try {
85-
const value = (await $`${tool} config get registry`.quiet().text()).trim();
86-
return value === "undefined" ? "https://registry.npmjs.org/" : value;
87-
} catch {
88-
return "https://registry.npmjs.org/";
89-
}
90-
}
91-
9285
async function main() {
9386
if (await isPortInUse()) {
9487
console.error(`\nError: Something is already running on port ${PORT}.`);
@@ -134,13 +127,6 @@ async function main() {
134127
const token = await createUser();
135128
await writeFile(tokenPath, token, "utf-8");
136129

137-
// Capture current global registry settings so we can restore them on exit.
138-
const origNpm = await getRegistryConfig("npm");
139-
const origPnpm = await getRegistryConfig("pnpm");
140-
141-
await $`npm config set registry ${REGISTRY}`.quiet();
142-
await $`pnpm config set registry ${REGISTRY}`.quiet();
143-
144130
console.log(`
145131
Registry : ${REGISTRY}
146132
Token : ${tokenPath}
@@ -150,28 +136,21 @@ async function main() {
150136
pnpm cli-release --next
151137
pnpm cli-release --legacy
152138
153-
Press Ctrl+C to stop and restore the original registry settings.
139+
Global npm/pnpm registry config is untouched — pass --registry ${REGISTRY}
140+
to npx / npm install when testing the published package.
141+
142+
Press Ctrl+C to stop.
154143
`);
155144

156-
const cleanup = async () => {
157-
process.stdout.write("\nShutting down local registry...");
158-
try {
159-
await $`npm config set registry ${origNpm}`.quiet();
160-
await $`pnpm config set registry ${origPnpm}`.quiet();
161-
process.stdout.write(" registry restored.\n");
162-
} catch {
163-
process.stdout.write(
164-
"\nWarning: could not restore registry config — run:\n" +
165-
` npm config set registry ${origNpm}\n` +
166-
` pnpm config set registry ${origPnpm}\n`,
167-
);
168-
}
145+
const cleanup = () => {
146+
process.stdout.write("\nShutting down local registry...\n");
169147
proc.kill();
170148
process.exit(0);
171149
};
172150

173151
process.on("SIGINT", cleanup);
174152
process.on("SIGTERM", cleanup);
153+
process.on("SIGHUP", cleanup);
175154

176155
// Block until a signal is received.
177156
await new Promise<never>(() => {});

0 commit comments

Comments
 (0)