generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathesbuild.config.mjs
More file actions
104 lines (95 loc) · 3.56 KB
/
esbuild.config.mjs
File metadata and controls
104 lines (95 loc) · 3.56 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
import * as esbuild from 'esbuild';
import * as fs from 'fs';
import { createRequire } from 'module';
// Stub plugin for optional dev dependencies
const optionalDepsPlugin = {
name: 'optional-deps',
setup(build) {
// Stub react-devtools-core (only used when DEV=true)
build.onResolve({ filter: /^react-devtools-core$/ }, () => ({
path: 'react-devtools-core',
namespace: 'optional-stub',
}));
build.onLoad({ filter: /.*/, namespace: 'optional-stub' }, () => ({
contents: `export default { initialize: () => {}, connectToDevTools: () => {} };`,
loader: 'js',
}));
},
};
// Text loader plugin for embedding files
const textLoaderPlugin = {
name: 'text-loader',
setup(build) {
// Handle .md and .txt files as text
build.onLoad({ filter: /\.(md|txt)$/ }, async args => {
const text = await fs.promises.readFile(args.path, 'utf8');
return {
contents: `export default ${JSON.stringify(text)};`,
loader: 'js',
};
});
// Handle .ts files in llm-compacted as text
build.onLoad({ filter: /llm-compacted[/\\].*\.ts$/ }, async args => {
const text = await fs.promises.readFile(args.path, 'utf8');
return {
contents: `export default ${JSON.stringify(text)};`,
loader: 'js',
};
});
},
};
await esbuild.build({
entryPoints: ['./src/cli/index.ts'],
outfile: './dist/cli/index.mjs',
bundle: true,
platform: 'node',
format: 'esm',
minify: true,
// Inject require shim for ESM compatibility with CommonJS dependencies
banner: {
js: `import { createRequire } from 'module'; const require = createRequire(import.meta.url);`,
},
external: ['fsevents', '@aws-cdk/toolkit-lib'],
plugins: [optionalDepsPlugin, textLoaderPlugin],
});
// Make executable
fs.chmodSync('./dist/cli/index.mjs', '755');
console.log('CLI build complete: dist/cli/index.mjs');
// ---------------------------------------------------------------------------
// MCP harness build — opt-in via BUILD_HARNESS=1
//
// The TUI harness is dev-only tooling for AI agents and integration tests.
// It is NOT shipped to end users. Build it separately with:
// BUILD_HARNESS=1 node esbuild.config.mjs
// npm run build:harness
// ---------------------------------------------------------------------------
const mcpEntryPoint = './src/tui-harness/mcp/index.ts';
if (process.env.BUILD_HARNESS === '1' && fs.existsSync(mcpEntryPoint)) {
await esbuild.build({
entryPoints: [mcpEntryPoint],
outfile: './dist/mcp-harness/index.mjs',
bundle: true,
platform: 'node',
format: 'esm',
minify: true,
banner: {
js: [
'#!/usr/bin/env node',
`import { createRequire } from 'module'; const require = createRequire(import.meta.url);`,
].join('\n'),
},
// node-pty is a native C++ addon and cannot be bundled.
// @xterm/headless is CJS-only (no ESM exports map) — esbuild's CJS-to-ESM
// conversion mangles its default export at runtime, so let Node handle it.
// fsevents is macOS-only optional native module.
// express is CJS-heavy (deeply nested require chains) — let Node.js resolve
// it at runtime from node_modules instead of bundling.
external: ['fsevents', 'node-pty', '@xterm/headless', 'express'],
plugins: [textLoaderPlugin],
});
// Make executable
fs.chmodSync('./dist/mcp-harness/index.mjs', '755');
console.log('MCP harness build complete: dist/mcp-harness/index.mjs');
} else if (process.env.BUILD_HARNESS === '1') {
console.log(`MCP harness build skipped: entry point ${mcpEntryPoint} does not exist yet`);
}