From 9d1a63c6a64de477e1e7dc6520a32885dca0b0f7 Mon Sep 17 00:00:00 2001 From: Remy Sharp Date: Tue, 10 Jul 2018 18:39:53 +0100 Subject: [PATCH] fix: allow watching relative path files (#1385) Fixes #1355 --- doc/cli/help.txt | 2 +- lib/monitor/match.js | 3 ++- test/monitor/match.test.js | 14 ++++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/doc/cli/help.txt b/doc/cli/help.txt index 11b749f..adc4ba8 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,jade,hbs. -x, --exec app ........... execute script with "app", ie. -x "python -v". - -w, --watch dir........... watch directory "dir" 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/lib/monitor/match.js b/lib/monitor/match.js index 1c7c4cf..3261ced 100644 --- a/lib/monitor/match.js +++ b/lib/monitor/match.js @@ -160,7 +160,8 @@ function match(files, monitor, ext) { return '!**' + (prefix !== path.sep ? path.sep : '') + s.slice(1); } - if (s.slice(0, 2) === '..') { + // if it starts with a period, then let's get the relative path + if (s.indexOf('.') === 0) { return path.resolve(cwd, s); } diff --git a/test/monitor/match.test.js b/test/monitor/match.test.js index 19674f3..6f59db6 100644 --- a/test/monitor/match.test.js +++ b/test/monitor/match.test.js @@ -557,4 +557,18 @@ describe('watcher', function() { } ); }); + + it('should watch relative paths', function() { + const monitor = match.rulesToMonitor([ './http.js' ], [], { + dirs: [], + }); + + var matched = match( + ['http.js'], + monitor, + 'js,mjs,json' + ); + assert(matched.result.length === 1, 'found match ' + matched.results); + }); + });