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

Improve ignore paths globifying #539

Closed
wants to merge 1 commit into from
Closed
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
21 changes: 16 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@ var isString = function(thing) {
return typeof thing === 'string';
};

var globify = function(path) {
var ret;
if (path.slice(-1) === sysPath.sep) {
ret = path + '**';
} else {
ret = path + sysPath.sep + '**';
}
if (!sysPath.isAbsolute(path)) {
ret = '**' + sysPath.sep + ret;
}
return ret;
};

// Public: Main class.
// Watches files & directories for changes.
//
Expand Down Expand Up @@ -356,9 +369,7 @@ FSWatcher.prototype._isIgnored = function(path, stats) {
var paths = arrify(ignored)
.filter(function(path) {
return typeof path === 'string' && !isGlob(path);
}).map(function(path) {
return path + '/**';
});
}).map(globify);
this._userIgnored = anymatch(
this._globIgnored.concat(ignored).concat(paths)
);
Expand Down Expand Up @@ -594,7 +605,7 @@ FSWatcher.prototype.add = function(paths, _origAdd, _internal) {
} else {
// if a path is being added that was previously ignored, stop ignoring it
delete this._ignoredPaths[path];
delete this._ignoredPaths[path + '/**'];
delete this._ignoredPaths[globify(path)];

// reset the cached userIgnored anymatch fn
// to make ignoredPaths changes effective
Expand Down Expand Up @@ -647,7 +658,7 @@ FSWatcher.prototype.unwatch = function(paths) {

this._ignoredPaths[path] = true;
if (path in this._watched) {
this._ignoredPaths[path + '/**'] = true;
this._ignoredPaths[globify(path)] = true;
}

// reset the cached userIgnored anymatch fn
Expand Down
34 changes: 34 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1100,6 +1100,40 @@ function runTests(baseopts) {
}, 300));
}));
});
it('should ignore paths provided only a directory name without ending slash', function(done) {
var spy = sinon.spy();
var testDir = getFixturePath('subdir');
var testFile = sysPath.join(testDir, 'add.txt');
options.ignored = 'subdir';
fs.mkdirSync(testDir, 0x1ed);
fs.writeFileSync(testFile, 'b');
watcher = chokidar.watch(fixturesPath, options)
.on('all', spy)
.on('ready', w(function() {
fs.writeFile(testFile, Date.now(), w(function() {
spy.should.not.have.been.calledWith('add', testFile);
spy.should.not.have.been.calledWith('change', testFile);
done();
}, 300));
}));
});
it('should ignore paths provided only a directory name with ending slash', function(done) {
var spy = sinon.spy();
var testDir = getFixturePath('subdir');
var testFile = sysPath.join(testDir, 'add.txt');
options.ignored = 'subdir/';
fs.mkdirSync(testDir, 0x1ed);
fs.writeFileSync(testFile, 'b');
watcher = chokidar.watch(fixturesPath, options)
.on('all', spy)
.on('ready', w(function() {
fs.writeFile(testFile, Date.now(), w(function() {
spy.should.not.have.been.calledWith('add', testFile);
spy.should.not.have.been.calledWith('change', testFile);
done();
}, 300));
}));
});
it('should allow regex/fn ignores', function(done) {
options.cwd = fixturesPath;
options.ignored = /add/;
Expand Down