diff --git a/src/node/cli-start.ts b/src/node/cli-start.ts index b014dd7..b3e2886 100644 --- a/src/node/cli-start.ts +++ b/src/node/cli-start.ts @@ -1,5 +1,4 @@ import { cac } from 'cac' -import consola from 'consola' import { name, version } from '../../package.json' import { build, serve } from './index' @@ -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)