Open History to see the last commit
1// @effect-diagnostics nodeBuiltinImport:off - runs before `vp i`, so only Node built-ins exist.
2import * as NodeChildProcess from "node:child_process";
3import * as NodeFS from "node:fs";
4import * as NodePath from "node:path";
5
6const ENV_FILES = [".env", NodePath.join("infra", "relay", ".env")];
7
8const projectRoot = process.env.T3CODE_PROJECT_ROOT;
9if (!projectRoot) {
10 throw new Error("T3CODE_PROJECT_ROOT is not set. Run this through the t3.json setup action.");
11}
12const worktree = NodePath.dirname(import.meta.dirname);
13
14// `shell` resolves `vp` through PATH, including Windows command shims.
15// Setup has no one answering install prompts. Pass pnpm's confirmation flag
16// through vp and leave stdin closed so other prompts fail instead of hanging.
17// Install exactly the locked dependencies so setup never rewrites the lockfile.
18// A stale lockfile must fail setup rather than silently resolving a new one.
19const install = NodeChildProcess.spawnSync("vp i --frozen-lockfile -- --yes", {
20 cwd: worktree,
21 shell: true,
22 stdio: ["ignore", "inherit", "inherit"],
23});
24if (install.status !== 0) process.exit(install.status ?? 1);
25
26// Env files live as real files in the main checkout; worktrees only get
27// symlinks to them. Only a symlink is ever replaced, so a real env file is
28// never deleted, including when this runs in the main checkout itself.
29for (const file of ENV_FILES) {
30 const source = NodePath.join(projectRoot, file);
31 const sourceStat = NodeFS.lstatSync(source, { throwIfNoEntry: false });
32 if (!sourceStat) continue;
33 if (!sourceStat.isFile()) {
34 process.stderr.write(`Skipping ${file}: ${source} is not a regular file.\n`);
35 continue;
36 }
37 const target = NodePath.join(worktree, file);
38 const existing = NodeFS.lstatSync(target, { throwIfNoEntry: false });
39 if (existing && !existing.isSymbolicLink()) continue;
40 if (existing) NodeFS.rmSync(target);
41 NodeFS.symlinkSync(source, target);
42}
43
44const warm = NodeChildProcess.spawnSync(
45 process.execPath,
46 [NodePath.join(worktree, "apps", "web", "scripts", "warm-dep-cache.ts")],
47 { cwd: worktree, stdio: "inherit" },
48);
49process.exit(warm.status ?? 1);