-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathesbuild.config.mjs
More file actions
142 lines (127 loc) · 5.52 KB
/
esbuild.config.mjs
File metadata and controls
142 lines (127 loc) · 5.52 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import { build } from "esbuild";
import { chmodSync, writeFileSync, readFileSync } from "node:fs";
const esmPackageJson = '{"type":"module"}\n';
const hivemindVersion = JSON.parse(readFileSync("package.json", "utf-8")).version;
const openclawVersion = JSON.parse(readFileSync("openclaw/package.json", "utf-8")).version;
const openclawSkillBody = readFileSync("openclaw/skills/SKILL.md", "utf-8");
// Claude Code plugin
const ccHooks = [
{ entry: "dist/src/hooks/session-start.js", out: "session-start" },
{ entry: "dist/src/hooks/session-start-setup.js", out: "session-start-setup" },
{ entry: "dist/src/hooks/capture.js", out: "capture" },
{ entry: "dist/src/hooks/pre-tool-use.js", out: "pre-tool-use" },
{ entry: "dist/src/hooks/session-end.js", out: "session-end" },
{ entry: "dist/src/hooks/plugin-cache-gc.js", out: "plugin-cache-gc" },
{ entry: "dist/src/hooks/wiki-worker.js", out: "wiki-worker" },
];
const ccShell = [
{ entry: "dist/src/shell/deeplake-shell.js", out: "shell/deeplake-shell" },
];
const ccCommands = [
{ entry: "dist/src/commands/auth-login.js", out: "commands/auth-login" },
];
const ccAll = [...ccHooks, ...ccShell, ...ccCommands];
await build({
entryPoints: Object.fromEntries(ccAll.map(h => [h.out, h.entry])),
bundle: true,
platform: "node",
format: "esm",
outdir: "claude-code/bundle",
external: ["node:*", "node-liblzma", "@mongodb-js/zstd"],
define: {
__HIVEMIND_VERSION__: JSON.stringify(hivemindVersion),
},
});
for (const h of ccAll) {
chmodSync(`claude-code/bundle/${h.out}.js`, 0o755);
}
writeFileSync("claude-code/bundle/package.json", esmPackageJson);
// Codex plugin
const codexHooks = [
{ entry: "dist/src/hooks/codex/session-start.js", out: "session-start" },
{ entry: "dist/src/hooks/codex/session-start-setup.js", out: "session-start-setup" },
{ entry: "dist/src/hooks/codex/capture.js", out: "capture" },
{ entry: "dist/src/hooks/codex/pre-tool-use.js", out: "pre-tool-use" },
{ entry: "dist/src/hooks/codex/stop.js", out: "stop" },
{ entry: "dist/src/hooks/codex/wiki-worker.js", out: "wiki-worker" },
];
const codexShell = [
{ entry: "dist/src/shell/deeplake-shell.js", out: "shell/deeplake-shell" },
];
const codexCommands = [
{ entry: "dist/src/commands/auth-login.js", out: "commands/auth-login" },
];
const codexAll = [...codexHooks, ...codexShell, ...codexCommands];
await build({
entryPoints: Object.fromEntries(codexAll.map(h => [h.out, h.entry])),
bundle: true,
platform: "node",
format: "esm",
outdir: "codex/bundle",
external: ["node:*", "node-liblzma", "@mongodb-js/zstd"],
define: {
__HIVEMIND_VERSION__: JSON.stringify(hivemindVersion),
},
});
for (const h of codexAll) {
chmodSync(`codex/bundle/${h.out}.js`, 0o755);
}
writeFileSync("codex/bundle/package.json", esmPackageJson);
// OpenClaw plugin bundle. The shared CC/Codex source modules reference a
// handful of HIVEMIND_* env vars for dev-only overrides. Those env paths are
// never taken in the openclaw runtime (the plugin loads config from
// pluginApi.pluginConfig + ~/.deeplake/credentials.json), so we replace them
// with `undefined` at build time to avoid shipping dead env-read code in the
// plugin bundle.
await build({
entryPoints: { index: "openclaw/src/index.ts" },
bundle: true,
splitting: true,
chunkNames: "chunks/[name]-[hash]",
platform: "node",
format: "esm",
outdir: "openclaw/dist",
external: ["node:*"],
define: {
__HIVEMIND_VERSION__: JSON.stringify(openclawVersion),
__HIVEMIND_SKILL__: JSON.stringify(openclawSkillBody),
"process.env.HIVEMIND_TOKEN": "undefined",
"process.env.HIVEMIND_ORG_ID": "undefined",
"process.env.HIVEMIND_WORKSPACE_ID": "undefined",
"process.env.HIVEMIND_API_URL": "undefined",
"process.env.HIVEMIND_TABLE": "undefined",
"process.env.HIVEMIND_SESSIONS_TABLE": "undefined",
"process.env.HIVEMIND_MEMORY_PATH": "undefined",
"process.env.HIVEMIND_DEBUG": "undefined",
"process.env.HIVEMIND_CAPTURE": "undefined",
"process.env.HIVEMIND_TRACE_SQL": "undefined",
"process.env.HIVEMIND_QUERY_TIMEOUT_MS": "undefined",
"process.env.HIVEMIND_INDEX_MARKER_TTL_MS": "undefined",
"process.env.HIVEMIND_INDEX_MARKER_DIR": "undefined",
},
plugins: [{
// Dead-code elimination for transitively bundled CC/Codex-only features.
// openclaw/src/index.ts imports shared modules from ../../src/ (DeeplakeApi,
// grep-core, virtual-table-query, auth device-flow). Several of those
// modules also host CC-specific helpers that shell out with execSync —
// opening the browser for SSO, nudging claude-plugin-update, spawning the
// wiki-worker daemon. Those helpers are never called through the openclaw
// entry point (openclaw is a pure HTTP/WebSocket gateway; it has no local
// browser, uses its own plugin installer, and does not run the wiki-worker
// daemon). Replacing node:child_process with a no-op export drops that
// dead code from the bundle instead of shipping unreachable exec calls.
name: "stub-unused-child-process",
setup(build) {
build.onResolve({ filter: /^node:child_process$/ }, () => ({
path: "node:child_process",
namespace: "stub",
}));
build.onLoad({ filter: /.*/, namespace: "stub" }, () => ({
contents: "export const execSync = () => {}; export const execFileSync = () => {}; export const spawn = () => {};",
loader: "js",
}));
},
}],
});
writeFileSync("openclaw/dist/package.json", esmPackageJson);
console.log(`Built: ${ccAll.length} CC + ${codexAll.length} Codex + 1 OpenClaw bundles`);