这是indexloc提供的服务,不要输入任何密码
Skip to content

fix: process not found on windows #1013

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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