1// @effect-diagnostics nodeBuiltinImport:off - setup-script bootstrap, runs before any Effect runtime exists.
2/**
3 * Pre-warms Vite's dependency-optimizer cache (`node_modules/.vite/deps`) so
4 * the first `vp run dev` in a fresh worktree doesn't stall the initial page
5 * load on a full optimize pass. Run by the t3.json worktree setup script;
6 * safe to re-run — a valid cache makes this a fast no-op.
7 *
8 * The cache cannot be shared between worktrees: Vite's config hash includes
9 * the absolute project root, so each worktree must warm its own.
10 */
11import * as NodePath from "node:path";
12import * as NodeURL from "node:url";
13
14import { optimizeDeps, resolveConfig } from "vite";
15
16const webRoot = NodePath.dirname(NodePath.dirname(NodeURL.fileURLToPath(import.meta.url)));
17
18// logLevel "error" silences the "manually calling optimizeDeps is deprecated"
19// warning — deliberate here: warming ahead of the server is the whole point.
20const config = await resolveConfig({ root: webRoot, logLevel: "error" }, "serve");
21await optimizeDeps(config);
22console.log("[warm-dep-cache] web dependency cache is warm");