-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathbuild.ts
More file actions
97 lines (87 loc) · 2.82 KB
/
Copy pathbuild.ts
File metadata and controls
97 lines (87 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/**
* Daemon build script — dual-runtime: Bun.build under Bun, esbuild under Node.
* Aliases native packages that break when bundled (baked paths to .node/.wasm binaries).
*/
const EXTERNAL_BUN = ["better-sqlite3", "@1password/sdk", "onnxruntime-node", "@huggingface/transformers"];
const EXTERNAL_NODE = [
"better-sqlite3",
"bun",
"bun:sqlite",
"@1password/sdk",
"libsodium-wrappers",
"onnxruntime-node",
"@huggingface/transformers",
];
const ALIAS: Record<string, string> = {
sharp: "./src/shims/sharp.ts",
};
const targets: Array<{
entrypoint: string;
outfile: string;
}> = [
{ entrypoint: "./src/daemon.ts", outfile: "./dist/daemon.js" },
{ entrypoint: "./src/mcp-stdio.ts", outfile: "./dist/mcp-stdio.js" },
{ entrypoint: "./src/index.ts", outfile: "./dist/index.js" },
{ entrypoint: "./src/synthesis-render-worker.ts", outfile: "./dist/synthesis-render-worker.js" },
{ entrypoint: "./src/database-integrity-worker.ts", outfile: "./dist/database-integrity-worker.js" },
{ entrypoint: "./src/db-owner-worker.ts", outfile: "./dist/db-owner-worker.js" },
{ entrypoint: "./src/native-memory-source-worker.ts", outfile: "./dist/native-memory-source-worker.js" },
{ entrypoint: "./src/pipeline/dreaming-token-worker.ts", outfile: "./dist/dreaming-token-worker.js" },
{ entrypoint: "./src/transcript-recovery-child.ts", outfile: "./dist/transcript-recovery-child.js" },
];
const forceNodeBuild = process.env.FORCE_NODE_BUILD === "1";
const isBun = typeof Bun !== "undefined" && !forceNodeBuild;
let ok = true;
if (isBun) {
for (const { entrypoint, outfile } of targets) {
const result = await Bun.build({
entrypoints: [entrypoint],
outdir: ".",
naming: outfile,
target: "bun",
format: "esm",
external: EXTERNAL_BUN,
alias: ALIAS,
});
if (!result.success) {
console.error(`Build failed: ${entrypoint}`);
for (const log of result.logs) {
console.error(log);
}
ok = false;
} else {
const size = result.outputs[0]?.size ?? 0;
const mb = (size / 1024 / 1024).toFixed(1);
console.log(` ${outfile} ${mb} MB`);
}
}
} else {
const { build } = await import("esbuild");
for (const { entrypoint, outfile } of targets) {
try {
await build({
entryPoints: [entrypoint],
bundle: true,
outfile,
platform: "node",
target: "node20",
external: EXTERNAL_NODE,
alias: ALIAS,
format: "esm",
banner: {
js: 'import { createRequire as __createRequire } from "module"; const require = __createRequire(import.meta.url);',
},
logLevel: "warning",
});
const { statSync } = await import("node:fs");
const size = statSync(outfile).size;
const mb = (size / 1024 / 1024).toFixed(1);
console.log(` ${outfile} ${mb} MB`);
} catch (err) {
console.error(`Build failed: ${entrypoint}`);
console.error(err);
ok = false;
}
}
}
if (!ok) process.exit(1);