Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

cliCompileCache.ts

25 lines1.1 KB

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";
6​
7export function enableCliCompileCache(): void {
8 try {
9 const cacheRoot =
10 process.env.XDG_CACHE_HOME ||
11 // oxlint-disable-next-line t3code/no-global-process-runtime -- Runs before the CLI's Effect runtime loads.
12 (process.platform === "linux" ? NodePath.join(NodeOS.homedir(), ".cache") : NodeOS.tmpdir());
13 const directory = NodePath.join(cacheRoot, "t3code", "compile-cache");
14 if (process.env.APPIMAGE) {
15 // AppImage paths change each launch. Older shims cached anyway, filling Node's engine folders.
16 for (const entry of NodeFS.readdirSync(directory, { withFileTypes: true })) {
17 if (entry.isDirectory() && /^v\d/.test(entry.name)) {
18 NodeFS.rmSync(NodePath.join(directory, entry.name), { recursive: true, force: true });
19 }
20 }
21 return;
22 }
23 NodeModule.enableCompileCache(directory);
24 } catch {}