Skip to content

Commit f8a5abe

Browse files
committed
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.
1 parent 30f999a commit f8a5abe

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

lib/monitor/watch.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ function resetWatchers() {
2424
watchers = [];
2525
}
2626

27-
2827
function watch() {
2928
if (watchers.length) {
3029
debug('early exit on watch, still watching (%s)', watchers.length);
@@ -141,6 +140,22 @@ function filterAndRestart(files) {
141140
undefsafe(config, 'options.execOptions.ext')
142141
);
143142

143+
// if there's no matches, then test to see if the changed file is the
144+
// running script, if so, let's allow a restart
145+
const script = path.resolve(config.options.execOptions.script);
146+
if (matched.result.length === 0 && script) {
147+
const length = script.length;
148+
files.find(file => {
149+
if (file.substr(-length, length) === script) {
150+
matched = {
151+
result: [ file ],
152+
total: 1,
153+
}
154+
return true;
155+
}
156+
})
157+
}
158+
144159
utils.log.detail('changes after filters (before/after): ' +
145160
[files.length, matched.result.length].join('/'));
146161

0 commit comments

Comments
 (0)