@@ -127,6 +127,87 @@ async function watchBuild(options = {}) {
127127 return exitCode
128128}
129129
130+ /**
131+ * Build SEA stub.
132+ */
133+ async function buildStub ( options = { } ) {
134+ const { quiet = false } = options
135+
136+ if ( ! quiet ) {
137+ log . progress ( 'Building SEA stub' )
138+ }
139+
140+ process . env [ 'NODE_ENV' ] = 'production'
141+ const exitCode = await runCommand (
142+ 'pnpm' ,
143+ [ 'exec' , 'rollup' , '-c' , '.config/rollup.sea.config.mjs' ] ,
144+ {
145+ stdio : quiet ? 'pipe' : 'inherit'
146+ }
147+ )
148+
149+ if ( exitCode !== 0 ) {
150+ if ( ! quiet ) {
151+ log . failed ( 'SEA stub build failed' )
152+ }
153+ return exitCode
154+ }
155+
156+ if ( ! quiet ) {
157+ log . done ( 'SEA stub built' )
158+ }
159+
160+ return 0
161+ }
162+
163+ /**
164+ * Build SEA binary using yao-pkg.
165+ */
166+ async function buildSea ( options = { } ) {
167+ const {
168+ arch = process . arch ,
169+ minify = false , // Default to current platform
170+ platform = process . platform , // Default to current architecture
171+ quiet = false
172+ } = options
173+
174+ if ( ! quiet ) {
175+ log . progress ( `Building yao-pkg binary for ${ platform } -${ arch } ` )
176+ }
177+
178+ // Build the SEA using yao-pkg (which uses the custom Node.js with patches)
179+ const args = [ path . join ( rootPath , 'scripts' , 'build' , 'build-stub.mjs' ) ]
180+
181+ // Always pass platform and arch (using defaults if not specified)
182+ args . push ( `--platform=${ platform } ` )
183+ args . push ( `--arch=${ arch } ` )
184+
185+ if ( minify ) {
186+ args . push ( '--minify' )
187+ }
188+
189+ if ( quiet ) {
190+ args . push ( '--quiet' )
191+ }
192+
193+ const exitCode = await runCommand ( 'node' , args , {
194+ stdio : quiet ? 'pipe' : 'inherit'
195+ } )
196+
197+ if ( exitCode !== 0 ) {
198+ if ( ! quiet ) {
199+ log . failed ( 'yao-pkg binary build failed' )
200+ }
201+ return exitCode
202+ }
203+
204+ if ( ! quiet ) {
205+ log . done ( 'yao-pkg binary built' )
206+ }
207+
208+ return 0
209+ }
210+
130211/**
131212 * Check if build is needed.
132213 */
@@ -174,6 +255,20 @@ async function main() {
174255 type : 'boolean' ,
175256 default : false ,
176257 } ,
258+ sea : {
259+ type : 'boolean' ,
260+ default : false ,
261+ } ,
262+ stub : {
263+ type : 'boolean' ,
264+ default : false ,
265+ } ,
266+ platform : {
267+ type : 'string' ,
268+ } ,
269+ arch : {
270+ type : 'string' ,
271+ } ,
177272 } ,
178273 allowPositionals : false ,
179274 strict : false ,
@@ -187,6 +282,10 @@ async function main() {
187282 console . log ( ' --help Show this help message' )
188283 console . log ( ' --src Build source code only' )
189284 console . log ( ' --types Build TypeScript declarations only' )
285+ console . log ( ' --sea Build self-contained binary with yao-pkg' )
286+ console . log ( ' --stub Build SEA stub only (for Node.js native SEA)' )
287+ console . log ( ' --platform Platform for SEA build (darwin, linux, win32)' )
288+ console . log ( ' --arch Architecture for SEA build (x64, arm64)' )
190289 console . log ( ' --watch Watch mode for development' )
191290 console . log ( ' --needed Only build if dist files are missing' )
192291 console . log ( ' --quiet, --silent Suppress progress messages' )
@@ -195,6 +294,9 @@ async function main() {
195294 console . log ( ' pnpm build # Full build (source + types)' )
196295 console . log ( ' pnpm build --src # Build source only' )
197296 console . log ( ' pnpm build --types # Build types only' )
297+ console . log ( ' pnpm build --stub # Build SEA stub only (for Node.js native SEA)' )
298+ console . log ( ' pnpm build --sea # Build self-contained binary with yao-pkg' )
299+ console . log ( ' pnpm build --sea --platform=darwin --arch=arm64 # Build macOS ARM64 binary' )
198300 console . log ( ' pnpm build --watch # Watch mode' )
199301 console . log ( ' pnpm build --needed # Build only if needed' )
200302 process . exitCode = 0
@@ -223,6 +325,20 @@ async function main() {
223325 if ( values . watch ) {
224326 exitCode = await watchBuild ( { quiet, verbose } )
225327 }
328+ // Build SEA binary
329+ else if ( values . sea ) {
330+ if ( ! quiet ) {
331+ log . step ( 'Building SEA binary' )
332+ }
333+ exitCode = await buildSea ( { quiet, verbose, platform : values . platform , arch : values . arch } )
334+ }
335+ // Build SEA stub only
336+ else if ( values . stub ) {
337+ if ( ! quiet ) {
338+ log . step ( 'Building SEA stub only' )
339+ }
340+ exitCode = await buildStub ( { quiet, verbose } )
341+ }
226342 // Build types only
227343 else if ( values . types && ! values . src ) {
228344 if ( ! quiet ) {
0 commit comments