From 0ab1d1ba41a9e3672eb0833df869ddc84f4ccfaf Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Mon, 4 Dec 2023 16:28:05 +0100 Subject: [PATCH] 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. --- package-lock.json | 13 ------------- package.json | 1 - tests/support/process.ts | 6 ++++-- 3 files changed, 4 insertions(+), 16 deletions(-) diff --git a/package-lock.json b/package-lock.json index fc746621c..3aa6ddf9c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/package.json b/package.json index 5540d8194..56399052a 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/tests/support/process.ts b/tests/support/process.ts index 34d541549..f4d28b5a4 100644 --- a/tests/support/process.ts +++ b/tests/support/process.ts @@ -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.