From cee65cf0913c7b485bced03badaa266fdc799a61 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 7 Jun 2022 14:47:32 +0500 Subject: [PATCH] add --kill timeout option --- lib/cli.js | 2 +- lib/index.js | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/cli.js b/lib/cli.js index 4edc038..7704fa2 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -15,7 +15,7 @@ const nodeCustom = ['inspect', 'inspect-brk', 'no-warnings']; const nodeString = ['require']; const nodeDevBoolean = ['clear', 'dedupe', 'fork', 'notify', 'poll', 'respawn', 'vm']; -const nodeDevNumber = ['debounce', 'deps', 'interval']; +const nodeDevNumber = ['debounce', 'deps', 'interval', 'kill']; const nodeDevString = ['graceful_ipc', 'ignore', 'timestamp']; const alias = Object.assign({}, nodeAlias); diff --git a/lib/index.js b/lib/index.js index 75dac54..16ce564 100644 --- a/lib/index.js +++ b/lib/index.js @@ -24,6 +24,7 @@ module.exports = function ( graceful_ipc: gracefulIPC, ignore, interval, + kill, notify: notifyEnabled, poll: forcePolling, respawn, @@ -60,11 +61,21 @@ module.exports = function ( const watcher = filewatcher({ debounce, forcePolling, interval }); let isPaused = false; + let killTimer = 0; // The child_process let child; watcher.on('change', file => { + if (isPaused) return; + + if (typeof kill === 'number') { + killTimer = setTimeout(() => { + console.log(`Sending SIGKILL after timeout (${kill} sec)`); + child.kill('SIGKILL'); + }, kill * 1000); + } + clearOutput(); notify('Restarting', `${file} has been modified`); watcher.removeAll(); @@ -91,7 +102,7 @@ module.exports = function ( */ function start() { isPaused = false; - + clearTimeout(killTimer); const args = nodeArgs.slice(); args.push(`--require=${resolveMain(localPath('wrap'))}`);