@@ -81,7 +81,7 @@ export const defaults: Options = {
81
81
spawn,
82
82
log,
83
83
}
84
-
84
+ const isWin = process . platform == 'win32'
85
85
try {
86
86
defaults . shell = which . sync ( 'bash' )
87
87
defaults . prefix = 'set -euo pipefail;'
@@ -120,6 +120,7 @@ export const $ = new Proxy<Shell & Options>(
120
120
}
121
121
cmd += s + pieces [ ++ i ]
122
122
}
123
+ isWin && console . log ( 'cmd=' , cmd )
123
124
promise . _bind ( cmd , from , resolve ! , reject ! , getStore ( ) )
124
125
// Postpone run to allow promise configuration.
125
126
setImmediate ( ( ) => promise . isHalted || promise . run ( ) )
@@ -197,7 +198,7 @@ export class ProcessPromise extends Promise<ProcessOutput> {
197
198
cmd : $ . prefix + this . _command ,
198
199
get cwd ( ) { return $ . cwd ?? $ [ processCwd ] } ,
199
200
get shell ( ) {
200
- console . log ( '!!! shell=' , $ . shell )
201
+ isWin && console . log ( '$. shell=' , $ . shell )
201
202
return typeof $ . shell === 'string' ? $ . shell : true
202
203
} ,
203
204
get env ( ) { return $ . env } ,
@@ -206,6 +207,8 @@ export class ProcessPromise extends Promise<ProcessOutput> {
206
207
stdio : this . _stdio as any ,
207
208
sync : false ,
208
209
nothrow : true ,
210
+ nohandle : true ,
211
+ detached : ! isWin ,
209
212
onStdout ( data : any ) { $ . log ( { kind : 'stdout' , data, verbose : $ . verbose && ! self . _quiet } ) } ,
210
213
onStderr ( data : any ) { $ . log ( { kind : 'stderr' , data, verbose : $ . verbose && ! self . _quiet } ) } ,
211
214
run : cb => cb ( ) ,
@@ -220,13 +223,31 @@ export class ProcessPromise extends Promise<ProcessOutput> {
220
223
error,
221
224
stdout,
222
225
stderr,
223
- status : code ,
226
+ stdall,
227
+ status,
224
228
signal
225
229
} ) => {
230
+ isWin && console . log ( 'ctx=' , this . _zurk ?. _ctx )
226
231
if ( error ) {
227
-
232
+ const message = ProcessOutput . getErrorMessage ( error , self . _from )
233
+ self . _reject (
234
+ new ProcessOutput ( null , null , stdout , stderr , stdall , message )
235
+ )
228
236
} else {
229
-
237
+ const message = ProcessOutput . getMessage ( status , signal , stderr , self . _from )
238
+ const output = new ProcessOutput (
239
+ status ,
240
+ signal ,
241
+ stdout ,
242
+ stderr ,
243
+ stdall ,
244
+ message ,
245
+ )
246
+ if ( status === 0 || self . _nothrow ) {
247
+ self . _resolve ( output )
248
+ } else {
249
+ self . _reject ( output )
250
+ }
230
251
}
231
252
232
253
} )
@@ -239,45 +260,45 @@ export class ProcessPromise extends Promise<ProcessOutput> {
239
260
// env: $.env,
240
261
// })
241
262
242
- this . child . on ( 'close' , ( code , signal ) => {
243
- let message = ProcessOutput . getMessage ( code , signal , stderr , this . _from )
244
- let output = new ProcessOutput (
245
- code ,
246
- signal ,
247
- stdout ,
248
- stderr ,
249
- combined ,
250
- message
251
- )
252
- if ( code === 0 || this . _nothrow ) {
253
- this . _resolve ( output )
254
- } else {
255
- this . _reject ( output )
256
- }
257
- // this._resolved = true
258
- } )
259
- this . child . on ( 'error' , ( err : NodeJS . ErrnoException ) => {
260
- const message = ProcessOutput . getErrorMessage ( err , this . _from )
261
- this . _reject (
262
- new ProcessOutput ( null , null , stdout , stderr , combined , message )
263
- )
264
- // this._resolved = true
265
- } )
266
- let stdout = '' ,
267
- stderr = '' ,
268
- combined = ''
269
- let onStdout = ( data : any ) => {
270
- // $.log({ kind: 'stdout', data, verbose: $.verbose && !this._quiet })
271
- stdout += data
272
- combined += data
273
- }
274
- let onStderr = ( data : any ) => {
275
- // $.log({ kind: 'stderr', data, verbose: $.verbose && !this._quiet })
276
- stderr += data
277
- combined += data
278
- }
279
- if ( ! this . _piped ) this . child . stdout ?. on ( 'data' , onStdout ) // If process is piped, don't collect or print output.
280
- this . child . stderr ?. on ( 'data' , onStderr ) // Stderr should be printed regardless of piping.
263
+ // this.child.on('close', (code, signal) => {
264
+ // // let message = ProcessOutput.getMessage(code, signal, stderr, this._from)
265
+ // // let output = new ProcessOutput(
266
+ // // code,
267
+ // // signal,
268
+ // // stdout,
269
+ // // stderr,
270
+ // // combined,
271
+ // // message
272
+ // // )
273
+ // // if (code === 0 || this._nothrow) {
274
+ // // this._resolve(output)
275
+ // / / } else {
276
+ // // this._reject(output)
277
+ // / / }
278
+ // // this._resolved = true
279
+ // })
280
+ // this.child.on('error', (err: NodeJS.ErrnoException) => {
281
+ // // const message = ProcessOutput.getErrorMessage(err, this._from)
282
+ // // this._reject(
283
+ // // new ProcessOutput(null, null, stdout, stderr, combined, message)
284
+ // // )
285
+ // // this._resolved = true
286
+ // })
287
+ // let stdout = '',
288
+ // stderr = '',
289
+ // combined = ''
290
+ // let onStdout = (data: any) => {
291
+ // // $.log({ kind: 'stdout', data, verbose: $.verbose && !this._quiet })
292
+ // stdout += data
293
+ // combined += data
294
+ // }
295
+ // let onStderr = (data: any) => {
296
+ // // $.log({ kind: 'stderr', data, verbose: $.verbose && !this._quiet })
297
+ // stderr += data
298
+ // combined += data
299
+ // }
300
+ // if (!this._piped) this.child.stdout?.on('data', onStdout) // If process is piped, don't collect or print output.
301
+ // this.child.stderr?.on('data', onStderr) // Stderr should be printed regardless of piping.
281
302
this . _postrun ( ) // In case $1.pipe($2), after both subprocesses are running, we can pipe $1.stdout to $2.stdin.
282
303
// if (this._timeout && this._timeoutSignal) {
283
304
// const t = setTimeout(() => this.kill(this._timeoutSignal), this._timeout)
@@ -374,15 +395,17 @@ export class ProcessPromise extends Promise<ProcessOutput> {
374
395
if ( ! this . child )
375
396
throw new Error ( 'Trying to kill a process without creating one.' )
376
397
if ( ! this . child . pid ) throw new Error ( 'The process pid is undefined.' )
377
- let children = await psTree ( this . child . pid )
378
- for ( const p of children ) {
379
- try {
380
- process . kill ( + p . PID , signal )
381
- } catch ( e ) { }
382
- }
383
- try {
384
- process . kill ( this . child . pid , signal )
385
- } catch ( e ) { }
398
+
399
+ await this . _zurk ?. kill ( signal as NodeJS . Signals )
400
+ // let children = await psTree(this.child.pid)
401
+ // for (const p of children) {
402
+ // try {
403
+ // process.kill(+p.PID, signal)
404
+ // } catch (e) {}
405
+ // }
406
+ // try {
407
+ // process.kill(this.child.pid, signal)
408
+ // } catch (e) {}
386
409
}
387
410
388
411
stdio ( stdin : IO , stdout : IO = 'pipe' , stderr : IO = 'pipe' ) : ProcessPromise {
0 commit comments