@@ -2,62 +2,62 @@ import { readdir, readFile, writeFile, cp } from "fs/promises";
22import { join } from "path" ;
33import { getMacroDefines } from "./scripts/defines.ts" ;
44
5- const outdir = " dist" ;
5+ const outdir = ' dist'
66
77// Step 1: Clean output directory
8- const { rmSync } = await import ( "fs" ) ;
9- rmSync ( outdir , { recursive : true , force : true } ) ;
8+ const { rmSync } = await import ( 'fs' )
9+ rmSync ( outdir , { recursive : true , force : true } )
1010
1111// Default features that match the official CLI build.
1212// Additional features can be enabled via FEATURE_<NAME>=1 env vars.
1313const DEFAULT_BUILD_FEATURES = [ "AGENT_TRIGGERS_REMOTE" , "CHICAGO_MCP" , "VOICE_MODE" ] ;
1414
1515// Collect FEATURE_* env vars → Bun.build features
1616const envFeatures = Object . keys ( process . env )
17- . filter ( k => k . startsWith ( " FEATURE_" ) )
18- . map ( k => k . replace ( " FEATURE_" , "" ) ) ;
19- const features = [ ...new Set ( [ ...DEFAULT_BUILD_FEATURES , ...envFeatures ] ) ] ;
17+ . filter ( k => k . startsWith ( ' FEATURE_' ) )
18+ . map ( k => k . replace ( ' FEATURE_' , '' ) )
19+ const features = [ ...new Set ( [ ...DEFAULT_BUILD_FEATURES , ...envFeatures ] ) ]
2020
2121// Step 2: Bundle with splitting
2222const result = await Bun . build ( {
23- entrypoints : [ " src/entrypoints/cli.tsx" ] ,
24- outdir,
25- target : " bun" ,
26- splitting : true ,
27- define : getMacroDefines ( ) ,
28- features,
29- } ) ;
23+ entrypoints : [ ' src/entrypoints/cli.tsx' ] ,
24+ outdir,
25+ target : ' bun' ,
26+ splitting : true ,
27+ define : getMacroDefines ( ) ,
28+ features,
29+ } )
3030
3131if ( ! result . success ) {
32- console . error ( " Build failed:" ) ;
33- for ( const log of result . logs ) {
34- console . error ( log ) ;
35- }
36- process . exit ( 1 ) ;
32+ console . error ( ' Build failed:' )
33+ for ( const log of result . logs ) {
34+ console . error ( log )
35+ }
36+ process . exit ( 1 )
3737}
3838
3939// Step 3: Post-process — replace Bun-only `import.meta.require` with Node.js compatible version
40- const files = await readdir ( outdir ) ;
41- const IMPORT_META_REQUIRE = " var __require = import.meta.require;" ;
42- const COMPAT_REQUIRE = `var __require = typeof import.meta.require === "function" ? import.meta.require : (await import("module")).createRequire(import.meta.url);` ;
40+ const files = await readdir ( outdir )
41+ const IMPORT_META_REQUIRE = ' var __require = import.meta.require;'
42+ const COMPAT_REQUIRE = `var __require = typeof import.meta.require === "function" ? import.meta.require : (await import("module")).createRequire(import.meta.url);`
4343
44- let patched = 0 ;
44+ let patched = 0
4545for ( const file of files ) {
46- if ( ! file . endsWith ( " .js" ) ) continue ;
47- const filePath = join ( outdir , file ) ;
48- const content = await readFile ( filePath , " utf-8" ) ;
49- if ( content . includes ( IMPORT_META_REQUIRE ) ) {
50- await writeFile (
51- filePath ,
52- content . replace ( IMPORT_META_REQUIRE , COMPAT_REQUIRE ) ,
53- ) ;
54- patched ++ ;
55- }
46+ if ( ! file . endsWith ( ' .js' ) ) continue
47+ const filePath = join ( outdir , file )
48+ const content = await readFile ( filePath , ' utf-8' )
49+ if ( content . includes ( IMPORT_META_REQUIRE ) ) {
50+ await writeFile (
51+ filePath ,
52+ content . replace ( IMPORT_META_REQUIRE , COMPAT_REQUIRE ) ,
53+ )
54+ patched ++
55+ }
5656}
5757
5858console . log (
59- `Bundled ${ result . outputs . length } files to ${ outdir } / (patched ${ patched } for Node.js compat)` ,
60- ) ;
59+ `Bundled ${ result . outputs . length } files to ${ outdir } / (patched ${ patched } for Node.js compat)` ,
60+ )
6161
6262// Step 4: Copy native .node addon files (audio-capture)
6363const vendorDir = join ( outdir , "vendor" , "audio-capture" ) ;
@@ -66,16 +66,16 @@ console.log(`Copied vendor/audio-capture/ → ${vendorDir}/`);
6666
6767// Step 5: Bundle download-ripgrep script as standalone JS for postinstall
6868const rgScript = await Bun . build ( {
69- entrypoints : [ " scripts/download-ripgrep.ts" ] ,
70- outdir,
71- target : " node" ,
72- } ) ;
69+ entrypoints : [ ' scripts/download-ripgrep.ts' ] ,
70+ outdir,
71+ target : ' node' ,
72+ } )
7373if ( ! rgScript . success ) {
74- console . error ( " Failed to bundle download-ripgrep script:" ) ;
75- for ( const log of rgScript . logs ) {
76- console . error ( log ) ;
77- }
78- // Non-fatal — postinstall fallback to bun run scripts/download-ripgrep.ts
74+ console . error ( ' Failed to bundle download-ripgrep script:' )
75+ for ( const log of rgScript . logs ) {
76+ console . error ( log )
77+ }
78+ // Non-fatal — postinstall fallback to bun run scripts/download-ripgrep.ts
7979} else {
80- console . log ( `Bundled download-ripgrep script to ${ outdir } /` ) ;
80+ console . log ( `Bundled download-ripgrep script to ${ outdir } /` )
8181}
0 commit comments