Skip to content

Commit 4589bc8

Browse files
authored
fix: properly ignore defaults, don't match partial
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
1 parent 1d88943 commit 4589bc8

File tree

2 files changed

+27
-18
lines changed

2 files changed

+27
-18
lines changed

lib/config/defaults.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var ignoreRoot = require('ignore-by-default').directories()
1+
var ignoreRoot = require('ignore-by-default').directories();
22

33
// default options for config.options
44
module.exports = {
@@ -11,7 +11,7 @@ module.exports = {
1111
// compatible with linux, mac and windows, or make the default.js
1212
// dynamically append the `.cmd` for node based utilities
1313
},
14-
ignoreRoot: ignoreRoot,
14+
ignoreRoot: ignoreRoot.map(_ => `**/${_}`),
1515
watch: ['*.*'],
1616
stdin: true,
1717
runOnChangeOnly: false,

lib/monitor/watch.js

+25-16
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,20 @@ function watch() {
3232
var dirs = [].slice.call(config.dirs);
3333

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

3738
var promises = [];
3839
var watchedFiles = [];
3940

4041
dirs.forEach(function (dir) {
4142
var promise = new Promise(function (resolve) {
42-
var ignored = config.options.ignore.re;
43-
var dotFilePattern = /[\/\\]\./;
43+
var dotFilePattern = /[/\\]\./;
44+
var ignored = Array.from(rootIgnored);
4445

4546
// don't ignore dotfiles if explicitly watched.
4647
if (!dir.match(dotFilePattern)) {
47-
ignored = [ignored, dotFilePattern];
48+
ignored.push(dotFilePattern);
4849
}
4950

5051
var watchOptions = {
@@ -62,7 +63,8 @@ function watch() {
6263
watchOptions.useFsEvents = false;
6364
}
6465

65-
var watcher = chokidar.watch(dir,
66+
var watcher = chokidar.watch(
67+
dir,
6668
Object.assign({}, watchOptions, config.watchOptions || {})
6769
);
6870

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

9092
watcher.on('error', function (error) {
9193
if (error.code === 'EINVAL') {
92-
utils.log.error('Internal watch failed. Likely cause: too many ' +
94+
utils.log.error(
95+
'Internal watch failed. Likely cause: too many ' +
9396
'files being watched (perhaps from the root of a drive?\n' +
94-
'See https://github.com/paulmillr/chokidar/issues/229 for details');
97+
'See https://github.com/paulmillr/chokidar/issues/229 for details'
98+
);
9599
} else {
96100
utils.log.error('Internal watch failed: ' + error.message);
97101
process.exit(1);
@@ -128,10 +132,14 @@ function filterAndRestart(files) {
128132
}
129133

130134
var cwd = process.cwd();
131-
utils.log.detail('files triggering change check: ' +
132-
files.map(function (file) {
133-
return path.relative(cwd, file);
134-
}).join(', '));
135+
utils.log.detail(
136+
'files triggering change check: ' +
137+
files
138+
.map(function (file) {
139+
return path.relative(cwd, file);
140+
})
141+
.join(', ')
142+
);
135143

136144
var matched = match(
137145
files,
@@ -150,15 +158,17 @@ function filterAndRestart(files) {
150158
matched = {
151159
result: [file],
152160
total: 1,
153-
}
161+
};
154162
return true;
155163
}
156-
})
164+
});
157165
}
158166
}
159167

160-
utils.log.detail('changes after filters (before/after): ' +
161-
[files.length, matched.result.length].join('/'));
168+
utils.log.detail(
169+
'changes after filters (before/after): ' +
170+
[files.length, matched.result.length].join('/')
171+
);
162172

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

180-
181190
function restartBus(matched) {
182191
utils.log.status('restarting due to changes...');
183192
matched.result.map(function (file) {

0 commit comments

Comments
 (0)