Repository: remy/nodemon
Pull request #1655 (2019-12-28 23:54:48)

docs: changed logging and docs to reflect support for single file watching
When watching for single files with the `--watch`  or JSON `watch` functionality and with verbose logging enabled, nodemon logs "watching dir(s)" when not all rules may be directories. This initially threw me off to believe that nodemon did _not_ support watching single files, which upon further review, is clearly not the case (i.e. single file works as intended).

Example output:
```
[nodemon] 1.19.4
[nodemon] reading config ./nodemon.json
[nodemon] to restart at any time, enter `rs`
[nodemon] watching dir(s): src/next.config.js src/server.ts
[nodemon] watching extensions: js,ts
[nodemon] starting `yarn run start:development:docker`
[nodemon] spawning
[nodemon] child pid: 44
[nodemon] watching 2 files
```

This pull request fixes these typos to "path(s)" in the verbose logging and "path" in the CLI documentation.

stale[bot]: This issue has been automatically marked as idle and stale because it hasn't had any recent activity. It will be automtically closed if no further activity occurs. If you think this is wrong, or the problem still persists, just pop a reply in the comments and @remy will (try!) to follow up.
Thank you for contributing <3

concision: Not stale

Patch:
diff --git a/doc/cli/help.txt b/doc/cli/help.txt
index 4d34ae1..7ba4ff2 100644
--- a/doc/cli/help.txt
+++ b/doc/cli/help.txt
@@ -5,7 +5,7 @@
   --config file ............ alternate nodemon.json config file to use
   -e, --ext ................ extensions to look for, ie. js,pug,hbs.
   -x, --exec app ........... execute script with "app", ie. -x "python -v".
-  -w, --watch path.......... watch directory "path" or files. use once for
+  -w, --watch path ......... watch directory "path" or files. use once for
                              each directory or file to watch.
   -i, --ignore ............. ignore specific files or directories.
   -V, --verbose ............ show detail on what is causing restarts.
diff --git a/doc/cli/options.txt b/doc/cli/options.txt
index af0edb5..598ae63 100644
--- a/doc/cli/options.txt
+++ b/doc/cli/options.txt
@@ -5,7 +5,7 @@ Configuration
   -i, --ignore ............. ignore specific files or directories
   --no-colors .............. disable color output
   --signal <signal> ........ use specified kill signal instead of default (ex. SIGTERM)
-  -w, --watch dir........... watch directory "dir" or files. use once for each
+  -w, --watch path ......... watch directory "dir" or files. use once for each
                              directory or file to watch
   --no-update-notifier ..... opt-out of update version check
 
diff --git a/lib/nodemon.js b/lib/nodemon.js
index 0f60e59..b3badea 100644
--- a/lib/nodemon.js
+++ b/lib/nodemon.js
@@ -180,7 +180,7 @@ function nodemon(settings) {
     }).filter(Boolean).join(' ');
     if (ignoring) utils.log.detail('ignoring: ' + ignoring);
 
-    utils.log.info('watching dir(s): ' + config.options.monitor.map(function (rule) {
+    utils.log.info('watching path(s): ' + config.options.monitor.map(function (rule) {
       if (rule.slice(0, 1) !== '!') {
         try {
           rule = path.relative(process.cwd(), rule);


Test patch:
diff --git a/test/fixtures/sigint.js b/test/fixtures/sigint.js
index fe98422..64192f1 100644
--- a/test/fixtures/sigint.js
+++ b/test/fixtures/sigint.js
@@ -1,5 +1,6 @@
 process.on('SIGINT', function() {
-  // do nothing here
+  if (process.argv.length === 3 && process.argv[2] === '--dont-exit') return;
+  process.exit();
 });
 // timer, to keep process running
 setInterval(function() {
diff --git a/test/misc/sigint.test.js b/test/misc/sigint.test.js
index b072835..6fa8ca7 100644
--- a/test/misc/sigint.test.js
+++ b/test/misc/sigint.test.js
@@ -6,42 +6,51 @@ var utils = require('../utils'),
     appjs = path.relative(process.cwd(), path.resolve(__dirname, '..', 'fixtures', 'sigint.js')),
     match = utils.match,
     cleanup = utils.cleanup,
-    run = utils.run;
+    run = utils.run,
+    isRunning = utils.isRunning;
 
-describe('terminal signals', function () {
-  it('should kill child with SIGINT (after ~10 seconds)', function (done) {
-    var childPID = null;
+function runAndKill(done, cmdline, exitcb)
+{
+  var childPID = null;
 
-    var p = run(appjs, {
-      output: function (data) {
-        if (match(data, 'pid: ')) {
-          data.replace(/pid: (\d+)/, function (m) {
-            childPID = m;
-          });
-        }
-      },
-      error: function (data) {
-        assert(false, 'nodemon failed with ' + data);
-        cleanup(p, done);
+  var p = run(cmdline, {
+    output: function (data) {
+      if (match(data, 'pid: ')) {
+        data.replace(/pid: (\d+)/, function (_, p1) {
+          childPID = p1;
+        });
       }
-    });
+    },
+    error: function (data) {
+      assert(false, 'nodemon failed with ' + data);
+      cleanup(p, done);
+    }
+  });
 
-    p.on('message', function (event) {
-      if (event.type === 'start') {
-        setTimeout(function () {
-          p.kill('SIGINT');
-        }, 1000);
-      }
-    }).on('exit', function () {
-      // check if the child process is still running
-      try {
-        process.kill(childPID, 0);
-        assert(false, 'child is still running at ' + childPID);
-      } catch (e) {
-        assert(true, 'child process was not running');
-      }
+  p.on('message', function (event) {
+    if (event.type === 'start') {
+      setTimeout(function () {
+       p.kill('SIGINT');
+      }, 1000);
+    }
+  }).on('exit', function () {
+    exitcb(childPID);
+  });
+}
+
+describe('terminal signals', function () {
+  it('should kill child with SIGINT', function (done) {
+    runAndKill(done, appjs, function (childPID) {
+      assert(!isRunning(childPID), 'child is still running at ' + childPID);
       done();
     });
   });
 
+  it('should terminate nodemon (after ~10 seconds)', function (done) {
+    runAndKill(done, appjs + ' --dont-exit', function (childPID) {
+      // make sure we don't keep abandoned child
+      process.kill(childPID, 'SIGTERM');
+      done();
+    });
+  });
 });
diff --git a/test/utils.js b/test/utils.js
index 4a96c92..f579a20 100644
--- a/test/utils.js
+++ b/test/utils.js
@@ -121,6 +121,16 @@ function getTriggerCount(msg) {
   return changes.pop();
 }
 
+function isRunning(pid) {
+  try {
+    process.kill(pid, 0)
+    return true
+  } catch (error) {
+    if (error.code && error.code === 'ESRCH') return false
+    throw error
+  }
+}
+
 module.exports = {
   getTriggerCount: getTriggerCount,
   Plan: Plan,
@@ -132,4 +142,5 @@ module.exports = {
   appcoffee: appcoffee,
   monitorForChange: monitorForChange,
   port: port,
+  isRunning: isRunning
 };