Skip to content

Commit 9114c74

Browse files
committed
rmv ps-tree
1 parent ea217b5 commit 9114c74

File tree

3 files changed

+10
-100
lines changed

3 files changed

+10
-100
lines changed

packages/cli/lib/testing.ts

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import process from 'node:process';
44
import degit from 'degit';
55
import { exec } from 'tinyexec';
66
import { create } from '@sveltejs/create';
7-
import pstree, { type PS } from 'ps-tree';
87

98
export { addPnpmBuildDependencies } from '../utils/package-manager.ts';
109
export type ProjectVariant = 'kit-js' | 'kit-ts' | 'vite-js' | 'vite-ts';
@@ -122,31 +121,18 @@ export async function startPreview({
122121
});
123122
}
124123

125-
async function getProcessTree(pid: number) {
126-
return new Promise<readonly PS[]>((res, rej) => {
127-
pstree(pid, (err, children) => {
128-
if (err) rej(err);
129-
res(children);
130-
});
131-
});
132-
}
133-
134124
async function terminate(pid: number) {
135-
const children = await getProcessTree(pid);
136-
// the process tree is ordered from parents -> children,
137-
// so we'll iterate in the reverse order to terminate the children first
138-
for (let i = children.length - 1; i >= 0; i--) {
139-
const child = children[i];
140-
const pid = Number(child.PID);
141-
kill(pid);
142-
}
143-
kill(pid);
144-
}
145-
146-
function kill(pid: number) {
147125
try {
148-
process.kill(pid);
126+
if (process.platform === 'win32') {
127+
await exec(`taskkill /pid ${pid} /T /F`); // on windows, use taskkill to terminate the process tree
128+
} else {
129+
process.kill(-pid, 'SIGTERM'); // Kill the process group
130+
}
149131
} catch {
150-
// this can happen if a process has been automatically terminated.
132+
try {
133+
process.kill(pid, 'SIGTERM'); // Kill just the process
134+
} catch {
135+
// Process might already be terminated
136+
}
151137
}
152138
}

packages/cli/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,11 @@
3535
"@sveltejs/cli-core": "workspace:*",
3636
"@sveltejs/create": "workspace:*",
3737
"@types/degit": "^2.8.6",
38-
"@types/ps-tree": "^1.1.6",
3938
"commander": "^13.1.0",
4039
"degit": "^2.8.4",
4140
"empathic": "^1.1.0",
4241
"package-manager-detector": "^0.2.11",
4342
"picocolors": "^1.1.1",
44-
"ps-tree": "^1.2.0",
4543
"tinyexec": "^0.3.2",
4644
"valibot": "^0.41.0"
4745
},

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)