@@ -67,6 +67,7 @@ export interface Options {
67
67
spawn : typeof spawn
68
68
spawnSync : typeof spawnSync
69
69
log : typeof log
70
+ kill : typeof kill
70
71
}
71
72
72
73
const storage = new AsyncLocalStorage < Options > ( )
@@ -95,6 +96,7 @@ export const defaults: Options = {
95
96
spawn,
96
97
spawnSync,
97
98
log,
99
+ kill,
98
100
}
99
101
const isWin = process . platform == 'win32'
100
102
try {
@@ -412,15 +414,7 @@ export class ProcessPromise extends Promise<ProcessOutput> {
412
414
throw new Error ( 'Trying to kill a process without creating one.' )
413
415
if ( ! this . child . pid ) throw new Error ( 'The process pid is undefined.' )
414
416
415
- let children = await ps . tree ( { pid : this . child . pid , recursive : true } )
416
- for ( const p of children ) {
417
- try {
418
- process . kill ( + p . pid , signal )
419
- } catch ( e ) { }
420
- }
421
- try {
422
- process . kill ( - this . child . pid , signal )
423
- } catch ( e ) { }
417
+ return $ . kill ( this . child . pid , signal )
424
418
}
425
419
426
420
stdio ( stdin : IO , stdout : IO = 'pipe' , stderr : IO = 'pipe' ) : ProcessPromise {
@@ -573,6 +567,18 @@ export function cd(dir: string | ProcessOutput) {
573
567
$ [ processCwd ] = process . cwd ( )
574
568
}
575
569
570
+ export async function kill ( pid : number , signal ?: string ) {
571
+ let children = await ps . tree ( { pid, recursive : true } )
572
+ for ( const p of children ) {
573
+ try {
574
+ process . kill ( + p . pid , signal )
575
+ } catch ( e ) { }
576
+ }
577
+ try {
578
+ process . kill ( - pid , signal )
579
+ } catch ( e ) { }
580
+ }
581
+
576
582
export type LogEntry =
577
583
| {
578
584
kind : 'cmd'
0 commit comments