diff --git a/node_modules/foreground-child/dist/cjs/all-signals.js b/node_modules/foreground-child/dist/commonjs/all-signals.js similarity index 100% rename from node_modules/foreground-child/dist/cjs/all-signals.js rename to node_modules/foreground-child/dist/commonjs/all-signals.js diff --git a/node_modules/foreground-child/dist/cjs/index.js b/node_modules/foreground-child/dist/commonjs/index.js similarity index 77% rename from node_modules/foreground-child/dist/cjs/index.js rename to node_modules/foreground-child/dist/commonjs/index.js index d522c981fabcb..8ea5413b0935b 100644 --- a/node_modules/foreground-child/dist/cjs/index.js +++ b/node_modules/foreground-child/dist/commonjs/index.js @@ -7,7 +7,7 @@ exports.foregroundChild = exports.normalizeFgArgs = void 0; const child_process_1 = require("child_process"); const cross_spawn_1 = __importDefault(require("cross-spawn")); const signal_exit_1 = require("signal-exit"); -const all_signals_js_1 = require("./all-signals.js"); +const proxy_signals_js_1 = require("./proxy-signals.js"); const watchdog_js_1 = require("./watchdog.js"); /* c8 ignore start */ const spawn = process?.platform === 'win32' ? cross_spawn_1.default : child_process_1.spawn; @@ -50,7 +50,6 @@ function foregroundChild(...fgArgs) { spawnOpts.stdio.push('ipc'); } const child = spawn(program, args, spawnOpts); - const unproxySignals = proxySignals(child); const childHangup = () => { try { child.kill('SIGHUP'); @@ -63,20 +62,18 @@ function foregroundChild(...fgArgs) { /* c8 ignore stop */ }; const removeOnExit = (0, signal_exit_1.onExit)(childHangup); - const dog = (0, watchdog_js_1.watchdog)(child); + (0, proxy_signals_js_1.proxySignals)(child); + (0, watchdog_js_1.watchdog)(child); let done = false; child.on('close', async (code, signal) => { - dog.kill('SIGKILL'); /* c8 ignore start */ - if (done) { + if (done) return; - } /* c8 ignore stop */ done = true; const result = cleanup(code, signal); const res = isPromise(result) ? await result : result; removeOnExit(); - unproxySignals(); if (res === false) return; else if (typeof res === 'string') { @@ -120,35 +117,5 @@ function foregroundChild(...fgArgs) { return child; } exports.foregroundChild = foregroundChild; -/** - * Starts forwarding signals to `child` through `parent`. - */ -const proxySignals = (child) => { - const listeners = new Map(); - for (const sig of all_signals_js_1.allSignals) { - const listener = () => { - // some signals can only be received, not sent - try { - child.kill(sig); - /* c8 ignore start */ - } - catch (_) { } - /* c8 ignore stop */ - }; - try { - // if it's a signal this system doesn't recognize, skip it - process.on(sig, listener); - listeners.set(sig, listener); - /* c8 ignore start */ - } - catch (_) { } - /* c8 ignore stop */ - } - return () => { - for (const [sig, listener] of listeners) { - process.removeListener(sig, listener); - } - }; -}; const isPromise = (o) => !!o && typeof o === 'object' && typeof o.then === 'function'; //# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/node_modules/foreground-child/dist/cjs/package.json b/node_modules/foreground-child/dist/commonjs/package.json similarity index 100% rename from node_modules/foreground-child/dist/cjs/package.json rename to node_modules/foreground-child/dist/commonjs/package.json diff --git a/node_modules/foreground-child/dist/commonjs/proxy-signals.js b/node_modules/foreground-child/dist/commonjs/proxy-signals.js new file mode 100644 index 0000000000000..3913e7b45bce2 --- /dev/null +++ b/node_modules/foreground-child/dist/commonjs/proxy-signals.js @@ -0,0 +1,38 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.proxySignals = void 0; +const all_signals_js_1 = require("./all-signals.js"); +/** + * Starts forwarding signals to `child` through `parent`. + */ +const proxySignals = (child) => { + const listeners = new Map(); + for (const sig of all_signals_js_1.allSignals) { + const listener = () => { + // some signals can only be received, not sent + try { + child.kill(sig); + /* c8 ignore start */ + } + catch (_) { } + /* c8 ignore stop */ + }; + try { + // if it's a signal this system doesn't recognize, skip it + process.on(sig, listener); + listeners.set(sig, listener); + /* c8 ignore start */ + } + catch (_) { } + /* c8 ignore stop */ + } + const unproxy = () => { + for (const [sig, listener] of listeners) { + process.removeListener(sig, listener); + } + }; + child.on('exit', unproxy); + return unproxy; +}; +exports.proxySignals = proxySignals; +//# sourceMappingURL=proxy-signals.js.map \ No newline at end of file diff --git a/node_modules/foreground-child/dist/cjs/watchdog.js b/node_modules/foreground-child/dist/commonjs/watchdog.js similarity index 81% rename from node_modules/foreground-child/dist/cjs/watchdog.js rename to node_modules/foreground-child/dist/commonjs/watchdog.js index 5f553ac1ae3d3..514e234c2a0ed 100644 --- a/node_modules/foreground-child/dist/cjs/watchdog.js +++ b/node_modules/foreground-child/dist/commonjs/watchdog.js @@ -27,6 +27,13 @@ if (!isNaN(pid)) { process.on('SIGHUP', bark) } `; +/** + * Pass in a ChildProcess, and this will spawn a watchdog process that + * will make sure it exits if the parent does, thus preventing any + * dangling detached zombie processes. + * + * If the child ends before the parent, then the watchdog will terminate. + */ const watchdog = (child) => { let dogExited = false; const dog = (0, child_process_1.spawn)(process.execPath, ['-e', watchdogCode, String(child.pid)], { @@ -35,7 +42,7 @@ const watchdog = (child) => { dog.on('exit', () => (dogExited = true)); child.on('exit', () => { if (!dogExited) - dog.kill('SIGTERM'); + dog.kill('SIGKILL'); }); return dog; }; diff --git a/node_modules/foreground-child/dist/mjs/all-signals.js b/node_modules/foreground-child/dist/esm/all-signals.js similarity index 100% rename from node_modules/foreground-child/dist/mjs/all-signals.js rename to node_modules/foreground-child/dist/esm/all-signals.js diff --git a/node_modules/foreground-child/dist/mjs/index.js b/node_modules/foreground-child/dist/esm/index.js similarity index 76% rename from node_modules/foreground-child/dist/mjs/index.js rename to node_modules/foreground-child/dist/esm/index.js index 405b3959310fa..d42ba8f31ddd0 100644 --- a/node_modules/foreground-child/dist/mjs/index.js +++ b/node_modules/foreground-child/dist/esm/index.js @@ -1,7 +1,7 @@ import { spawn as nodeSpawn, } from 'child_process'; import crossSpawn from 'cross-spawn'; import { onExit } from 'signal-exit'; -import { allSignals } from './all-signals.js'; +import { proxySignals } from './proxy-signals.js'; import { watchdog } from './watchdog.js'; /* c8 ignore start */ const spawn = process?.platform === 'win32' ? crossSpawn : nodeSpawn; @@ -43,7 +43,6 @@ export function foregroundChild(...fgArgs) { spawnOpts.stdio.push('ipc'); } const child = spawn(program, args, spawnOpts); - const unproxySignals = proxySignals(child); const childHangup = () => { try { child.kill('SIGHUP'); @@ -56,20 +55,18 @@ export function foregroundChild(...fgArgs) { /* c8 ignore stop */ }; const removeOnExit = onExit(childHangup); - const dog = watchdog(child); + proxySignals(child); + watchdog(child); let done = false; child.on('close', async (code, signal) => { - dog.kill('SIGKILL'); /* c8 ignore start */ - if (done) { + if (done) return; - } /* c8 ignore stop */ done = true; const result = cleanup(code, signal); const res = isPromise(result) ? await result : result; removeOnExit(); - unproxySignals(); if (res === false) return; else if (typeof res === 'string') { @@ -112,35 +109,5 @@ export function foregroundChild(...fgArgs) { } return child; } -/** - * Starts forwarding signals to `child` through `parent`. - */ -const proxySignals = (child) => { - const listeners = new Map(); - for (const sig of allSignals) { - const listener = () => { - // some signals can only be received, not sent - try { - child.kill(sig); - /* c8 ignore start */ - } - catch (_) { } - /* c8 ignore stop */ - }; - try { - // if it's a signal this system doesn't recognize, skip it - process.on(sig, listener); - listeners.set(sig, listener); - /* c8 ignore start */ - } - catch (_) { } - /* c8 ignore stop */ - } - return () => { - for (const [sig, listener] of listeners) { - process.removeListener(sig, listener); - } - }; -}; const isPromise = (o) => !!o && typeof o === 'object' && typeof o.then === 'function'; //# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/node_modules/foreground-child/dist/mjs/package.json b/node_modules/foreground-child/dist/esm/package.json similarity index 100% rename from node_modules/foreground-child/dist/mjs/package.json rename to node_modules/foreground-child/dist/esm/package.json diff --git a/node_modules/foreground-child/dist/esm/proxy-signals.js b/node_modules/foreground-child/dist/esm/proxy-signals.js new file mode 100644 index 0000000000000..8e1efe3e301d6 --- /dev/null +++ b/node_modules/foreground-child/dist/esm/proxy-signals.js @@ -0,0 +1,34 @@ +import { allSignals } from './all-signals.js'; +/** + * Starts forwarding signals to `child` through `parent`. + */ +export const proxySignals = (child) => { + const listeners = new Map(); + for (const sig of allSignals) { + const listener = () => { + // some signals can only be received, not sent + try { + child.kill(sig); + /* c8 ignore start */ + } + catch (_) { } + /* c8 ignore stop */ + }; + try { + // if it's a signal this system doesn't recognize, skip it + process.on(sig, listener); + listeners.set(sig, listener); + /* c8 ignore start */ + } + catch (_) { } + /* c8 ignore stop */ + } + const unproxy = () => { + for (const [sig, listener] of listeners) { + process.removeListener(sig, listener); + } + }; + child.on('exit', unproxy); + return unproxy; +}; +//# sourceMappingURL=proxy-signals.js.map \ No newline at end of file diff --git a/node_modules/foreground-child/dist/mjs/watchdog.js b/node_modules/foreground-child/dist/esm/watchdog.js similarity index 79% rename from node_modules/foreground-child/dist/mjs/watchdog.js rename to node_modules/foreground-child/dist/esm/watchdog.js index 3b897a6c4c73f..7aa184ede4f5a 100644 --- a/node_modules/foreground-child/dist/mjs/watchdog.js +++ b/node_modules/foreground-child/dist/esm/watchdog.js @@ -24,6 +24,13 @@ if (!isNaN(pid)) { process.on('SIGHUP', bark) } `; +/** + * Pass in a ChildProcess, and this will spawn a watchdog process that + * will make sure it exits if the parent does, thus preventing any + * dangling detached zombie processes. + * + * If the child ends before the parent, then the watchdog will terminate. + */ export const watchdog = (child) => { let dogExited = false; const dog = spawn(process.execPath, ['-e', watchdogCode, String(child.pid)], { @@ -32,7 +39,7 @@ export const watchdog = (child) => { dog.on('exit', () => (dogExited = true)); child.on('exit', () => { if (!dogExited) - dog.kill('SIGTERM'); + dog.kill('SIGKILL'); }); return dog; }; diff --git a/node_modules/foreground-child/package.json b/node_modules/foreground-child/package.json index dfda32847d990..e157528477c6f 100644 --- a/node_modules/foreground-child/package.json +++ b/node_modules/foreground-child/package.json @@ -1,19 +1,45 @@ { "name": "foreground-child", - "version": "3.1.1", + "version": "3.2.1", "description": "Run a child as if it's the foreground process. Give it stdio. Exit when it exits.", - "main": "./dist/cjs/index.js", - "module": "./dist/mjs/index.js", - "types": "./dist/mjs/index.d.ts", + "main": "./dist/commonjs/index.js", + "types": "./dist/commonjs/index.d.ts", "exports": { + "./watchdog": { + "import": { + "source": "./src/watchdog.ts", + "types": "./dist/esm/watchdog.d.ts", + "default": "./dist/esm/watchdog.js" + }, + "require": { + "source": "./src/watchdog.ts", + "types": "./dist/commonjs/watchdog.d.ts", + "default": "./dist/commonjs/watchdog.js" + } + }, + "./proxy-signals": { + "import": { + "source": "./src/proxy-signals.ts", + "types": "./dist/esm/proxy-signals.d.ts", + "default": "./dist/esm/proxy-signals.js" + }, + "require": { + "source": "./src/proxy-signals.ts", + "types": "./dist/commonjs/proxy-signals.d.ts", + "default": "./dist/commonjs/proxy-signals.js" + } + }, + "./package.json": "./package.json", ".": { "import": { - "types": "./dist/mjs/index.d.ts", - "default": "./dist/mjs/index.js" + "source": "./src/index.ts", + "types": "./dist/esm/index.d.ts", + "default": "./dist/esm/index.js" }, "require": { - "types": "./dist/cjs/index.d.ts", - "default": "./dist/cjs/index.js" + "source": "./src/index.ts", + "types": "./dist/commonjs/index.d.ts", + "default": "./dist/commonjs/index.js" } } }, @@ -31,15 +57,16 @@ "preversion": "npm test", "postversion": "npm publish", "prepublishOnly": "git push origin --follow-tags", - "prepare": "tsc -p tsconfig.json && tsc -p tsconfig-esm.json && bash ./scripts/fixup.sh", + "prepare": "tshy", "pretest": "npm run prepare", "presnap": "npm run prepare", - "test": "c8 tap", - "snap": "c8 tap", - "format": "prettier --write . --loglevel warn", - "typedoc": "typedoc --tsconfig tsconfig-esm.json ./src/*.ts" + "test": "tap", + "snap": "tap", + "format": "prettier --write . --log-level warn", + "typedoc": "typedoc --tsconfig .tshy/esm.json ./src/*.ts" }, "prettier": { + "experimentalTernaries": true, "semi": false, "printWidth": 75, "tabWidth": 2, @@ -51,14 +78,7 @@ "endOfLine": "lf" }, "tap": { - "coverage": false, - "jobs": 1, - "node-arg": [ - "--no-warnings", - "--loader", - "ts-node/esm" - ], - "ts": false + "typecheck": true }, "repository": { "type": "git", @@ -70,14 +90,22 @@ "@types/cross-spawn": "^6.0.2", "@types/node": "^18.15.11", "@types/tap": "^15.0.8", - "c8": "^7.13.0", - "prettier": "^2.8.6", - "tap": "^16.3.4", - "ts-node": "^10.9.1", + "prettier": "^3.3.2", + "tap": "^19.2.5", + "tshy": "^1.15.1", "typedoc": "^0.24.2", "typescript": "^5.0.2" }, "funding": { "url": "https://github.com/sponsors/isaacs" - } + }, + "tshy": { + "exports": { + "./watchdog": "./src/watchdog.ts", + "./proxy-signals": "./src/proxy-signals.ts", + "./package.json": "./package.json", + ".": "./src/index.ts" + } + }, + "type": "module" } diff --git a/package-lock.json b/package-lock.json index 0c535ea21f679..e11a88399d6aa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5592,9 +5592,9 @@ } }, "node_modules/foreground-child": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-3.1.1.tgz", - "integrity": "sha512-TMKDUnIte6bfb5nWv7V/caI169OHgvwjb7V4WkeUvbQQdjr5rWKqHFiKWb/fcOwB+CzBT+qbWjvj+DVwRskpIg==", + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-3.2.1.tgz", + "integrity": "sha512-PXUUyLqrR2XCWICfv6ukppP96sdFwWbNEnfEMt7jNsISjMsvaLNinAHNDYyvkyU+SZG2BTSbT5NjG+vZslfGTA==", "inBundle": true, "license": "ISC", "dependencies": {