Skip to content

Commit dbc8449

Browse files
committed
refactor(hub): run taskkill through tinyexec
1 parent 8a6ea61 commit dbc8449

1 file changed

Lines changed: 10 additions & 17 deletions

File tree

‎packages/hub/src/node/host-terminals.ts‎

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import type {
1616
DevframeTerminalsHost as DevframeTerminalsHostType,
1717
} from '../types/terminals'
1818
import type { DevframeHubContext } from './context'
19-
import { spawn } from 'node:child_process'
2019
import process from 'node:process'
2120
import { createEventEmitter } from 'devframe/utils/events'
2221
import { HUB_EVENTS } from '../events'
@@ -46,27 +45,21 @@ const PTY_TERM_NAME = 'xterm-256color'
4645
* the real program running (and holding its ports). `taskkill /T /F` ends the
4746
* whole tree; `cp.kill()` stays the fallback and the POSIX path.
4847
*/
49-
function killProcessTree(cp: TinyExecResult): Promise<void> {
48+
async function killProcessTree(cp: TinyExecResult): Promise<void> {
5049
const child = cp.process
5150
const pid = child?.pid
5251
if (process.platform !== 'win32' || !child || pid === undefined || child.exitCode !== null || child.signalCode !== null) {
5352
cp.kill()
54-
return Promise.resolve()
53+
return
5554
}
56-
return new Promise((resolve) => {
57-
let finished = false
58-
const finish = (ok: boolean) => {
59-
if (finished)
60-
return
61-
finished = true
62-
if (!ok)
63-
cp.kill()
64-
resolve()
65-
}
66-
const killer = spawn('taskkill', ['/pid', String(pid), '/T', '/F'], { stdio: 'ignore', windowsHide: true })
67-
killer.once('error', () => finish(false))
68-
killer.once('exit', code => finish(code === 0))
69-
})
55+
const { exec } = await import('tinyexec')
56+
try {
57+
const { exitCode } = await exec('taskkill', ['/pid', String(pid), '/T', '/F'])
58+
if (exitCode === 0)
59+
return
60+
}
61+
catch {}
62+
cp.kill()
7063
}
7164

7265
export class DevframeTerminalsHost implements DevframeTerminalsHostType {

0 commit comments

Comments
 (0)