-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.ts
More file actions
76 lines (66 loc) · 1.93 KB
/
Copy pathbuild.ts
File metadata and controls
76 lines (66 loc) · 1.93 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
#!/usr/bin/env bun
import { execSync } from 'node:child_process'
const entrypoints = [
'src/index.ts',
'src/claude/index.ts',
'src/opencode/index.ts',
'src/bin/haptic.ts',
'src/bin/haptic-hook.ts',
]
const result = await Bun.build({
entrypoints,
outdir: 'dist',
target: 'node',
format: 'esm',
splitting: true,
sourcemap: 'linked',
external: ['*.node'],
})
if (!result.success) {
console.error('Build failed:')
for (const log of result.logs) {
console.error(log)
}
process.exit(1)
}
const createRequireBanner = `import { createRequire } from 'module'; const require = createRequire(import.meta.url);\n`
for (const output of result.outputs) {
if (output.path.endsWith('.js')) {
let content = await output.text()
const needsRequire = content.includes('require(') && !content.includes('createRequire')
if (needsRequire) {
content = createRequireBanner + content
}
// Fix Bun's duplicate export bug - remove the second export statement with exports_*
content = content.replace(/^export \{ [^}]+, exports_\w+ \};$/m, '')
await Bun.write(output.path, content)
}
}
execSync('bunx tsc --emitDeclarationOnly --declaration --outDir dist', { stdio: 'inherit' })
// Bundle hook for Claude Code marketplace (committed to git)
const hookResult = await Bun.build({
entrypoints: ['src/bin/haptic-hook.ts'],
outdir: 'hooks',
target: 'node',
format: 'esm',
splitting: false,
minify: false,
external: [],
})
if (!hookResult.success) {
console.error('Hook bundle failed:')
for (const log of hookResult.logs) {
console.error(log)
}
process.exit(1)
}
for (const output of hookResult.outputs) {
if (output.path.endsWith('.js')) {
let content = await output.text()
if (content.includes('require(') && !content.includes('createRequire')) {
content = createRequireBanner + content
}
await Bun.write(output.path, content)
}
}
console.log('Build completed successfully!')