1- import { execFileSync , execSync } from 'child_process' ;
1+ import { execFileSync } from 'child_process' ;
2+ import { copyFileSync } from 'fs' ;
23
34const SEA_CONFIG = 'src/cli/sea-config.json' ;
4- const CLI_BINARY = 'httptoolkit-cli' ;
55const SEA_BLOB = 'build/cli/cli.blob' ;
66const SENTINEL_FUSE = 'NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2' ;
7+ const CLI_BINARY = 'httptoolkit-cli' + ( process . platform === 'win32' ? '.exe' : '' ) ;
78
89// Generate the single-executable-application blob from the compiled CLI JS:
910console . log ( 'Generating SEA blob...' ) ;
@@ -13,17 +14,30 @@ execFileSync(process.execPath, ['--experimental-sea-config', SEA_CONFIG], {
1314
1415// Copy the current Node binary to use as the CLI executable:
1516console . log ( 'Copying node binary...' ) ;
16- const nodePath = execSync ( 'which node' , { encoding : 'utf8' } ) . trim ( ) ;
17- execFileSync ( 'cp' , [ nodePath , CLI_BINARY ] ) ;
17+ copyFileSync ( process . execPath , CLI_BINARY ) ;
18+
19+ // On macOS, remove the ad-hoc signature before injection:
20+ if ( process . platform === 'darwin' ) {
21+ console . log ( 'Removing macOS ad-hoc signature...' ) ;
22+ execFileSync ( 'codesign' , [ '--remove-signature' , CLI_BINARY ] ) ;
23+ }
1824
1925// Inject the SEA blob into the copied binary:
2026console . log ( 'Injecting SEA blob...' ) ;
21- execFileSync ( 'npx' , [
27+ const postjectArgs = [
2228 'postject' , CLI_BINARY ,
2329 'NODE_SEA_BLOB' , SEA_BLOB ,
2430 '--sentinel-fuse' , SENTINEL_FUSE
25- ] , {
26- stdio : 'inherit'
27- } ) ;
31+ ] ;
32+ if ( process . platform === 'darwin' ) {
33+ postjectArgs . push ( '--macho-segment-name' , 'NODE_SEA' ) ;
34+ }
35+ execFileSync ( 'npx' , postjectArgs , { stdio : 'inherit' } ) ;
36+
37+ // On macOS, re-apply an ad-hoc signature so the binary is valid:
38+ if ( process . platform === 'darwin' ) {
39+ console . log ( 'Re-signing macOS binary...' ) ;
40+ execFileSync ( 'codesign' , [ '--sign' , '-' , CLI_BINARY ] ) ;
41+ }
2842
2943console . log ( 'CLI build completed.' ) ;
0 commit comments