@@ -183,6 +183,7 @@ export class ProcessPromise extends Promise<ProcessOutput> {
183
183
184
184
run ( ) : ProcessPromise {
185
185
const $ = this . _snapshot
186
+ const self = this
186
187
if ( this . child ) return this // The _run() can be called from a few places.
187
188
this . _prerun ( ) // In case $1.pipe($2), the $2 returned, and on $2._run() invoke $1._run().
188
189
@@ -193,22 +194,38 @@ export class ProcessPromise extends Promise<ProcessOutput> {
193
194
} )
194
195
195
196
this . _zurk = zurk$ ( {
196
- get cwd ( ) { return $ . cwd ?? $ [ processCwd ] } ,
197
197
cmd : $ . prefix + this . _command ,
198
+ get cwd ( ) { return $ . cwd ?? $ [ processCwd ] } ,
198
199
get shell ( ) { return typeof $ . shell === 'string' ? $ . shell : true } ,
199
200
get env ( ) { return $ . env } ,
200
- stdio : this . _stdio as any ,
201
201
get spawn ( ) { return $ . spawn } ,
202
- run : cb => cb ( ) ,
202
+ stdio : this . _stdio as any ,
203
203
sync : false ,
204
- nothrow : true
204
+ nothrow : true ,
205
+ onStdout ( data : any ) { $ . log ( { kind : 'stdout' , data, verbose : $ . verbose && ! self . _quiet } ) } ,
206
+ onStderr ( data : any ) { $ . log ( { kind : 'stderr' , data, verbose : $ . verbose && ! self . _quiet } ) } ,
207
+ run : cb => cb ( ) ,
208
+ timeout : self . _timeout ,
209
+ timeoutSignal : self . _timeoutSignal as NodeJS . Signals ,
205
210
} ) ( ) as TZurkShellResponse
206
211
207
212
this . child = this . _zurk . _ctx . child as ChildProcess
208
213
209
- // this._zurk.then(({}) => {
210
- //
211
- // })
214
+ this . _zurk . finally ( ( ) => self . _resolved = true )
215
+ this . _zurk . then ( ( {
216
+ error,
217
+ stdout,
218
+ stderr,
219
+ status : code ,
220
+ signal
221
+ } ) => {
222
+ if ( error ) {
223
+
224
+ } else {
225
+
226
+ }
227
+
228
+ } )
212
229
213
230
// this.child = $.spawn($.prefix + this._command, {
214
231
// cwd: $.cwd ?? $[processCwd],
@@ -233,39 +250,35 @@ export class ProcessPromise extends Promise<ProcessOutput> {
233
250
} else {
234
251
this . _reject ( output )
235
252
}
236
- this . _resolved = true
253
+ // this._resolved = true
237
254
} )
238
255
this . child . on ( 'error' , ( err : NodeJS . ErrnoException ) => {
239
- const message =
240
- `${ err . message } \n` +
241
- ` errno: ${ err . errno } (${ errnoMessage ( err . errno ) } )\n` +
242
- ` code: ${ err . code } \n` +
243
- ` at ${ this . _from } `
256
+ const message = ProcessOutput . getErrorMessage ( err , this . _from )
244
257
this . _reject (
245
258
new ProcessOutput ( null , null , stdout , stderr , combined , message )
246
259
)
247
- this . _resolved = true
260
+ // this._resolved = true
248
261
} )
249
262
let stdout = '' ,
250
263
stderr = '' ,
251
264
combined = ''
252
265
let onStdout = ( data : any ) => {
253
- $ . log ( { kind : 'stdout' , data, verbose : $ . verbose && ! this . _quiet } )
266
+ // $.log({ kind: 'stdout', data, verbose: $.verbose && !this._quiet })
254
267
stdout += data
255
268
combined += data
256
269
}
257
270
let onStderr = ( data : any ) => {
258
- $ . log ( { kind : 'stderr' , data, verbose : $ . verbose && ! this . _quiet } )
271
+ // $.log({ kind: 'stderr', data, verbose: $.verbose && !this._quiet })
259
272
stderr += data
260
273
combined += data
261
274
}
262
275
if ( ! this . _piped ) this . child . stdout ?. on ( 'data' , onStdout ) // If process is piped, don't collect or print output.
263
276
this . child . stderr ?. on ( 'data' , onStderr ) // Stderr should be printed regardless of piping.
264
277
this . _postrun ( ) // In case $1.pipe($2), after both subprocesses are running, we can pipe $1.stdout to $2.stdin.
265
- if ( this . _timeout && this . _timeoutSignal ) {
266
- const t = setTimeout ( ( ) => this . kill ( this . _timeoutSignal ) , this . _timeout )
267
- this . finally ( ( ) => clearTimeout ( t ) ) . catch ( noop )
268
- }
278
+ // if (this._timeout && this._timeoutSignal) {
279
+ // const t = setTimeout(() => this.kill(this._timeoutSignal), this._timeout)
280
+ // this.finally(() => clearTimeout(t)).catch(noop)
281
+ // }
269
282
return this
270
283
}
271
284
@@ -457,6 +470,14 @@ export class ProcessOutput extends Error {
457
470
return message
458
471
}
459
472
473
+ static getErrorMessage ( err : NodeJS . ErrnoException , from : string ) {
474
+ return `` +
475
+ `${ err . message } \n` +
476
+ ` errno: ${ err . errno } (${ errnoMessage ( err . errno ) } )\n` +
477
+ ` code: ${ err . code } \n` +
478
+ ` at ${ from } `
479
+ }
480
+
460
481
[ inspect . custom ] ( ) {
461
482
let stringify = ( s : string , c : ChalkInstance ) =>
462
483
s . length === 0 ? "''" : c ( inspect ( s ) )
0 commit comments