-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathesbuild.config.mjs
More file actions
50 lines (43 loc) · 1.36 KB
/
Copy pathesbuild.config.mjs
File metadata and controls
50 lines (43 loc) · 1.36 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
import { build } from 'esbuild';
import { chmod, mkdir, readFile } from 'node:fs/promises';
const outfile = 'dist/cli.js';
await mkdir('dist', { recursive: true });
const pkg = JSON.parse(await readFile('package.json', 'utf8'));
const sharedBuild = {
bundle: true,
platform: 'node',
target: 'node20',
format: 'esm',
banner: {
js: [
'#!/usr/bin/env node',
// Polyfill `require` for CJS deps (commander, pino, js-yaml) bundled
// into ESM output — esbuild's dynamic-require shim otherwise throws.
"import { createRequire as __createRequire } from 'node:module';",
'const require = __createRequire(import.meta.url);',
].join('\n'),
},
define: {
// Build-time version injection — `agent-tree --version` reads this.
// Avoids runtime require('../package.json') path-resolution differences
// between `tsx src/cli.ts` (source) and `node dist/cli.js` (bundle).
__PKG_VERSION__: JSON.stringify(pkg.version),
},
sourcemap: true,
external: ['@anthropic-ai/sdk'],
logLevel: 'info',
};
await build({
...sharedBuild,
entryPoints: ['src/cli.ts'],
outfile,
});
await chmod(outfile, 0o755);
const mcpOutfile = 'dist/mcp-server.js';
await build({
...sharedBuild,
entryPoints: ['src/mcp/server.ts'],
outfile: mcpOutfile,
});
await chmod(mcpOutfile, 0o755);
console.log(`✔ built ${outfile} + ${mcpOutfile}`);