TypeScript
build(setup): leaner installs on Mac and Linux, cross-device store warning, setup-done marker (#22718)
Theo Browne618761a2d6d6
diff --git a/.pnpmfile.cjs b/.pnpmfile.cjsnew file mode 100644index 00000000000..ff75832369d--- /dev/null+++ b/.pnpmfile.cjs@@ -0,0 +1,21 @@+// Windows WSL dev mode runs the server under Linux from the same node_modules+// as the Windows client, so Windows installs also need Linux x64 glibc native+// modules. Other platforms install only their own binaries; setting this+// everywhere added ~2.2 GB of foreign binaries to every macOS install.+// Release scripts stage their own installs with explicit architectures.+module.exports = {+ hooks: {+ updateConfig(config) {+ // oxlint-disable-next-line t3code/no-global-process-runtime -- pnpm loads this file before any Effect runtime exists.+ if (process.platform !== "win32") return config;+ return {+ ...config,+ supportedArchitectures: {+ os: ["current", "linux"],+ cpu: ["current", "x64"],+ libc: ["current", "glibc"],+ },+ };+ },+ },+};diff --git a/AGENTS.md b/AGENTS.mdindex e87e5bfb1d9..034e505b06b 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -78,6 +78,7 @@ The most common defect in this repo is a change that works on the path you teste## Dev servers- `vp i` installs. Worktrees get this from the t3.json setup script; if module resolution looks broken, it probably did not run.+- Setup runs in the background. While `.t3/setup-running` names a live PID, wait for it and do not run `vp i`. It ends with `.t3/setup-done` or `.t3/setup-failed` (with the error tail). With no marker at all, setup never ran here, so run `vp i` yourself.- `vp run dev` starts server and web. In a worktree, state defaults to that worktree's gitignored `.t3`, which deliberately outranks an ambient `T3CODE_HOME` so you cannot land on shared state by accident. An explicit `--home-dir` still wins.- Ports derive from the worktree path and are stable across restarts, but read the real ones from the `[dev-runner]` line since occupied ports shift.- Sharing over the tailnet is three steps: run `vp run dev --share` in the background, wait for the `pairingUrl:` line in its output, then give that full URL to an unpaired browser. Do not wire up `tailscale serve` by hand, open the URL yourself, or consume the user's pairing link. A browser with the reusable dev cookie can use the bare origin. If a normal one-time token was consumed, mint a fresh one with `node apps/server/src/bin.ts pair`. It carries standard scopes, while the startup URL carries admin scopes needed for Connections settings.diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 8c03fc7d0e3..34458e07f72 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -166,6 +166,8 @@ overrides:packageExtensionsChecksum: sha256-EowbsmlBFaoO0Ypufw901RnvdyjKG5dcdk2FRbc7Dr0=+pnpmfileChecksum: sha256-lS/yS+IvX/sj4KLdjVeRsq/hRipJMILKWjIbzIC+czo=+patchedDependencies:'@clerk/[email protected]': 7a808b92da8460750b85818552e13be3fb73d111691c7db76965970351e124e4'@effect/[email protected]': 2731c9c3761c595f25ddc625a7d61ca376b389d5b3049ecb837c8940f21cfa02diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yamlindex 2fc5cd50e40..715492185e1 100644--- a/pnpm-workspace.yaml+++ b/pnpm-workspace.yaml@@ -373,8 +373,3 @@ peerDependencyRules:# pnpm keeps optional deps inside the virtual store, so hoist it to the root.publicHoistPattern:- "@cursor/sdk-*"--supportedArchitectures:- cpu: [current, x64]- libc: [current, glibc]- os: [current, linux]diff --git a/scripts/setup-worktree.ts b/scripts/setup-worktree.tsindex cee8b567aa9..6fabf341682 100644--- a/scripts/setup-worktree.ts+++ b/scripts/setup-worktree.ts@@ -5,23 +5,102 @@ import * as NodePath from "node:path";const ENV_FILES = [".env", NodePath.join("infra", "relay", ".env")];+const worktree = NodePath.dirname(import.meta.dirname);++// T3 runs setup in the background, so agents can start before it ends.+// `setup-running` holds this PID until setup ends with `setup-done` or+// `setup-failed`, so agents wait instead of racing it with their own `vp i`.+const markerDir = NodePath.join(worktree, ".t3");+const runningMarker = NodePath.join(markerDir, "setup-running");+const doneMarker = NodePath.join(markerDir, "setup-done");+const failedMarker = NodePath.join(markerDir, "setup-failed");+NodeFS.rmSync(doneMarker, { force: true });+NodeFS.rmSync(failedMarker, { force: true });+NodeFS.mkdirSync(markerDir, { recursive: true });+NodeFS.writeFileSync(runningMarker, `${process.pid}\n`);+let failureDetail = "";+process.on("uncaughtExceptionMonitor", (error) => {+ failureDetail = error.stack ?? String(error);+});+process.on("exit", (code) => {+ if (code === 0) NodeFS.writeFileSync(doneMarker, "");+ else NodeFS.writeFileSync(failedMarker, `Setup exited with code ${code}.\n${failureDetail}\n`);+ NodeFS.rmSync(runningMarker, { force: true });+});+// A cancelled setup must still leave a marker, or agents would wait forever.+// During install, the signal goes on to the installer and setup exits when the+// install output closes. Any child the shell leaves behind holds that output+// open, so no marker appears while `vp i` can still write node_modules.+let cancelSignal: NodeJS.Signals | undefined;+let activeInstall: NodeChildProcess.ChildProcess | undefined;+for (const signal of ["SIGINT", "SIGTERM", "SIGHUP"] as const) {+ process.on(signal, () => {+ cancelSignal = signal;+ if (activeInstall) activeInstall.kill(signal);+ else process.exit(1);+ });+}+const projectRoot = process.env.T3CODE_PROJECT_ROOT;if (!projectRoot) {throw new Error("T3CODE_PROJECT_ROOT is not set. Run this through the t3.json setup action.");}-const worktree = NodePath.dirname(import.meta.dirname);// `shell` resolves `vp` through PATH, including Windows command shims.// Setup has no one answering install prompts. Pass pnpm's confirmation flag// through vp and leave stdin closed so other prompts fail instead of hanging.// Install exactly the locked dependencies so setup never rewrites the lockfile.// A stale lockfile must fail setup rather than silently resolving a new one.-const install = NodeChildProcess.spawnSync("vp i --frozen-lockfile -- --yes", {+// Output is piped, not inherited, so a failure can keep its tail in the marker.+const install = NodeChildProcess.spawn("vp i --frozen-lockfile -- --yes", {cwd: worktree,shell: true,- stdio: ["ignore", "inherit", "inherit"],+ stdio: ["ignore", "pipe", "pipe"],});-if (install.status !== 0) process.exit(install.status ?? 1);+activeInstall = install;+let installOutput = "";+for (const [source, target] of [+ [install.stdout, process.stdout],+ [install.stderr, process.stderr],+] as const) {+ source.setEncoding("utf8");+ source.on("data", (chunk: string) => {+ target.write(chunk);+ installOutput = (installOutput + chunk).slice(-8_000);+ });+}+const installStatus = await new Promise<number | null>((resolve) => install.on("close", resolve));+activeInstall = undefined;+if (installStatus !== 0 || cancelSignal) {+ failureDetail = cancelSignal+ ? `Cancelled by ${cancelSignal}.`+ : installOutput.trimEnd().split("\n").slice(-30).join("\n");+ process.exit(installStatus || 1);+}++// pnpm cannot clone or hardlink across filesystems, so a store on another+// device silently turns every worktree install into a full copy.+const storeDir: unknown = JSON.parse(+ NodeFS.readFileSync(NodePath.join(worktree, "node_modules", ".modules.yaml"), "utf8"),+).storeDir;+if (+ typeof storeDir === "string" &&+ NodeFS.statSync(storeDir).dev !== NodeFS.statSync(NodePath.join(worktree, "node_modules")).dev+) {+ process.stderr.write(+ [+ "",+ "WARNING: the pnpm store is on a different filesystem than this worktree.",+ ` store: ${storeDir}`,+ ` worktree: ${worktree}`,+ "pnpm cannot hardlink or clone across filesystems, so it copied every package into node_modules.",+ "Fix: put the store on the worktree's filesystem, for example:",+ ` pnpm config set store-dir ${JSON.stringify(NodePath.join(NodePath.dirname(worktree), ".pnpm-store"))} --global`,+ "",+ "",+ ].join("\n"),+ );+}// Env files live as real files in the main checkout; worktrees only get// symlinks to them. Only a symlink is ever replaced, so a real env file is