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 6, 2018
1 parent 6e7ce4b commit 0b63d11
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 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
30 changes: 25 additions & 5 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 All @@ -82,7 +85,7 @@ function nodemon(settings) {
utils.log.info(version.pinned);

if (config.options.cwd) {
utils.log.detail('process root: ' + process.cwd());
utils.log.detail('process root: ' + cwd);
}

config.loaded.forEach(function (filename) {
Expand Down Expand Up @@ -145,9 +148,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 @@ -160,7 +180,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 0b63d11

Please sign in to comment.