From 690af7b89939c0b4d4e02549c3ed90a1d9c8c50b Mon Sep 17 00:00:00 2001 From: Pink Champagne <45930107+PinkChampagne17@users.noreply.github.com> Date: Mon, 16 Oct 2023 20:53:10 +0800 Subject: [PATCH] fix: process not found on windows (#1013) --- src/index.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index f6d4ce70..0a542f80 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() }) })