Skip to content

Commit

Permalink
fix: process not found on windows (#1013)
Browse files Browse the repository at this point in the history
  • Loading branch information
PinkChampagne17 authored Oct 16, 2023
1 parent b749a27 commit 690af7b
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

1 comment on commit 690af7b

@vercel
Copy link

@vercel vercel bot commented on 690af7b Nov 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

tsup – ./

tsup.vercel.app
tsup-git-main-egoist.vercel.app
tsup-egoist.vercel.app
tsup.egoist.dev

Please sign in to comment.