@@ -6,20 +6,33 @@ const path = require("path")
66const os = require ( "os" )
77
88function run ( target ) {
9- const result = childProcess . spawnSync ( target , process . argv . slice ( 2 ) , {
9+ const child = childProcess . spawn ( target , process . argv . slice ( 2 ) , {
1010 stdio : "inherit" ,
1111 } )
12- if ( result . error ) {
13- console . error ( result . error . message )
12+ child . on ( " error" , ( err ) => {
13+ console . error ( err . message )
1414 process . exit ( 1 )
15+ } )
16+ const forward = ( sig ) => {
17+ if ( ! child . killed ) {
18+ try { child . kill ( sig ) } catch { }
19+ }
1520 }
16- const code = typeof result . status === "number" ? result . status : 0
17- process . exit ( code )
21+ ; [ "SIGINT" , "SIGTERM" , "SIGHUP" ] . forEach ( ( sig ) => {
22+ process . on ( sig , ( ) => forward ( sig ) )
23+ } )
24+ child . on ( "exit" , ( code , signal ) => {
25+ if ( signal ) {
26+ process . kill ( process . pid , signal )
27+ return
28+ }
29+ process . exit ( typeof code === "number" ? code : 1 )
30+ } )
1831}
1932
2033const envPath = process . env . OPENCODE_BIN_PATH
2134if ( envPath ) {
22- run ( envPath )
35+ return run ( envPath )
2336}
2437
2538const scriptPath = fs . realpathSync ( __filename )
@@ -28,7 +41,7 @@ const scriptDir = path.dirname(scriptPath)
2841//
2942const cached = path . join ( scriptDir , ".opencode" )
3043if ( fs . existsSync ( cached ) ) {
31- run ( cached )
44+ return run ( cached )
3245}
3346
3447const platformMap = {
0 commit comments