Open History to see the last commit
1// @effect-diagnostics nodeBuiltinImport:off -- Runs before the CLI's Effect runtime loads.
2import * as NodeFS from "node:fs";
3import * as NodeModule from "node:module";
4import * as NodeOS from "node:os";
5import * as NodePath from "node:path";
6import * as NodeSea from "node:sea";
7
8export function enableCliCompileCache(): void {
9 try {
10 // SEA has no separate modules to cache.
11 if (NodeSea.isSea()) return;
12 const cacheRoot =
13 process.env.XDG_CACHE_HOME ||
14 // oxlint-disable-next-line t3code/no-global-process-runtime -- Runs before the CLI's Effect runtime loads.
15 (process.platform === "linux" ? NodePath.join(NodeOS.homedir(), ".cache") : NodeOS.tmpdir());
16 const directory = NodePath.join(cacheRoot, "t3code", "compile-cache");
17 if (process.env.APPIMAGE) {
18 // AppImage paths change each launch. Older shims cached anyway, filling Node's engine folders.
19 for (const entry of NodeFS.readdirSync(directory, { withFileTypes: true })) {
20 if (entry.isDirectory() && /^v\d/.test(entry.name)) {
21 NodeFS.rmSync(NodePath.join(directory, entry.name), { recursive: true, force: true });
22 }
23 }
24 return;
25 }
26 NodeModule.enableCompileCache(directory);
27 } catch {}
28}