@@ -18,7 +18,6 @@ if (typeof Bun !== "undefined" && await Bun.file(wasmOnDisk).exists()) {
1818 setQuickJSModule ( mod ) ;
1919}
2020
21- import { spawn } from "node:child_process" ;
2221import { resolve } from "node:path" ;
2322import { Command , Options , Args } from "@effect/cli" ;
2423import { BunRuntime } from "@effect/platform-bun" ;
@@ -74,33 +73,16 @@ const script = process.argv[1];
7473const isDevMode = script ?. endsWith ( ".ts" ) || script ?. endsWith ( ".js" ) ;
7574const cliPrefix = isDevMode ? `bun run ${ script } ` : "executor" ;
7675
77- const startBackgroundServer = ( port : number ) : void => {
78- const args = isDevMode
79- ? [ "run" , script , "web" , "--port" , String ( port ) ]
80- : [ "web" , "--port" , String ( port ) ] ;
81- const child = spawn ( process . execPath , args , {
82- detached : true ,
83- stdio : "ignore" ,
84- } ) ;
85- child . unref ( ) ;
86- } ;
87-
8876const ensureServer = ( baseUrl : string ) =>
8977 Effect . gen ( function * ( ) {
9078 if ( yield * Effect . promise ( ( ) => isServerReachable ( baseUrl ) ) ) return ;
9179
80+ // Start server in-process instead of spawning a background child.
81+ // This is more reliable across environments (containers, sandboxes, etc.)
9282 const url = new URL ( baseUrl ) ;
9383 const port = Number ( url . port ) || DEFAULT_PORT ;
94- console . error ( `Starting background server on port ${ port } ...` ) ;
95- startBackgroundServer ( port ) ;
96-
97- const deadline = Date . now ( ) + 30_000 ;
98- while ( Date . now ( ) < deadline ) {
99- yield * Effect . promise ( ( ) => new Promise ( ( r ) => setTimeout ( r , 200 ) ) ) ;
100- if ( yield * Effect . promise ( ( ) => isServerReachable ( baseUrl ) ) ) return ;
101- }
102-
103- return yield * Effect . fail ( new Error ( `Server failed to start within 30s at ${ baseUrl } ` ) ) ;
84+ console . error ( `Starting server on port ${ port } ...` ) ;
85+ yield * Effect . promise ( ( ) => startServer ( { port, embeddedWebUI } ) ) ;
10486 } ) ;
10587
10688// ---------------------------------------------------------------------------
@@ -302,6 +284,11 @@ const runCli = Command.run(root, {
302284 executable : CLI_NAME ,
303285} ) ;
304286
287+ if ( process . argv . includes ( "-v" ) ) {
288+ console . log ( CLI_VERSION ) ;
289+ process . exit ( 0 ) ;
290+ }
291+
305292const program = runCli ( process . argv ) . pipe (
306293 Effect . catchAllCause ( ( cause ) =>
307294 Effect . sync ( ( ) => {
0 commit comments