@@ -104,11 +104,56 @@ export default class LimaBackend extends BaseBackend {
104104 } ) ( ) ;
105105 }
106106
107- protected async lima ( ...args : string [ ] ) : Promise < void > {
107+ protected async lima (
108+ command : string ,
109+ ...args : string [ ]
110+ ) : Promise < ChildResultType > {
108111 try {
109- await childProcess . spawnFile ( this . limactl , args , {
112+ const child = await childProcess . spawn ( this . limactl , [ command , ... args ] , {
110113 env : this . limaEnv ,
111- stdio : this . log ,
114+ } ) ;
115+
116+ const result = { code : 0 , stdout : "" , stderr : "" } ;
117+
118+ return await new Promise ( ( resolve , reject ) => {
119+ child . stdout ?. on ( "data" , ( data : Buffer ) => {
120+ const dataString = data . toString ( ) ;
121+ result . stdout += dataString ;
122+ this . emit ( events . VM_INIT_OUTPUT , dataString ) ;
123+ } ) ;
124+ child . stderr ?. on ( "data" , ( data : Buffer ) => {
125+ let dataString = data . toString ( ) ;
126+ result . stderr += dataString ;
127+ this . emit ( events . VM_INIT_OUTPUT , dataString ) ;
128+ } ) ;
129+ child . on ( "exit" , ( code , signal ) => {
130+ if ( result . stderr ) {
131+ }
132+ if ( code === 0 ) {
133+ resolve ( { ...result , code } ) ;
134+ } else if ( signal ) {
135+ reject (
136+ Object . create ( result , {
137+ code : { value : - 1 } ,
138+ signal : { value : signal } ,
139+ [ childProcess . ErrorCommand ] : {
140+ enumerable : false ,
141+ value : child . spawnargs ,
142+ } ,
143+ } )
144+ ) ;
145+ } else {
146+ reject (
147+ Object . create ( result , {
148+ code : { value : code } ,
149+ [ childProcess . ErrorCommand ] : {
150+ enumerable : false ,
151+ value : child . spawnargs ,
152+ } ,
153+ } )
154+ ) ;
155+ }
156+ } ) ;
112157 } ) ;
113158 } catch ( ex ) {
114159 console . error ( `+ limactl ${ args . join ( " " ) } ` ) ;
0 commit comments