Skip to content

Commit 1ae388c

Browse files
committed
Integate CLI build into the real app build itself
Previously it was run manually only, and was Linux only - should now work cross-platform (in theory).
1 parent 919f598 commit 1ae388c

3 files changed

Lines changed: 69 additions & 10 deletions

File tree

build-setup/build-cli.ts

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { execFileSync, execSync } from 'child_process';
1+
import { execFileSync } from 'child_process';
2+
import { copyFileSync } from 'fs';
23

34
const SEA_CONFIG = 'src/cli/sea-config.json';
4-
const CLI_BINARY = 'httptoolkit-cli';
55
const SEA_BLOB = 'build/cli/cli.blob';
66
const 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:
910
console.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:
1516
console.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:
2026
console.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

2943
console.log('CLI build completed.');

package-lock.json

Lines changed: 44 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"scripts": {
1111
"postinstall": "electron-builder install-app-deps",
1212
"server:setup": "tsx ./build-setup/setup-server.ts",
13-
"build": "npm run build:src && npm run build:electron",
13+
"build": "npm run build:src && npm run build:cli && npm run build:electron",
1414
"build:src": "tsc",
1515
"postbuild:src": "tsx ./build-setup/strip-preload-map.ts",
1616
"build:electron": "npm run server:setup && electron-builder build --config ./build-setup/electron-builder.config.cjs",
@@ -61,7 +61,7 @@
6161
],
6262
"extraResources": [
6363
"httptoolkit-server/**/*",
64-
"httptoolkit-cli"
64+
"httptoolkit-cli{,.*}"
6565
],
6666
"artifactName": "HttpToolkit-${version}-${arch}.${ext}",
6767
"mac": {
@@ -172,6 +172,7 @@
172172
"targz": "^1.0.1",
173173
"tsc-watch": "^4.2.9",
174174
"tsx": "^4.16.2",
175+
"postject": "1.0.0-alpha.6",
175176
"typescript": "~5.9"
176177
},
177178
"engines": {

0 commit comments

Comments
 (0)