Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: properly ignore defaults, don't match partial #1186

Merged
merged 2 commits into from
Dec 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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