Skip to content

Commit

Permalink
fix: only handle SIGINT, implemented like vite
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaskuske committed Aug 13, 2022
1 parent 683912d commit c9ebd92
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/node/cli-start.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { cac } from 'cac'
import consola from 'consola'
import { name, version } from '../../package.json'
import { build, serve } from './index'

Expand Down Expand Up @@ -33,15 +32,16 @@ export async function startCli(cwd = process.cwd(), argv = process.argv) {
.action(async (file: string, options: { watch: false | string | string[]; port: number; outDir?: string }) => {
const server = await serve({ cwd, entry: file, ...options })

const close = () => server.httpServer?.listening && server.close()

process.on('SIGINT', () => close())
process.on('exit', () => close())
process.on('uncaughtException', (err) => {
consola.error(err)
process.exitCode = 1
close()
})
// Vite handles SIGTERM and end of stdin (Ctrl+D) itself, but not SIGINT
const exitProcess = async () => {
try {
await server.close()
}
finally {
process.exit()
}
}
process.once('SIGINT', exitProcess)
})

// Filter out unnecessary "default" output for negated options (zerobyte acts as marker)
Expand Down

0 comments on commit c9ebd92

Please sign in to comment.