@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 03:37 UTC

main
ts 28 lines 1.21 KB
Raw
1 // @effect-diagnostics nodeBuiltinImport:off -- Runs before the CLI's Effect runtime loads.
2 import * as NodeFS from "node:fs";
3 import * as NodeModule from "node:module";
4 import * as NodeOS from "node:os";
5 import * as NodePath from "node:path";
6 import * as NodeSea from "node:sea";
7
8 export 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 }