Skip to content

Commit 618761a

Browse files
t3dotggclaude
andauthored
build(setup): leaner installs on Mac and Linux, cross-device store warning, setup-done marker (#22718)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent ea1c494 commit 618761a

5 files changed

Lines changed: 107 additions & 9 deletions

File tree

‎.pnpmfile.cjs‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Windows WSL dev mode runs the server under Linux from the same node_modules
2+
// as the Windows client, so Windows installs also need Linux x64 glibc native
3+
// modules. Other platforms install only their own binaries; setting this
4+
// everywhere added ~2.2 GB of foreign binaries to every macOS install.
5+
// Release scripts stage their own installs with explicit architectures.
6+
module.exports = {
7+
hooks: {
8+
updateConfig(config) {
9+
// oxlint-disable-next-line t3code/no-global-process-runtime -- pnpm loads this file before any Effect runtime exists.
10+
if (process.platform !== "win32") return config;
11+
return {
12+
...config,
13+
supportedArchitectures: {
14+
os: ["current", "linux"],
15+
cpu: ["current", "x64"],
16+
libc: ["current", "glibc"],
17+
},
18+
};
19+
},
20+
},
21+
};

‎AGENTS.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ The most common defect in this repo is a change that works on the path you teste
7878
## Dev servers
7979

8080
- `vp i` installs. Worktrees get this from the t3.json setup script; if module resolution looks broken, it probably did not run.
81+
- 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.
8182
- `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.
8283
- 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.
8384
- 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.

‎pnpm-lock.yaml‎

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎pnpm-workspace.yaml‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,3 @@ peerDependencyRules:
373373
# pnpm keeps optional deps inside the virtual store, so hoist it to the root.
374374
publicHoistPattern:
375375
- "@cursor/sdk-*"
376-
377-
supportedArchitectures:
378-
cpu: [current, x64]
379-
libc: [current, glibc]
380-
os: [current, linux]

‎scripts/setup-worktree.ts‎

Lines changed: 83 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,102 @@ import * as NodePath from "node:path";
55

66
const ENV_FILES = [".env", NodePath.join("infra", "relay", ".env")];
77

8+
const worktree = NodePath.dirname(import.meta.dirname);
9+
10+
// T3 runs setup in the background, so agents can start before it ends.
11+
// `setup-running` holds this PID until setup ends with `setup-done` or
12+
// `setup-failed`, so agents wait instead of racing it with their own `vp i`.
13+
const markerDir = NodePath.join(worktree, ".t3");
14+
const runningMarker = NodePath.join(markerDir, "setup-running");
15+
const doneMarker = NodePath.join(markerDir, "setup-done");
16+
const failedMarker = NodePath.join(markerDir, "setup-failed");
17+
NodeFS.rmSync(doneMarker, { force: true });
18+
NodeFS.rmSync(failedMarker, { force: true });
19+
NodeFS.mkdirSync(markerDir, { recursive: true });
20+
NodeFS.writeFileSync(runningMarker, `${process.pid}\n`);
21+
let failureDetail = "";
22+
process.on("uncaughtExceptionMonitor", (error) => {
23+
failureDetail = error.stack ?? String(error);
24+
});
25+
process.on("exit", (code) => {
26+
if (code === 0) NodeFS.writeFileSync(doneMarker, "");
27+
else NodeFS.writeFileSync(failedMarker, `Setup exited with code ${code}.\n${failureDetail}\n`);
28+
NodeFS.rmSync(runningMarker, { force: true });
29+
});
30+
// A cancelled setup must still leave a marker, or agents would wait forever.
31+
// During install, the signal goes on to the installer and setup exits when the
32+
// install output closes. Any child the shell leaves behind holds that output
33+
// open, so no marker appears while `vp i` can still write node_modules.
34+
let cancelSignal: NodeJS.Signals | undefined;
35+
let activeInstall: NodeChildProcess.ChildProcess | undefined;
36+
for (const signal of ["SIGINT", "SIGTERM", "SIGHUP"] as const) {
37+
process.on(signal, () => {
38+
cancelSignal = signal;
39+
if (activeInstall) activeInstall.kill(signal);
40+
else process.exit(1);
41+
});
42+
}
43+
844
const projectRoot = process.env.T3CODE_PROJECT_ROOT;
945
if (!projectRoot) {
1046
throw new Error("T3CODE_PROJECT_ROOT is not set. Run this through the t3.json setup action.");
1147
}
12-
const worktree = NodePath.dirname(import.meta.dirname);
1348

1449
// `shell` resolves `vp` through PATH, including Windows command shims.
1550
// Setup has no one answering install prompts. Pass pnpm's confirmation flag
1651
// through vp and leave stdin closed so other prompts fail instead of hanging.
1752
// Install exactly the locked dependencies so setup never rewrites the lockfile.
1853
// A stale lockfile must fail setup rather than silently resolving a new one.
19-
const install = NodeChildProcess.spawnSync("vp i --frozen-lockfile -- --yes", {
54+
// Output is piped, not inherited, so a failure can keep its tail in the marker.
55+
const install = NodeChildProcess.spawn("vp i --frozen-lockfile -- --yes", {
2056
cwd: worktree,
2157
shell: true,
22-
stdio: ["ignore", "inherit", "inherit"],
58+
stdio: ["ignore", "pipe", "pipe"],
2359
});
24-
if (install.status !== 0) process.exit(install.status ?? 1);
60+
activeInstall = install;
61+
let installOutput = "";
62+
for (const [source, target] of [
63+
[install.stdout, process.stdout],
64+
[install.stderr, process.stderr],
65+
] as const) {
66+
source.setEncoding("utf8");
67+
source.on("data", (chunk: string) => {
68+
target.write(chunk);
69+
installOutput = (installOutput + chunk).slice(-8_000);
70+
});
71+
}
72+
const installStatus = await new Promise<number | null>((resolve) => install.on("close", resolve));
73+
activeInstall = undefined;
74+
if (installStatus !== 0 || cancelSignal) {
75+
failureDetail = cancelSignal
76+
? `Cancelled by ${cancelSignal}.`
77+
: installOutput.trimEnd().split("\n").slice(-30).join("\n");
78+
process.exit(installStatus || 1);
79+
}
80+
81+
// pnpm cannot clone or hardlink across filesystems, so a store on another
82+
// device silently turns every worktree install into a full copy.
83+
const storeDir: unknown = JSON.parse(
84+
NodeFS.readFileSync(NodePath.join(worktree, "node_modules", ".modules.yaml"), "utf8"),
85+
).storeDir;
86+
if (
87+
typeof storeDir === "string" &&
88+
NodeFS.statSync(storeDir).dev !== NodeFS.statSync(NodePath.join(worktree, "node_modules")).dev
89+
) {
90+
process.stderr.write(
91+
[
92+
"",
93+
"WARNING: the pnpm store is on a different filesystem than this worktree.",
94+
` store: ${storeDir}`,
95+
` worktree: ${worktree}`,
96+
"pnpm cannot hardlink or clone across filesystems, so it copied every package into node_modules.",
97+
"Fix: put the store on the worktree's filesystem, for example:",
98+
` pnpm config set store-dir ${JSON.stringify(NodePath.join(NodePath.dirname(worktree), ".pnpm-store"))} --global`,
99+
"",
100+
"",
101+
].join("\n"),
102+
);
103+
}
25104

26105
// Env files live as real files in the main checkout; worktrees only get
27106
// symlinks to them. Only a symlink is ever replaced, so a real env file is

0 commit comments

Comments
 (0)