Replace exit-hook with custom event listeners

Instead of relying on the `exit-hook` dependency, we should listen to
`exit`, `SIGINT`, `SIGTERM` and other exceptions, and kill all running
processes.
This commit is contained in:
Sebastian Martinez
2023-12-04 20:14:27 +01:00
parent 23895bd826
commit 0ab1d1ba41
3 changed files with 4 additions and 16 deletions
-13
View File
@@ -48,7 +48,6 @@
"eslint-plugin-no-only-tests": "^3.1.0",
"eslint-plugin-svelte": "^2.35.0",
"execa": "^8.0.1",
"exit-hook": "^4.0.0",
"get-port": "^7.0.0",
"happy-dom": "^12.10.3",
"prettier": "^3.1.0",
@@ -2326,18 +2325,6 @@
"url": "https://github.com/sindresorhus/execa?sponsor=1"
}
},
"node_modules/exit-hook": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/exit-hook/-/exit-hook-4.0.0.tgz",
"integrity": "sha512-Fqs7ChZm72y40wKjOFXBKg7nJZvQJmewP5/7LtePDdnah/+FH9Hp5sgMujSCMPXlxOAW2//1jrW9pnsY7o20vQ==",
"dev": true,
"engines": {
"node": ">=18"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/extend-shallow": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/extend-shallow/-/extend-shallow-2.0.1.tgz",
-1
View File
@@ -38,7 +38,6 @@
"eslint-plugin-no-only-tests": "^3.1.0",
"eslint-plugin-svelte": "^2.35.0",
"execa": "^8.0.1",
"exit-hook": "^4.0.0",
"get-port": "^7.0.0",
"happy-dom": "^12.10.3",
"prettier": "^3.1.0",
+4 -2
View File
@@ -1,7 +1,6 @@
import type { ExecaChildProcess, Options } from "execa";
import * as Stream from "node:stream";
import onExit from "exit-hook";
import { StringDecoder } from "string_decoder";
import { execa } from "execa";
@@ -11,7 +10,9 @@ import { logPrefix } from "./logPrefix.js";
// We add all proxy and node instances that we spawn to this list.
const processes: ExecaChildProcess[] = [];
onExit(killAllProcesses);
process.on("exit", killAllProcesses);
process.on("SIGINT", killAllProcesses);
process.on("SIGTERM", killAllProcesses);
// Kill all processes with SIGKILL
export function killAllProcesses(): void {
@@ -20,6 +21,7 @@ export function killAllProcesses(): void {
process.kill("SIGKILL");
}
}
process.exit();
}
// Spawn a process with `execa` and register it.