11import os from "node:os" ;
22import syncFs from "node:fs" ;
33import fs from "node:fs/promises" ;
4- import { spawn , spawnSync } from "node:child_process" ;
4+ import { spawn } from "node:child_process" ;
55
66const coreCount = os . cpus ( ) . length ;
77const threadCount = coreCount * 2 ;
8+ const ccacheEnv = { CC : "ccache gcc" , CXX : "ccache g++" } ;
89
910const nodejsGithubRepo = "https://github.com/nodejs/node" ;
1011const removeTheVCharacter = ( str ) => str . replace ( "v" , "" ) ;
@@ -35,11 +36,15 @@ const isANewerVersion = (oldVer, newVer) => {
3536 return false ;
3637} ;
3738
38- const spawnAsync = ( program , args , cwd ) =>
39+ const spawnAsync = ( program , args , cwd , env ) =>
3940 new Promise ( ( resolve , reject ) => {
4041 console . log ( [ program , ...args ] . join ( " " ) ) ;
4142
42- const child = spawn ( program , args , cwd ? { cwd } : { } ) ;
43+ const child = spawn (
44+ program ,
45+ args ,
46+ cwd ? { cwd, env : { ...process . env , ...env } } : { }
47+ ) ;
4348
4449 child . stdout . on ( "data" , ( chunk ) => console . log ( chunk . toString ( ) ) ) ;
4550 child . stderr . on ( "data" , ( chunk ) => console . warn ( chunk . toString ( ) ) ) ;
@@ -62,14 +67,16 @@ if (!syncFs.existsSync("node")) {
6267 `v${ latestNodeVersion } ` ,
6368 "--depth=1" ,
6469 ] ,
65- undefined
70+ undefined ,
71+ { }
6672 ) ;
6773}
6874
6975await spawnAsync (
7076 "./configure" ,
71- [ "--ninja" , "--shared" , "--debug" , "CC='ccache gcc'" , "CXX='ccache g++'" ] ,
72- "node"
77+ [ "--ninja" , "--shared" , "--debug" ] ,
78+ "node" ,
79+ ccacheEnv
7380) ;
7481
75- await spawnAsync ( "make" , [ `-j${ threadCount } ` ] , "node" ) ;
82+ await spawnAsync ( "make" , [ `-j${ threadCount } ` ] , "node" , ccacheEnv ) ;
0 commit comments