Skip to content

Commit

Permalink
fix: the process not found on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
PinkChampagne17 committed Oct 5, 2023
1 parent e85437e commit 7bf06a8
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,26 @@ export const defineConfig = (
) => MaybePromise<Options | Options[]>)
) => 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<void>((resolve, reject) => {
kill(pid, signal, (err) => {
if (err) return reject(err)
if (err && !isTaskkillCmdProcessNotFoundError(err)) return reject(err)
resolve()
})
})
Expand Down

0 comments on commit 7bf06a8

Please sign in to comment.