Skip to content

Commit 690af7b

Browse files
fix: process not found on windows (#1013)
1 parent b749a27 commit 690af7b

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/index.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,26 @@ export const defineConfig = (
3535
) => MaybePromise<Options | Options[]>)
3636
) => options
3737

38+
/**
39+
* tree-kill use `taskkill` command on Windows to kill the process,
40+
* it may return 128 as exit code when the process has already exited.
41+
* @see https://github.com/egoist/tsup/issues/976
42+
*/
43+
const isTaskkillCmdProcessNotFoundError = (err: Error) => {
44+
return (
45+
process.platform === 'win32' &&
46+
'cmd' in err &&
47+
'code' in err &&
48+
typeof err.cmd === 'string' &&
49+
err.cmd.startsWith('taskkill') &&
50+
err.code === 128
51+
)
52+
}
53+
3854
const killProcess = ({ pid, signal }: { pid: number; signal: KILL_SIGNAL }) =>
3955
new Promise<void>((resolve, reject) => {
4056
kill(pid, signal, (err) => {
41-
if (err) return reject(err)
57+
if (err && !isTaskkillCmdProcessNotFoundError(err)) return reject(err)
4258
resolve()
4359
})
4460
})

0 commit comments

Comments
 (0)