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

main
ts 49 lines 2.05 KB
Raw
1 // @effect-diagnostics nodeBuiltinImport:off
2 import * as NodeFSP from "node:fs/promises";
3 import * as NodeModule from "node:module";
4 import * as NodePath from "node:path";
5
6 import { scanGlibcNeeds } from "./linux-glibc.ts";
7
8 const prepareServerCompileCache: (context: AfterPackContext) => Promise<void> =
9 NodeModule.createRequire(import.meta.url)("./prepare-server-compile-cache.cjs");
10
11 interface AfterPackContext {
12 readonly appOutDir: string;
13 readonly electronPlatformName: string;
14 readonly targets: ReadonlyArray<{
15 readonly name: string;
16 readonly options?: { depends?: string | string[] } | null;
17 }>;
18 }
19
20 // Electron's Linux zips can ship world-writable files (44.10.0 has 0777 binaries), and
21 // electron-builder copies zip modes verbatim into the .deb and AppImage.
22 export default async function afterPack(context: AfterPackContext): Promise<void> {
23 await prepareServerCompileCache(context);
24 await removeSharedWriteAccess(context.appOutDir);
25 const { minimum } = await scanGlibcNeeds(context.appOutDir);
26 for (const target of context.targets) {
27 if (target.name !== "deb") continue;
28 if (!target.options || !Array.isArray(target.options.depends)) {
29 throw new Error("Linux deb target must configure its dependencies before afterPack");
30 }
31 // FPM snapshots config when targets are created; update the target's resolved options.
32 // Targets are shared across arches, so replace any entry an earlier arch added.
33 target.options.depends = [
34 ...target.options.depends.filter((dependency) => !dependency.startsWith("libc6 ")),
35 `libc6 (>= ${minimum})`,
36 ];
37 }
38 }
39
40 // Walks by hand: recursive readdir follows directory symlinks out of the app folder.
41 export async function removeSharedWriteAccess(path: string): Promise<void> {
42 const stats = await NodeFSP.lstat(path);
43 if (stats.isSymbolicLink()) return;
44 if (stats.mode & 0o022) await NodeFSP.chmod(path, stats.mode & 0o7755);
45 if (!stats.isDirectory()) return;
46 for (const entry of await NodeFSP.readdir(path)) {
47 await removeSharedWriteAccess(NodePath.join(path, entry));
48 }
49 }