fix(cli): handle different kind of shutdown signals (#19485)

This commit is contained in:
pooya parsa 2023-03-06 15:42:20 +01:00 committed by GitHub
parent d4f443abfb
commit 4f61e36c6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 4 deletions

View File

@ -16,13 +16,19 @@ if (process.argv[2] === 'dev') {
}
function startSubprocess () {
let childProc: ChildProcess
let childProc: ChildProcess | undefined
process.on('exit', () => {
const onShutdown = () => {
if (childProc) {
childProc.kill()
childProc = undefined
}
})
}
process.on('exit', onShutdown)
process.on('SIGTERM', onShutdown) // Graceful shutdown
process.on('SIGINT', onShutdown) // Ctrl-C
process.on('SIGQUIT', onShutdown) // Ctrl-\
start()
@ -31,7 +37,7 @@ function startSubprocess () {
childProc.on('close', (code) => { if (code) { process.exit(code) } })
childProc.on('message', (message) => {
if ((message as { type: string })?.type === 'nuxt:restart') {
childProc.kill()
childProc?.kill()
startSubprocess()
}
})