diff --git a/src/index.ts b/src/index.ts index f6d4ce700..0a542f800 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() }) })