Skip to content

Commit ebe0823

Browse files
committed
refactor: remove tree-kill dependency and refactor killAllProcesses to use native childProc.kill.
Remove last `tree-kill` package usage.
1 parent b47078f commit ebe0823

File tree

4 files changed

+22
-26
lines changed

4 files changed

+22
-26
lines changed

pnpm-lock.yaml

Lines changed: 0 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/e2e/utils/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,5 @@ ts_project(
2020
"//:node_modules/verdaccio-auth-memory",
2121
"//tests:node_modules/@types/tar-stream",
2222
"//tests:node_modules/tar-stream",
23-
"//tests:node_modules/tree-kill",
2423
],
2524
)

tests/e2e/utils/process.ts

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { spawn, SpawnOptions } from 'node:child_process';
22
import * as child_process from 'node:child_process';
33
import { getGlobalVariable, getGlobalVariablesEnv } from './env';
4-
import treeKill from 'tree-kill';
54
import { delimiter, join, resolve } from 'node:path';
65
import { stripVTControlCharacters, styleText } from 'node:util';
76

@@ -255,26 +254,34 @@ export async function waitForAnyProcessOutputToMatch(
255254
return matchingProcess;
256255
}
257256

258-
export async function killAllProcesses(signal = 'SIGTERM'): Promise<void> {
257+
/**
258+
* Kills a process by PID
259+
* @param pid The PID of the process to kill
260+
* @param signal The signal to send to the process
261+
*/
262+
async function killProcess(pid: number, signal: NodeJS.Signals): Promise<void> {
263+
if (process.platform === 'win32') {
264+
// /T kills child processes, /F forces it
265+
await exec(`taskkill /pid ${pid} /T /F`);
266+
} else {
267+
// Use -pid to signal the entire process group
268+
process.kill(-pid, signal);
269+
}
270+
}
271+
272+
/**
273+
* Kills all tracked processes
274+
*/
275+
export async function killAllProcesses(signal: NodeJS.Signals = 'SIGTERM'): Promise<void> {
259276
const processesToKill: Promise<void>[] = [];
260277

261278
while (_processes.length) {
262279
const childProc = _processes.pop();
263-
if (!childProc || childProc.pid === undefined) {
280+
if (!childProc || childProc.pid === undefined || childProc.killed) {
264281
continue;
265282
}
266283

267-
processesToKill.push(
268-
new Promise<void>((resolve) => {
269-
treeKill(childProc.pid!, signal, () => {
270-
// Ignore all errors.
271-
// This is due to a race condition with the `waitForMatch` logic.
272-
// where promises are resolved on matches and not when the process terminates.
273-
// Also in some cases in windows we get `The operation attempted is not supported`.
274-
resolve();
275-
});
276-
}),
277-
);
284+
processesToKill.push(killProcess(childProc.pid, signal));
278285
}
279286

280287
await Promise.all(processesToKill);

tests/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"devDependencies": {
33
"@types/tar-stream": "3.1.4",
44
"@angular-devkit/schematics": "workspace:*",
5-
"tar-stream": "3.1.7",
6-
"tree-kill": "1.2.2"
5+
"tar-stream": "3.1.7"
76
}
87
}

0 commit comments

Comments
 (0)