From 3ffb036627c4a57b74d636c114ca94124b991ba5 Mon Sep 17 00:00:00 2001 From: "Fred K. Schott" Date: Wed, 3 Jun 2020 12:33:41 -0700 Subject: [PATCH] improve handling of process exit --- package.json | 1 + src/commands/dev.ts | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index cafce17389..706278a25f 100644 --- a/package.json +++ b/package.json @@ -83,6 +83,7 @@ "resolve-from": "^5.0.0", "rimraf": "^3.0.0", "rollup": "^2.3.0", + "signal-exit": "^3.0.3", "strip-comments": "^2.0.1", "tar": "^6.0.1", "validate-npm-package-name": "^3.0.0", diff --git a/src/commands/dev.ts b/src/commands/dev.ts index 1ce7b16324..29c8f19a69 100644 --- a/src/commands/dev.ts +++ b/src/commands/dev.ts @@ -38,6 +38,7 @@ import npmRunPath from 'npm-run-path'; import os from 'os'; import path from 'path'; import url from 'url'; +import onProcessExit from 'signal-exit'; import detectPort from 'detect-port'; import {BuildScript, SnowpackPluginBuildResult} from '../config'; import {EsmHmrEngine} from '../hmr-server-engine'; @@ -777,9 +778,8 @@ export async function command(commandOptions: CommandOptions) { watcher.on('change', (fileLoc) => onWatchEvent(fileLoc)); watcher.on('unlink', (fileLoc) => onWatchEvent(fileLoc)); - process.on('SIGINT', () => { + onProcessExit(() => { hmrEngine.disconnectAllClients(); - process.exit(0); }); console.log = (...args) => {