Skip to content

Commit

Permalink
fix: correctly pass ignored rules to chokidar
Browse files Browse the repository at this point in the history
Previous the rules weren't matching fully inside of chokidar, requiring
that, for instance, node_modules is written as **/node_modules/**.

I've also tidied up what's printed in verbose mode, so it doesn't print
default ignores, and doesn't print the full path of an ignored
directory.

This change _also_ fixes notifications from chokidar from user ignored
paths (using the `cwd` argument). This should fix #1202
  • Loading branch information
remy committed Jan 8, 2018
1 parent 64a82ff commit 718a9ad
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/config/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = {
// compatible with linux, mac and windows, or make the default.js
// dynamically append the `.cmd` for node based utilities
},
ignoreRoot: ignoreRoot.map(_ => `**/${_}`),
ignoreRoot: ignoreRoot.map(_ => `**/${_}/**`),
watch: ['*.*'],
stdin: true,
runOnChangeOnly: false,
Expand Down
3 changes: 2 additions & 1 deletion lib/monitor/match.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ function rulesToMonitor(watch, ignore, config) {
if (rule.slice(-4) !== '**/*' &&
rule.slice(-1) === '*' &&
rule.indexOf('*.') === -1) {
rule += '*/*';

if (rule.slice(-2) !== '**') rule += '*/*';
}


Expand Down
1 change: 1 addition & 0 deletions lib/monitor/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ function watch() {
}

var watchOptions = {
cwd: process.cwd(), // use cwd for relative path ignore
ignored: ignored,
persistent: true,
usePolling: config.options.legacyWatch || false,
Expand Down
28 changes: 24 additions & 4 deletions lib/nodemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var bus = utils.bus;
var help = require('./help');
var config = require('./config');
var spawn = require('./spawn');
const defaults = require('./config/defaults')
var eventHandlers = {};

// this is fairly dirty, but theoretically sound since it's part of the
Expand Down Expand Up @@ -65,6 +66,8 @@ function nodemon(settings) {
}
}

const cwd = process.cwd();

config.load(settings, function (config) {
if (!config.options.dump && !config.options.execOptions.script &&
config.options.execOptions.exec === 'node') {
Expand Down Expand Up @@ -147,9 +150,26 @@ function nodemon(settings) {
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(Boolean).join(' '));
const ignoring = config.options.monitor.map(function (rule) {
if (rule.slice(0, 1) !== '!') {
return false;
}

rule = rule.slice(1);

// don't notify of default ignores
if (defaults.ignoreRoot.includes(rule)) {
return false;
return rule.slice(3).slice(0, -3);
}

if (rule.startsWith(cwd)) {
return rule.replace(cwd, '.');
}

return rule;
}).filter(Boolean).join(' ');
if (ignoring) utils.log.detail('ignoring: ' + ignoring);

utils.log.info('watching: ' + config.options.monitor.map(function (rule) {
return rule.slice(0, 1) !== '!' ? rule : false;
Expand All @@ -162,7 +182,7 @@ function nodemon(settings) {
utils.log._log('log', 'node: ' + process.version);
utils.log._log('log', 'nodemon: ' + version.pinned);
utils.log._log('log', 'command: ' + process.argv.join(' '));
utils.log._log('log', 'cwd: ' + process.cwd());
utils.log._log('log', 'cwd: ' + cwd);
utils.log._log('log', ['OS:', process.platform, process.arch].join(' '));
utils.log._log('log', '--------------');
utils.log._log('log', util.inspect(config, { depth: null }));
Expand Down

0 comments on commit 718a9ad

Please sign in to comment.