From f8a5abe258ae3a224cb0a0566e70aa8cf5bfe19e Mon Sep 17 00:00:00 2001 From: Remy Sharp Date: Thu, 14 Dec 2017 23:28:41 +0000 Subject: [PATCH] feat: watch script regardless of extension Fixes the issue where express is a js based project, but the executable is `www`, so it misses on the match. So now nodemon will watch for matching extensions but *also* the script the user gave. Fixes #461 Note that this can't handle the situation where npm is used to run `node ./bin/www` as nodemon can't split out a package script command. --- lib/monitor/watch.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/monitor/watch.js b/lib/monitor/watch.js index 68220b54..09c334df 100644 --- a/lib/monitor/watch.js +++ b/lib/monitor/watch.js @@ -24,7 +24,6 @@ function resetWatchers() { watchers = []; } - function watch() { if (watchers.length) { debug('early exit on watch, still watching (%s)', watchers.length); @@ -141,6 +140,22 @@ function filterAndRestart(files) { undefsafe(config, 'options.execOptions.ext') ); + // if there's no matches, then test to see if the changed file is the + // running script, if so, let's allow a restart + const script = path.resolve(config.options.execOptions.script); + if (matched.result.length === 0 && script) { + const length = script.length; + files.find(file => { + if (file.substr(-length, length) === script) { + matched = { + result: [ file ], + total: 1, + } + return true; + } + }) + } + utils.log.detail('changes after filters (before/after): ' + [files.length, matched.result.length].join('/'));