@@ -55,6 +55,7 @@ export interface Options {
55
55
nothrow : boolean
56
56
prefix : string
57
57
quote : typeof quote
58
+ quiet : boolean
58
59
spawn : typeof spawn
59
60
log : typeof log
60
61
}
@@ -75,6 +76,7 @@ export const defaults: Options = {
75
76
env : process . env ,
76
77
shell : true ,
77
78
nothrow : false ,
79
+ quiet : false ,
78
80
prefix : '' ,
79
81
quote : ( ) => {
80
82
throw new Error ( 'No quote function is defined: https://ï.at/no-quote-func' )
@@ -161,7 +163,7 @@ export class ProcessPromise extends Promise<ProcessOutput> {
161
163
private _snapshot = getStore ( )
162
164
private _stdio : [ IO , IO , IO ] = [ 'inherit' , 'pipe' , 'pipe' ]
163
165
private _nothrow ?: boolean
164
- private _quiet = false
166
+ private _quiet ?: boolean
165
167
private _timeout ?: number
166
168
private _timeoutSignal ?: string
167
169
private _resolved = false
@@ -194,7 +196,7 @@ export class ProcessPromise extends Promise<ProcessOutput> {
194
196
$ . log ( {
195
197
kind : 'cmd' ,
196
198
cmd : this . _command ,
197
- verbose : $ . verbose && ! this . _quiet ,
199
+ verbose : self . isVerbose ( ) ,
198
200
} )
199
201
200
202
this . _zurk = zurk$ ( {
@@ -210,10 +212,13 @@ export class ProcessPromise extends Promise<ProcessOutput> {
210
212
nohandle : true ,
211
213
detached : ! isWin ,
212
214
onStdout ( data : any ) {
213
- $ . log ( { kind : 'stdout' , data, verbose : $ . verbose && ! self . _quiet } )
215
+ // If process is piped, don't print output.
216
+ if ( self . _piped ) return
217
+ $ . log ( { kind : 'stdout' , data, verbose : self . isVerbose ( ) } )
214
218
} ,
215
219
onStderr ( data : any ) {
216
- $ . log ( { kind : 'stderr' , data, verbose : $ . verbose && ! self . _quiet } )
220
+ // Stderr should be printed regardless of piping.
221
+ $ . log ( { kind : 'stderr' , data, verbose : self . isVerbose ( ) } )
217
222
} ,
218
223
run : ( cb ) => cb ( ) ,
219
224
timeout : self . _timeout ,
@@ -232,7 +237,7 @@ export class ProcessPromise extends Promise<ProcessOutput> {
232
237
new ProcessOutput ( null , null , stdout , stderr , stdall , message )
233
238
)
234
239
} else {
235
- const message = ProcessOutput . getMessage (
240
+ const message = ProcessOutput . getExitMessage (
236
241
status ,
237
242
signal ,
238
243
stderr ,
@@ -255,8 +260,6 @@ export class ProcessPromise extends Promise<ProcessOutput> {
255
260
}
256
261
} )
257
262
258
- // if (!this._piped) this.child.stdout?.on('data', onStdout) // If process is piped, don't collect or print output.
259
- // this.child.stderr?.on('data', onStderr) // Stderr should be printed regardless of piping.
260
263
this . _postrun ( ) // In case $1.pipe($2), after both subprocesses are running, we can pipe $1.stdout to $2.stdin.
261
264
262
265
return this
@@ -352,6 +355,9 @@ export class ProcessPromise extends Promise<ProcessOutput> {
352
355
if ( ! this . child . pid ) throw new Error ( 'The process pid is undefined.' )
353
356
354
357
await this . _zurk ?. kill ( signal as NodeJS . Signals )
358
+ // zurk uses detached + process.kill(-p.pid)
359
+ // Do we still need this?
360
+
355
361
// let children = await psTree(this.child.pid)
356
362
// for (const p of children) {
357
363
// try {
@@ -378,6 +384,11 @@ export class ProcessPromise extends Promise<ProcessOutput> {
378
384
return this
379
385
}
380
386
387
+ isVerbose ( ) : boolean {
388
+ const { verbose, quiet } = this . _snapshot
389
+ return verbose && ! ( this . _quiet ?? quiet )
390
+ }
391
+
381
392
timeout ( d : Duration , signal = 'SIGTERM' ) : ProcessPromise {
382
393
this . _timeout = parseDuration ( d )
383
394
this . _timeoutSignal = signal
@@ -437,7 +448,7 @@ export class ProcessOutput extends Error {
437
448
return this . _signal
438
449
}
439
450
440
- static getMessage (
451
+ static getExitMessage (
441
452
code : number | null ,
442
453
signal : NodeJS . Signals | null ,
443
454
stderr : string ,
0 commit comments