33 */
44
55import { spawn } from 'node:child_process'
6- import { existsSync } from 'node:fs'
6+ import { existsSync , statSync } from 'node:fs'
77import path from 'node:path'
88import { fileURLToPath } from 'node:url'
99import { parseArgs } from 'node:util'
@@ -230,6 +230,14 @@ async function main() {
230230 type : 'boolean' ,
231231 default : false ,
232232 } ,
233+ node : {
234+ type : 'boolean' ,
235+ default : false ,
236+ } ,
237+ stub : {
238+ type : 'boolean' ,
239+ default : false ,
240+ } ,
233241 } ,
234242 allowPositionals : false ,
235243 strict : false ,
@@ -244,15 +252,66 @@ async function main() {
244252 console . log ( ' --types Build TypeScript declarations only' )
245253 console . log ( ' --watch Watch mode for development' )
246254 console . log ( ' --needed Only build if dist files are missing' )
255+ console . log ( ' --node Build custom Node.js binary (socket-node)' )
256+ console . log ( ' --stub Build stub/SEA binary (includes Node build if needed)' )
247257 console . log ( '\nExamples:' )
248258 console . log ( ' pnpm build # Full build (source + types)' )
249259 console . log ( ' pnpm build --src # Build source only' )
250260 console . log ( ' pnpm build --types # Build types only' )
251261 console . log ( ' pnpm build --watch # Watch mode' )
262+ console . log ( ' pnpm build --node # Build custom Node.js binary' )
263+ console . log ( ' pnpm build --stub # Build standalone executable' )
252264 process . exitCode = 0
253265 return
254266 }
255267
268+ // Handle custom Node.js build.
269+ if ( values . node ) {
270+ printHeader ( 'Custom Node.js Builder' )
271+ log . step ( 'Building custom Node.js binary' )
272+
273+ const buildNodeScript = path . join ( __dirname , 'build' , 'build-tiny-node.mjs' )
274+ const nodeArgs = [ 'exec' , 'node' , buildNodeScript ]
275+
276+ const nodeExitCode = await runCommand ( 'pnpm' , nodeArgs )
277+
278+ if ( nodeExitCode !== 0 ) {
279+ log . error ( 'Node build failed' )
280+ process . exitCode = nodeExitCode
281+ } else {
282+ // Report file size
283+ const nodeBinary = WIN32 ? 'node.exe' : 'node'
284+ const nodePath = path . join ( rootPath , 'build' , 'tiny-node' , `node-v24.9.0-custom` , 'out' , 'Release' , nodeBinary )
285+ if ( existsSync ( nodePath ) ) {
286+ const stats = statSync ( nodePath )
287+ const sizeMB = ( stats . size / 1024 / 1024 ) . toFixed ( 1 )
288+ printFooter ( `Node.js built successfully! Size: ${ sizeMB } MB` )
289+ } else {
290+ printFooter ( 'Node.js built successfully!' )
291+ }
292+ }
293+ return
294+ }
295+
296+ // Handle stub/SEA build.
297+ if ( values . stub ) {
298+ printHeader ( 'Stub/SEA Builder' )
299+ log . step ( 'Building standalone executable' )
300+
301+ const buildStubScript = path . join ( __dirname , 'build' , 'build-stub.mjs' )
302+ const stubArgs = [ 'exec' , 'node' , buildStubScript ]
303+
304+ const stubExitCode = await runCommand ( 'pnpm' , stubArgs )
305+
306+ if ( stubExitCode !== 0 ) {
307+ log . error ( 'Stub build failed' )
308+ process . exitCode = stubExitCode
309+ } else {
310+ printFooter ( 'Stub/SEA binary built successfully!' )
311+ }
312+ return
313+ }
314+
256315 // Detect build configuration.
257316 const config = detectBuildConfig ( )
258317
0 commit comments