-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-sea.js
More file actions
67 lines (59 loc) · 1.93 KB
/
build-sea.js
File metadata and controls
67 lines (59 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
const { execSync } = require('child_process');
const fs = require('fs');
const path = require('path');
// Ensure required directories exist
const dirs = ['dist', 'dist/bundled', 'dist/sea'];
dirs.forEach(dir => {
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true });
}
});
// First, ensure the bundle exists
if (!fs.existsSync('./dist/bundled/bundle.js')) {
console.error('Bundle not found. Please run npm run bundle first.');
process.exit(1);
}
// Step 1: Generate the sea-prep.blob file
console.log('Generating sea-prep.blob...');
try {
execSync('node --experimental-sea-config sea-config.json');
} catch (error) {
console.error('Failed to generate sea-prep.blob:', error.message);
process.exit(1);
}
// Step 2: Copy node binary
console.log('Copying node binary...');
try {
const nodePath = execSync('command -v node').toString().trim();
fs.copyFileSync(nodePath, 'dist/hello');
} catch (error) {
console.error('Failed to copy node binary:', error.message);
process.exit(1);
}
// Step 3: Remove existing signature (macOS specific)
console.log('Removing existing signature...');
try {
execSync('codesign --remove-signature dist/hello');
} catch (error) {
console.error('Failed to remove signature:', error.message);
process.exit(1);
}
// Step 4: Inject the blob into the binary
console.log('Injecting SEA blob...');
try {
execSync('npx --yes postject dist/hello NODE_SEA_BLOB dist/sea/sea-prep.blob \
--sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2 \
--macho-segment-name NODE_SEA');
} catch (error) {
console.error('Failed to inject SEA blob:', error.message);
process.exit(1);
}
// Step 5: Sign the binary (macOS specific)
console.log('Signing the binary...');
try {
execSync('codesign --sign - dist/hello');
} catch (error) {
console.error('Failed to sign binary:', error.message);
process.exit(1);
}
console.log('SEA binary creation complete! The executable is ready: ./dist/hello');