From 7bf06a88543ff4567b8a4b53f6143b0091ef1668 Mon Sep 17 00:00:00 2001 From: Pink Champagne <45930107+PinkChampagne17@users.noreply.github.com> Date: Thu, 5 Oct 2023 14:29:04 +0800 Subject: [PATCH] fix: the process not found on Windows --- src/index.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 0eecc990..157df252 100644 --- a/src/index.ts +++ b/src/index.ts @@ -35,10 +35,26 @@ export const defineConfig = ( ) => MaybePromise) ) => options +/** + * tree-kill use `taskkill` command on Windows to kill the process, + * it may return 128 as exit code when the process has already exited. + * @see https://github.com/egoist/tsup/issues/976 + */ +const isTaskkillCmdProcessNotFoundError = (err: Error) => { + return ( + process.platform === 'win32' && + 'cmd' in err && + 'code' in err && + typeof err.cmd === 'string' && + err.cmd.startsWith('taskkill') && + err.code === 128 + ) +} + const killProcess = ({ pid, signal }: { pid: number; signal: KILL_SIGNAL }) => new Promise((resolve, reject) => { kill(pid, signal, (err) => { - if (err) return reject(err) + if (err && !isTaskkillCmdProcessNotFoundError(err)) return reject(err) resolve() }) })