Skip to content

Commit 1b9aedd

Browse files
frattaroisaacs
authored andcommitted
feat: add watchdog pid as cleanup metadata arg
PR-URL: tapjs#59 Credit: @frattaro Close: tapjs#59 Reviewed-by: @isaacs
1 parent 132a017 commit 1b9aedd

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changes
22

3+
## v3.3
4+
5+
- Include `watchdogPid` as a metadata argument to cleanup
6+
function
7+
38
## v3.2
49

510
- Export `watchdog` and `proxySignals` functionality

src/index.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
Serializable,
55
spawn as nodeSpawn,
66
SpawnOptions,
7+
ChildProcess,
78
} from 'child_process'
89
import crossSpawn from 'cross-spawn'
910
import { onExit } from 'signal-exit'
@@ -37,6 +38,9 @@ const spawn = process?.platform === 'win32' ? crossSpawn : nodeSpawn
3738
export type Cleanup = (
3839
code: number | null,
3940
signal: null | NodeJS.Signals,
41+
processInfo: {
42+
watchdogPid: ChildProcess['pid']
43+
},
4044
) =>
4145
| void
4246
| undefined
@@ -159,15 +163,17 @@ export function foregroundChild(
159163
const removeOnExit = onExit(childHangup)
160164

161165
proxySignals(child)
162-
watchdog(child)
166+
const dog = watchdog(child)
163167

164168
let done = false
165169
child.on('close', async (code, signal) => {
166170
/* c8 ignore start */
167171
if (done) return
168172
/* c8 ignore stop */
169173
done = true
170-
const result = cleanup(code, signal)
174+
const result = cleanup(code, signal, {
175+
watchdogPid: dog.pid,
176+
})
171177
const res = isPromise(result) ? await result : result
172178
removeOnExit()
173179

0 commit comments

Comments
 (0)