| 1 | // @effect-diagnostics nodeBuiltinImport:off |
| 2 | // Runs before any Effect runtime exists, so it stays on Node built-ins. |
| 3 | import * as NodeModule from "node:module"; |
| 4 | import * as NodeOS from "node:os"; |
| 5 | import * as NodePath from "node:path"; |
| 6 | |
| 7 | // Turns on Node's on-disk V8 code cache for every module loaded after this one, |
| 8 | // so later launches skip recompiling the large main and server bundles. |
| 9 | // Packaged builds only: boot.ts loads it for the main process, and the local |
| 10 | // backend gets it with `--require`. Dev launches main.cjs directly and skips it. |
| 11 | // Linux uses the user's cache dir because /tmp is shared between users; the |
| 12 | // macOS and Windows temp dirs are already per user. |
| 13 | // |
| 14 | // Skipped under AppImage: it mounts the app at a new /tmp/.mount_* path each |
| 15 | // launch, and Node keys entries by path, so every launch would miss and leave |
| 16 | // another copy behind. The backend inherits APPIMAGE, so this covers it too. |
| 17 | try { |
| 18 | if (!process.env.APPIMAGE) { |
| 19 | const cacheRoot = |
| 20 | // oxlint-disable-next-line t3code/no-global-process-runtime -- Loads before any Effect runtime. |
| 21 | process.platform === "linux" |
| 22 | ? process.env.XDG_CACHE_HOME || NodePath.join(NodeOS.homedir(), ".cache") |
| 23 | : NodeOS.tmpdir(); |
| 24 | NodeModule.enableCompileCache(NodePath.join(cacheRoot, "t3code", "compile-cache")); |
| 25 | } |
| 26 | } catch { |
| 27 | // The cache is only a speedup. Never let it stop the app from starting. |
| 28 | } |