Open History to see the last commit
1// @effect-diagnostics nodeBuiltinImport:off - runs before `vp i`, so only Node built-ins exist.
2/**
3 * Worktree setup, run by the t3.json "Setup Worktree" action as
4 * `node scripts/setup-worktree.ts`. Plain Node keeps one command working in
5 * every shell T3 Code spawns (zsh, bash, fish, PowerShell): it installs
6 * dependencies, links the main checkout's gitignored env files into this
7 * worktree, then warms the web dependency cache.
8 */
9import * as NodeChildProcess from "node:child_process";
10import * as NodeFS from "node:fs";
11import * as NodePath from "node:path";
12
13const ENV_FILES = [".env", NodePath.join("infra", "relay", ".env")];
14
15const projectRoot = process.env.T3CODE_PROJECT_ROOT;
16if (!projectRoot) {
17 throw new Error("T3CODE_PROJECT_ROOT is not set. Run this through the t3.json setup action.");
18}
19const worktree = NodePath.dirname(import.meta.dirname);
20
21// `shell` resolves `vp` through PATH, including Windows command shims.
22const install = NodeChildProcess.spawnSync("vp i", {
23 cwd: worktree,
24 shell: true,
25 stdio: "inherit",
26});
27if (install.status !== 0) process.exit(install.status ?? 1);
28
29// In the main checkout itself, relinking would replace the real env files.
30if (NodeFS.realpathSync(projectRoot) !== NodeFS.realpathSync(worktree)) {
31 for (const file of ENV_FILES) {
32 const source = NodePath.join(projectRoot, file);
33 if (!NodeFS.existsSync(source)) continue;
34 const target = NodePath.join(worktree, file);
35 NodeFS.rmSync(target, { force: true });
36 NodeFS.symlinkSync(source, target);
37 }
38}
39
40const warm = NodeChildProcess.spawnSync(
41 process.execPath,
42 [NodePath.join(worktree, "apps", "web", "scripts", "warm-dep-cache.ts")],
43 { cwd: worktree, stdio: "inherit" },
44);
45process.exit(warm.status ?? 1);