Skip to content

Commit 30f999a

Browse files
committed
feat: support SIGHUP to restart nodemon
Also small linting tweaks and typos in comments. Fixes #393
1 parent a282afb commit 30f999a

File tree

5 files changed

+36
-51
lines changed

5 files changed

+36
-51
lines changed

Dockerfile

Lines changed: 0 additions & 19 deletions
This file was deleted.

lib/config/defaults.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ module.exports = {
1616
stdin: true,
1717
runOnChangeOnly: false,
1818
verbose: false,
19+
signal: 'SIGUSR2',
1920
// 'stdout' refers to the default behaviour of a required nodemon's child,
2021
// but also includes stderr. If this is false, data is still dispatched via
2122
// nodemon.on('stdout/stderr')

lib/config/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ var config = {
3131
dirs: [],
3232
timeout: 1000,
3333
options: {},
34-
signal: 'SIGUSR2',
3534
};
3635

3736
/**
@@ -59,7 +58,7 @@ config.load = function (settings, ready) {
5958
}
6059

6160
config.watchInterval = options.watchInterval || null;
62-
if (options['signal']) { // jshint ignore:line
61+
if (options.signal) {
6362
config.signal = options.signal;
6463
}
6564

lib/nodemon.js

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -135,21 +135,23 @@ function nodemon(settings) {
135135
config.options.restartable + '`');
136136
}
137137

138-
var none = function (v) {
139-
return v;
140-
};
138+
if (!config.required) {
139+
const restartSignal = config.options.signal === 'SIGUSR2' ? 'SIGHUP' : 'SIGUSR2';
140+
process.on(restartSignal, nodemon.restart);
141+
utils.log.detail((config.options.restartable ? 'or ' : '') + 'send ' +
142+
restartSignal + ' to ' + process.pid + ' to restart');
143+
}
141144

142145
utils.log.detail('ignoring: ' + config.options.monitor.map(function (rule) {
143146
return rule.slice(0, 1) === '!' ? rule.slice(1) : false;
144-
}).filter(none).join(' '));
147+
}).filter(Boolean).join(' '));
145148

146149
utils.log.info('watching: ' + config.options.monitor.map(function (rule) {
147150
return rule.slice(0, 1) !== '!' ? rule : false;
148-
}).filter(none).join(' '));
151+
}).filter(Boolean).join(' '));
149152

150153
utils.log.detail('watching extensions: ' + config.options.execOptions.ext);
151154

152-
153155
if (config.options.dump) {
154156
utils.log._log('log', '--------------');
155157
utils.log._log('log', 'node: ' + process.version);
@@ -164,33 +166,35 @@ function nodemon(settings) {
164166
process.exit();
165167
}
166168

167-
} else {
168-
config.run = true;
169+
return;
170+
}
169171

170-
if (config.options.stdout === false) {
171-
nodemon.on('start', function () {
172-
nodemon.stdout = bus.stdout;
173-
nodemon.stderr = bus.stderr;
172+
config.run = true;
174173

175-
bus.emit('readable');
176-
});
177-
}
174+
if (config.options.stdout === false) {
175+
nodemon.on('start', function () {
176+
nodemon.stdout = bus.stdout;
177+
nodemon.stderr = bus.stderr;
178178

179-
if (config.options.events && Object.keys(config.options.events).length) {
180-
Object.keys(config.options.events).forEach(function (key) {
181-
utils.log.detail('bind ' + key + ' -> `' +
182-
config.options.events[key] + '`');
183-
nodemon.on(key, function () {
184-
if (config.options && config.options.events) {
185-
spawn(config.options.events[key], config,
186-
[].slice.apply(arguments));
187-
}
188-
});
189-
});
190-
}
179+
bus.emit('readable');
180+
});
181+
}
191182

192-
monitor.run(config.options);
183+
if (config.options.events && Object.keys(config.options.events).length) {
184+
Object.keys(config.options.events).forEach(function (key) {
185+
utils.log.detail('bind ' + key + ' -> `' +
186+
config.options.events[key] + '`');
187+
nodemon.on(key, function () {
188+
if (config.options && config.options.events) {
189+
spawn(config.options.events[key], config,
190+
[].slice.apply(arguments));
191+
}
192+
});
193+
});
193194
}
195+
196+
monitor.run(config.options);
197+
194198
});
195199

196200
return nodemon;

lib/rules/add.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ var reAsterisk = /\*/g;
1313
module.exports = add;
1414

1515
/**
16-
* Coverts file patterns or regular expressions to nodemon
16+
* Converts file patterns or regular expressions to nodemon
1717
* compatible RegExp matching rules. Note: the `rules` argument
1818
* object is modified to include the new rule and new RegExp
1919
*
@@ -86,4 +86,4 @@ function add(rules, which, rule) {
8686
// used for the directory matching
8787
rules[which].re = new RegExp(re);
8888
}
89-
}
89+
}

0 commit comments

Comments
 (0)