Skip to content

Commit

Permalink
fix: properly ignore defaults, don't match partial
Browse files Browse the repository at this point in the history
Changed to passing Chokidar simple strings instead of custom regexp, only had to prefix with **/ to get it to match the ignore directories properly.

Fixes #916
  • Loading branch information
remy authored Dec 20, 2017
1 parent 1d88943 commit 4589bc8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
4 changes: 2 additions & 2 deletions lib/config/defaults.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var ignoreRoot = require('ignore-by-default').directories()
var ignoreRoot = require('ignore-by-default').directories();

// default options for config.options
module.exports = {
Expand All @@ -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,
ignoreRoot: ignoreRoot.map(_ => `**/${_}`),
watch: ['*.*'],
stdin: true,
runOnChangeOnly: false,
Expand Down
41 changes: 25 additions & 16 deletions lib/monitor/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,20 @@ function watch() {
var dirs = [].slice.call(config.dirs);

debugRoot('start watch on: %s', dirs.join(', '));
debugRoot('ignore dirs regex(%s)', config.options.ignore.re);
const rootIgnored = config.options.ignore;
debugRoot('ignored', rootIgnored);

var promises = [];
var watchedFiles = [];

dirs.forEach(function (dir) {
var promise = new Promise(function (resolve) {
var ignored = config.options.ignore.re;
var dotFilePattern = /[\/\\]\./;
var dotFilePattern = /[/\\]\./;
var ignored = Array.from(rootIgnored);

// don't ignore dotfiles if explicitly watched.
if (!dir.match(dotFilePattern)) {
ignored = [ignored, dotFilePattern];
ignored.push(dotFilePattern);
}

var watchOptions = {
Expand All @@ -62,7 +63,8 @@ function watch() {
watchOptions.useFsEvents = false;
}

var watcher = chokidar.watch(dir,
var watcher = chokidar.watch(
dir,
Object.assign({}, watchOptions, config.watchOptions || {})
);

Expand All @@ -89,9 +91,11 @@ function watch() {

watcher.on('error', function (error) {
if (error.code === 'EINVAL') {
utils.log.error('Internal watch failed. Likely cause: too many ' +
utils.log.error(
'Internal watch failed. Likely cause: too many ' +
'files being watched (perhaps from the root of a drive?\n' +
'See https://github.com/paulmillr/chokidar/issues/229 for details');
'See https://github.com/paulmillr/chokidar/issues/229 for details'
);
} else {
utils.log.error('Internal watch failed: ' + error.message);
process.exit(1);
Expand Down Expand Up @@ -128,10 +132,14 @@ function filterAndRestart(files) {
}

var cwd = process.cwd();
utils.log.detail('files triggering change check: ' +
files.map(function (file) {
return path.relative(cwd, file);
}).join(', '));
utils.log.detail(
'files triggering change check: ' +
files
.map(function (file) {
return path.relative(cwd, file);
})
.join(', ')
);

var matched = match(
files,
Expand All @@ -150,15 +158,17 @@ function filterAndRestart(files) {
matched = {
result: [file],
total: 1,
}
};
return true;
}
})
});
}
}

utils.log.detail('changes after filters (before/after): ' +
[files.length, matched.result.length].join('/'));
utils.log.detail(
'changes after filters (before/after): ' +
[files.length, matched.result.length].join('/')
);

// reset the last check so we're only looking at recently modified files
config.lastStarted = Date.now();
Expand All @@ -177,7 +187,6 @@ function filterAndRestart(files) {
}
}


function restartBus(matched) {
utils.log.status('restarting due to changes...');
matched.result.map(function (file) {
Expand Down

0 comments on commit 4589bc8

Please sign in to comment.