@@ -39,31 +39,24 @@ const SKIP_WASM = args.includes('--skip-wasm')
3939
4040// Platform definitions.
4141const PLATFORMS = [
42- 'alpine- arm64' ,
43- 'alpine- x64' ,
44- 'darwin- arm64' ,
45- 'darwin- x64' ,
46- 'linux- arm64' ,
47- 'linux- x64' ,
48- 'win32- arm64' ,
49- 'win32- x64' ,
42+ { platform : 'alpine' , arch : ' arm64' } ,
43+ { platform : 'alpine' , arch : ' x64' } ,
44+ { platform : 'darwin' , arch : ' arm64' } ,
45+ { platform : 'darwin' , arch : ' x64' } ,
46+ { platform : 'linux' , arch : ' arm64' } ,
47+ { platform : 'linux' , arch : ' x64' } ,
48+ { platform : 'win32' , arch : ' arm64' } ,
49+ { platform : 'win32' , arch : ' x64' } ,
5050]
5151
5252/**
5353 * Get current platform identifier.
5454 */
5555function getCurrentPlatform ( ) {
56- const platform = osPlatform ( )
57- const arch = osArch ( )
58-
59- // Map Node.js platform/arch to our naming convention.
60- const platformMap = {
61- darwin : { arm64 : 'darwin-arm64' , x64 : 'darwin-x64' } ,
62- linux : { arm64 : 'linux-arm64' , x64 : 'linux-x64' } ,
63- win32 : { arm64 : 'win32-arm64' , x64 : 'win32-x64' } ,
56+ return {
57+ platform : osPlatform ( ) ,
58+ arch : osArch ( ) ,
6459 }
65-
66- return platformMap [ platform ] ?. [ arch ] || `${ platform } -${ arch } `
6760}
6861
6962/**
@@ -153,15 +146,16 @@ async function buildModelPackages() {
153146/**
154147 * Build custom Node.js (smol variant).
155148 */
156- async function buildNodeSmol ( targetPlatform ) {
157- logger . step ( `Building node-smol-builder (${ targetPlatform } )` )
149+ async function buildNodeSmol ( target ) {
150+ const targetName = `${ target . platform } -${ target . arch } `
151+ logger . step ( `Building node-smol-builder (${ targetName } )` )
158152 logger . info ( '' )
159153
160154 const pkgDir = path . join ( rootDir , 'packages' , 'node-smol-builder' )
161155 const buildScript = path . join ( pkgDir , 'scripts' , 'build.mjs' )
162156
163157 // Create build directory structure.
164- const buildDir = path . join ( pkgDir , 'build' , `cli-${ targetPlatform } ` )
158+ const buildDir = path . join ( pkgDir , 'build' , `cli-${ targetName } ` )
165159 await mkdir ( buildDir , { recursive : true } )
166160
167161 logger . info ( ` Target: ${ buildDir } ` )
@@ -175,22 +169,23 @@ async function buildNodeSmol(targetPlatform) {
175169 // Build custom Node.js.
176170 await exec ( 'node' , [ buildScript ] , { cwd : pkgDir } )
177171
178- logger . success ( `✓ node-smol-builder built for ${ targetPlatform } ` )
172+ logger . success ( `✓ node-smol-builder built for ${ targetName } ` )
179173 logger . info ( '' )
180174}
181175
182176/**
183177 * Build SEA binaries.
184178 */
185- async function buildNodeSEA ( targetPlatform ) {
186- logger . step ( `Building node-sea-builder (${ targetPlatform } )` )
179+ async function buildNodeSEA ( target ) {
180+ const targetName = `${ target . platform } -${ target . arch } `
181+ logger . step ( `Building node-sea-builder (${ targetName } )` )
187182 logger . info ( '' )
188183
189184 const pkgDir = path . join ( rootDir , 'packages' , 'node-sea-builder' )
190185 const buildScript = path . join ( pkgDir , 'scripts' , 'build.mjs' )
191186
192187 // Create build directory structure.
193- const buildDir = path . join ( pkgDir , 'build' , `cli-${ targetPlatform } ` )
188+ const buildDir = path . join ( pkgDir , 'build' , `cli-${ targetName } ` )
194189 await mkdir ( buildDir , { recursive : true } )
195190
196191 logger . info ( ` Target: ${ buildDir } ` )
@@ -202,11 +197,15 @@ async function buildNodeSEA(targetPlatform) {
202197 }
203198
204199 // Build SEA binary.
205- await exec ( 'node' , [ buildScript , '--platform' , targetPlatform ] , {
206- cwd : pkgDir ,
207- } )
208-
209- logger . success ( `✓ node-sea-builder built for ${ targetPlatform } ` )
200+ await exec (
201+ 'node' ,
202+ [ buildScript , '--platform' , target . platform , '--arch' , target . arch ] ,
203+ {
204+ cwd : pkgDir ,
205+ } ,
206+ )
207+
208+ logger . success ( `✓ node-sea-builder built for ${ targetName } ` )
210209 logger . info ( '' )
211210}
212211
@@ -226,8 +225,11 @@ async function main() {
226225 ? PLATFORMS
227226 : [ currentPlatform ]
228227
229- logger . info ( `Current platform: ${ currentPlatform } ` )
230- logger . info ( `Building for: ${ platformsToBuild . join ( ', ' ) } ` )
228+ const formatPlatform = p => `${ p . platform } -${ p . arch } `
229+ logger . info ( `Current platform: ${ formatPlatform ( currentPlatform ) } ` )
230+ logger . info (
231+ `Building for: ${ platformsToBuild . map ( formatPlatform ) . join ( ', ' ) } ` ,
232+ )
231233 logger . info ( '' )
232234
233235 // Phase 1: WASM Components.
@@ -243,20 +245,21 @@ async function main() {
243245 }
244246
245247 // Phase 2: Build for each platform.
246- for ( const platform of platformsToBuild ) {
248+ for ( const target of platformsToBuild ) {
249+ const targetName = formatPlatform ( target )
247250 logger . info ( `\n${ '=' . repeat ( 60 ) } ` )
248- logger . info ( `Building platform: ${ platform } ` )
251+ logger . info ( `Building platform: ${ targetName } ` )
249252 logger . info ( '=' . repeat ( 60 ) )
250253 logger . info ( '' )
251254
252255 // Build smol variant.
253256 if ( ! BUILD_SEA_ONLY ) {
254- await buildNodeSmol ( platform )
257+ await buildNodeSmol ( target )
255258 }
256259
257260 // Build SEA variant.
258261 if ( ! BUILD_SMOL_ONLY ) {
259- await buildNodeSEA ( platform )
262+ await buildNodeSEA ( target )
260263 }
261264 }
262265
0 commit comments