watch: add `--watch-kill-signal` flag · nodejs/node@4dc6b4c · GitHub
Skip to content

Commit 4dc6b4c

Browse files
dario-piotrowiczaduh95
authored andcommitted
watch: add --watch-kill-signal flag
add the new `--watch-kill-signal` to allow users to customize what signal is sent to the process on restarts during watch mode PR-URL: #58719 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
1 parent e24dede commit 4dc6b4c

6 files changed

Lines changed: 147 additions & 2 deletions

File tree

doc/api/cli.md

Lines changed: 14 additions & 0 deletions

doc/node-config-schema.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,9 @@
568568
"watch": {
569569
"type": "boolean"
570570
},
571+
"watch-kill-signal": {
572+
"type": "string"
573+
},
571574
"watch-path": {
572575
"oneOf": [
573576
{

lib/internal/main/watch_mode.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const {
2020
const { getOptionValue } = require('internal/options');
2121
const { FilesWatcher } = require('internal/watch_mode/files_watcher');
2222
const { green, blue, red, white, clear } = require('internal/util/colors');
23+
const { convertToValidSignal } = require('internal/util');
2324

2425
const { spawn } = require('child_process');
2526
const { inspect } = require('util');
@@ -30,8 +31,7 @@ const { once } = require('events');
3031
prepareMainThreadExecution(false, false);
3132
markBootstrapComplete();
3233

33-
// TODO(MoLow): Make kill signal configurable
34-
const kKillSignal = 'SIGTERM';
34+
const kKillSignal = convertToValidSignal(getOptionValue('--watch-kill-signal'));
3535
const kShouldFilterModules = getOptionValue('--watch-path').length === 0;
3636
const kEnvFile = getOptionValue('--env-file') || getOptionValue('--env-file-if-exists');
3737
const kWatchedPaths = ArrayPrototypeMap(getOptionValue('--watch-path'), (path) => resolve(path));

src/node_options.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,11 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
862862
"path to watch",
863863
&EnvironmentOptions::watch_mode_paths,
864864
kAllowedInEnvvar);
865+
AddOption("--watch-kill-signal",
866+
"kill signal to send to the process on watch mode restarts"
867+
"(default: SIGTERM)",
868+
&EnvironmentOptions::watch_mode_kill_signal,
869+
kAllowedInEnvvar);
865870
AddOption("--watch-preserve-output",
866871
"preserve outputs on watch mode restart",
867872
&EnvironmentOptions::watch_mode_preserve_output,

src/node_options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ class EnvironmentOptions : public Options {
229229
bool watch_mode = false;
230230
bool watch_mode_report_to_parent = false;
231231
bool watch_mode_preserve_output = false;
232+
std::string watch_mode_kill_signal = "SIGTERM";
232233
std::vector<std::string> watch_mode_paths;
233234

234235
bool syntax_check_only = false;
Lines changed: 122 additions & 0 deletions

0 commit comments

Comments
 (0)