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: watch does not work for glob pattern '<dir>/**' if '<dir>' does not exist on fs #746

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
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,8 @@ FSWatcher.prototype._isIgnored = function(path, stats) {
var replacerRe = /^\.[\/\\]/;
FSWatcher.prototype._getWatchHelpers = function(path, depth) {
path = path.replace(replacerRe, '');
var watchPath = depth || this.options.disableGlobbing || !isGlob(path) ? path : globParent(path);
var getExistingPath = function(path) { return fs.existsSync(path) ? path : getExistingPath(sysPath.dirname(path)); };
var watchPath = depth || this.options.disableGlobbing || !isGlob(path) ? path : getExistingPath(globParent(path));
var fullWatchPath = sysPath.resolve(watchPath);
var hasGlob = watchPath !== path;
var globFilter = hasGlob ? anymatch(path) : false;
Expand Down
17 changes: 17 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1151,6 +1151,23 @@ function runTests(baseopts) {
});
});
});
it('should correctly watch glob patterns which initially do not match any files on fs', (done) => {
var spy = sinon.spy();
var watchPath = upath.normalizeSafe(getGlobPath('subdir/**'));
var dir = getFixturePath('subdir');
var file = getFixturePath('subdir/a.txt');
watcher = chokidar.watch(watchPath, options)
.on('all', spy)
.on('ready', function() {
fs.mkdirSync(getFixturePath('subdir'), 0x1ed);
fs.writeFileSync(file, Date.now());
waitFor([spy.withArgs('add')], function() {
spy.should.have.been.calledWith('addDir', dir);
spy.should.have.been.calledWith('add', file);
});
done();
});
});
});
describe('watch symlinks', function() {
if (os === 'win32') return;
Expand Down