@@ -28,54 +28,64 @@ compilerInstance.ports.completeStaticBuild.subscribe(async function (output) {
28
28
// the Gren application, with a hint that tells the V8 engine what the
29
29
// main function is
30
30
31
- const compiledSrc = await fs . readFile ( jsBuildPath , "utf-8" ) ;
32
-
33
- const initRegex = / t h i s \. G r e n \. .+ \( \{ \} \) ; / g;
34
- const initCall = compiledSrc . match ( initRegex ) [ 0 ] ;
35
- const snapshotCompatibleSrc = compiledSrc . replace (
36
- initCall ,
37
- `
38
- const v8 = require('node:v8');
39
- v8.startupSnapshot.setDeserializeMainFunction(function() {
40
- ${ initCall }
41
- });
42
- ` ,
43
- ) ;
31
+ try {
32
+ const compiledSrc = await fs . readFile ( jsBuildPath , "utf-8" ) ;
33
+
34
+ const initRegex = / t h i s \. G r e n \. .+ \( \{ \} \) ; / g;
35
+ const initCall = compiledSrc . match ( initRegex ) [ 0 ] ;
36
+ const snapshotCompatibleSrc = compiledSrc . replace (
37
+ initCall ,
38
+ `
39
+ const v8 = require('node:v8');
40
+ v8.startupSnapshot.setDeserializeMainFunction(function() {
41
+ ${ initCall }
42
+ });
43
+ ` ,
44
+ ) ;
44
45
45
- await fs . writeFile ( jsBuildPath , snapshotCompatibleSrc ) ;
46
+ await fs . writeFile ( jsBuildPath , snapshotCompatibleSrc ) ;
46
47
47
- // We then need to generate the snapshot
48
+ // We then need to generate the snapshot
48
49
49
- const nodePath = process . execPath ;
50
- await fs . writeFile ( seaConfigPath , JSON . stringify ( seaConfig ) ) ;
51
- cp . execFileSync ( nodePath , [ "--experimental-sea-config" , seaConfigPath ] ) ;
50
+ const nodePath = process . execPath ;
51
+ await fs . writeFile ( seaConfigPath , JSON . stringify ( seaConfig ) ) ;
52
+ cp . execFileSync ( nodePath , [ "--experimental-sea-config" , seaConfigPath ] ) ;
52
53
53
- // Then copy the node executable and inject the snapshot into it
54
- await fs . copyFile ( nodePath , binPath ) ;
54
+ // Then copy the node executable and inject the snapshot into it
55
+ await fs . copyFile ( nodePath , binPath ) ;
56
+ await fs . chmod ( binPath , "755" ) ;
55
57
56
- if ( isMac ) {
57
- // required on mac, optional on windows, not required on linux
58
- cp . execFileSync ( "codesign" , [ "--remove-signature" , binPath ] ) ;
59
- }
58
+ if ( isMac ) {
59
+ // required on mac, optional on windows, not required on linux
60
+ cp . execFileSync ( "codesign" , [ "--remove-signature" , binPath ] ) ;
61
+ }
60
62
61
- const blobContent = await fs . readFile ( blobPath ) ;
63
+ const blobContent = await fs . readFile ( blobPath ) ;
62
64
63
- await postject . inject ( binPath , "NODE_SEA_BLOB" , blobContent , {
64
- sentinelFuse : "NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2" ,
65
- machoSegmentName : isMac ? "NODE_SEA" : undefined ,
66
- } ) ;
65
+ await postject . inject ( binPath , "NODE_SEA_BLOB" , blobContent , {
66
+ sentinelFuse : "NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2" ,
67
+ machoSegmentName : isMac ? "NODE_SEA" : undefined ,
68
+ } ) ;
67
69
68
- if ( isMac ) {
69
- // required on mac
70
- cp . execFileSync ( "codesign" , [ "--sign" , "-" , binPath ] ) ;
71
- }
70
+ if ( isMac ) {
71
+ // required on mac
72
+ cp . execFileSync ( "codesign" , [ "--sign" , "-" , binPath ] ) ;
73
+ }
72
74
73
- // cleanup
75
+ const outputPath = isWin ? jsBuildPath + ".exe" : jsBuildPath ;
76
+ await fs . rename ( binPath , outputPath ) ;
74
77
75
- await fs . rm ( jsBuildPath ) ;
76
- await fs . rm ( blobPath ) ;
77
- await fs . rm ( seaConfigPath ) ;
78
+ if ( isWin ) {
79
+ await fs . rm ( jsBuildPath ) ;
80
+ }
78
81
79
- const outputPath = isWin ? jsBuildPath + ".exe" : jsBuildPath ;
80
- await fs . rename ( binPath , outputPath ) ;
82
+ console . log ( "Done!" ) ;
83
+ } catch ( e ) {
84
+ console . error ( "Failed to create static executable" , e ) ;
85
+ await fs . rm ( jsBuildPath ) ;
86
+ } finally {
87
+ // cleanup
88
+ await fs . rm ( blobPath ) ;
89
+ await fs . rm ( seaConfigPath ) ;
90
+ }
81
91
} ) ;
0 commit comments