From 30f999a06cac8252180ee6df46a9d22659163ea1 Mon Sep 17 00:00:00 2001 From: Remy Sharp Date: Thu, 14 Dec 2017 21:56:17 +0000 Subject: [PATCH] feat: support SIGHUP to restart nodemon Also small linting tweaks and typos in comments. Fixes #393 --- Dockerfile | 19 ------------- lib/config/defaults.js | 1 + lib/config/index.js | 3 +-- lib/nodemon.js | 60 ++++++++++++++++++++++-------------------- lib/rules/add.js | 4 +-- 5 files changed, 36 insertions(+), 51 deletions(-) delete mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 990c12e0..00000000 --- a/Dockerfile +++ /dev/null @@ -1,19 +0,0 @@ -FROM ubuntu:12.04 -MAINTAINER Remy Sharp - -RUN rm /bin/sh && ln -s /bin/bash /bin/sh -RUN apt-get update && apt-get install curl npm -y - -ENV NVM_DIR /usr/local/nvm -ENV NODE_VERSION 4 -ENV NVM_VERSION 0.26.1 -ENV TRAVIS TRUE - -# # Install nvm with node and npm -RUN curl https://raw.githubusercontent.com/creationix/nvm/v$NVM_VERSION/install.sh | bash \ - && source $NVM_DIR/nvm.sh \ - && nvm install 0.10 \ - && nvm install 0.12 \ - && nvm install 4 \ - && nvm alias default $NODE_VERSION \ - && nvm use default diff --git a/lib/config/defaults.js b/lib/config/defaults.js index 622c71b5..9a55b215 100644 --- a/lib/config/defaults.js +++ b/lib/config/defaults.js @@ -16,6 +16,7 @@ module.exports = { stdin: true, runOnChangeOnly: false, verbose: false, + signal: 'SIGUSR2', // 'stdout' refers to the default behaviour of a required nodemon's child, // but also includes stderr. If this is false, data is still dispatched via // nodemon.on('stdout/stderr') diff --git a/lib/config/index.js b/lib/config/index.js index 12b6b651..aae238ee 100644 --- a/lib/config/index.js +++ b/lib/config/index.js @@ -31,7 +31,6 @@ var config = { dirs: [], timeout: 1000, options: {}, - signal: 'SIGUSR2', }; /** @@ -59,7 +58,7 @@ config.load = function (settings, ready) { } config.watchInterval = options.watchInterval || null; - if (options['signal']) { // jshint ignore:line + if (options.signal) { config.signal = options.signal; } diff --git a/lib/nodemon.js b/lib/nodemon.js index 92982321..5e5f4e81 100644 --- a/lib/nodemon.js +++ b/lib/nodemon.js @@ -135,21 +135,23 @@ function nodemon(settings) { config.options.restartable + '`'); } - var none = function (v) { - return v; - }; + if (!config.required) { + const restartSignal = config.options.signal === 'SIGUSR2' ? 'SIGHUP' : 'SIGUSR2'; + process.on(restartSignal, nodemon.restart); + utils.log.detail((config.options.restartable ? 'or ' : '') + 'send ' + + restartSignal + ' to ' + process.pid + ' to restart'); + } utils.log.detail('ignoring: ' + config.options.monitor.map(function (rule) { return rule.slice(0, 1) === '!' ? rule.slice(1) : false; - }).filter(none).join(' ')); + }).filter(Boolean).join(' ')); utils.log.info('watching: ' + config.options.monitor.map(function (rule) { return rule.slice(0, 1) !== '!' ? rule : false; - }).filter(none).join(' ')); + }).filter(Boolean).join(' ')); utils.log.detail('watching extensions: ' + config.options.execOptions.ext); - if (config.options.dump) { utils.log._log('log', '--------------'); utils.log._log('log', 'node: ' + process.version); @@ -164,33 +166,35 @@ function nodemon(settings) { process.exit(); } - } else { - config.run = true; + return; + } - if (config.options.stdout === false) { - nodemon.on('start', function () { - nodemon.stdout = bus.stdout; - nodemon.stderr = bus.stderr; + config.run = true; - bus.emit('readable'); - }); - } + if (config.options.stdout === false) { + nodemon.on('start', function () { + nodemon.stdout = bus.stdout; + nodemon.stderr = bus.stderr; - if (config.options.events && Object.keys(config.options.events).length) { - Object.keys(config.options.events).forEach(function (key) { - utils.log.detail('bind ' + key + ' -> `' + - config.options.events[key] + '`'); - nodemon.on(key, function () { - if (config.options && config.options.events) { - spawn(config.options.events[key], config, - [].slice.apply(arguments)); - } - }); - }); - } + bus.emit('readable'); + }); + } - monitor.run(config.options); + if (config.options.events && Object.keys(config.options.events).length) { + Object.keys(config.options.events).forEach(function (key) { + utils.log.detail('bind ' + key + ' -> `' + + config.options.events[key] + '`'); + nodemon.on(key, function () { + if (config.options && config.options.events) { + spawn(config.options.events[key], config, + [].slice.apply(arguments)); + } + }); + }); } + + monitor.run(config.options); + }); return nodemon; diff --git a/lib/rules/add.js b/lib/rules/add.js index d2e18276..de85bb7f 100644 --- a/lib/rules/add.js +++ b/lib/rules/add.js @@ -13,7 +13,7 @@ var reAsterisk = /\*/g; module.exports = add; /** - * Coverts file patterns or regular expressions to nodemon + * Converts file patterns or regular expressions to nodemon * compatible RegExp matching rules. Note: the `rules` argument * object is modified to include the new rule and new RegExp * @@ -86,4 +86,4 @@ function add(rules, which, rule) { // used for the directory matching rules[which].re = new RegExp(re); } -} \ No newline at end of file +}