diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d284a9..649f270 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changes +## v3.3 + +- Include `watchdogPid` as a metadata argument to cleanup + function + ## v3.2 - Export `watchdog` and `proxySignals` functionality diff --git a/src/index.ts b/src/index.ts index 9e84fed..d807126 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,6 +4,7 @@ import { Serializable, spawn as nodeSpawn, SpawnOptions, + ChildProcess, } from 'child_process' import crossSpawn from 'cross-spawn' import { onExit } from 'signal-exit' @@ -37,6 +38,9 @@ const spawn = process?.platform === 'win32' ? crossSpawn : nodeSpawn export type Cleanup = ( code: number | null, signal: null | NodeJS.Signals, + processInfo: { + watchdogPid?: ChildProcess['pid'] + }, ) => | void | undefined @@ -159,7 +163,7 @@ export function foregroundChild( const removeOnExit = onExit(childHangup) proxySignals(child) - watchdog(child) + const dog = watchdog(child) let done = false child.on('close', async (code, signal) => { @@ -167,7 +171,9 @@ export function foregroundChild( if (done) return /* c8 ignore stop */ done = true - const result = cleanup(code, signal) + const result = cleanup(code, signal, { + watchdogPid: dog.pid, + }) const res = isPromise(result) ? await result : result removeOnExit() diff --git a/test/normalize-fg-args.ts b/test/normalize-fg-args.ts index aee0280..698ad81 100644 --- a/test/normalize-fg-args.ts +++ b/test/normalize-fg-args.ts @@ -32,7 +32,7 @@ t.plan(cases.length) for (const c of cases) { t.test(JSON.stringify(c), t => { const norm = normalizeFgArgs(c) - norm[3](0, null) + norm[3](0, null, {}) t.equal(norm[0], 'cmd') if (Array.isArray(c[1])) { t.equal(norm[1], c[1])