Skip to content

Commit

Permalink
Merge b149ec0 into 528826f
Browse files Browse the repository at this point in the history
  • Loading branch information
MhMadHamster committed Jul 23, 2017
2 parents 528826f + b149ec0 commit b3f3293
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 6 deletions.
21 changes: 16 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var globParent = require('glob-parent');
var isGlob = require('is-glob');
var isAbsolute = require('path-is-absolute');
var inherits = require('inherits');
var braces = require('braces');

var NodeFsHandler = require('./lib/nodefs-handler');
var FsEventsHandler = require('./lib/fsevents-handler');
Expand Down Expand Up @@ -423,21 +424,31 @@ FSWatcher.prototype._getWatchHelpers = function(path, depth) {

var getDirParts = function(path) {
if (!hasGlob) return false;
var parts = sysPath.relative(watchPath, path).split(/[\/\\]/);
var parts = [];
var expandedPath = braces.expand(path);
expandedPath.forEach(function(path) {
parts.push(sysPath.relative(watchPath, path).split(/[\/\\]/));
});
return parts;
};

var dirParts = getDirParts(path);
if (dirParts && dirParts.length > 1) dirParts.pop();
if (dirParts) {
dirParts.forEach(function(parts) {
if (parts.length > 1) parts.pop();
});
}
var unmatchedGlob;

var filterDir = function(entry) {
if (hasGlob) {
var entryParts = getDirParts(checkGlobSymlink(entry));
var globstar = false;
unmatchedGlob = !dirParts.every(function(part, i) {
if (part === '**') globstar = true;
return globstar || !entryParts[i] || anymatch(part, entryParts[i]);
unmatchedGlob = !dirParts.some(function(parts) {
return parts.every(function(part, i) {
if (part === '**') globstar = true;
return globstar || !entryParts[0][i] || anymatch(part, entryParts[0][i]);
});
});
}
return !unmatchedGlob && this._isntIgnored(entryPath(entry), entry.stat);
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,16 @@
"mocha": "^3.0.0",
"rimraf": "^2.4.3",
"sinon": "^1.10.3",
"sinon-chai": "^2.6.0"
"sinon-chai": "^2.6.0",
"upath": "1.0.0"
},
"optionalDependencies": {
"fsevents": "^1.0.0"
},
"dependencies": {
"anymatch": "^1.3.0",
"async-each": "^1.0.0",
"braces": "2.2.2",
"glob-parent": "^2.0.0",
"inherits": "^2.0.1",
"is-binary-path": "^1.0.0",
Expand Down
28 changes: 28 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var sinon = require('sinon');
var rimraf = require('rimraf');
var fs = require('graceful-fs');
var sysPath = require('path');
var upath = require("upath");
var cp = require('child_process');
chai.use(require('sinon-chai'));
var os = process.platform;
Expand Down Expand Up @@ -767,6 +768,33 @@ function runTests(baseopts) {
});
});
});
it('should correctly handle glob with braces', function(done) {
var spy = sinon.spy();
var watchPath = upath.normalizeSafe(getFixturePath('{subdir/*,subdir1/subsub1}/subsubsub/*.txt'));
var deepFileA = getFixturePath('subdir/subsub/subsubsub/a.txt');
var deepFileB = getFixturePath('subdir1/subsub1/subsubsub/a.txt');
fs.mkdirSync(getFixturePath('subdir'), 0x1ed);
fs.mkdirSync(getFixturePath('subdir/subsub'), 0x1ed);
fs.mkdirSync(getFixturePath('subdir/subsub/subsubsub'), 0x1ed);
fs.mkdirSync(getFixturePath('subdir1'), 0x1ed);
fs.mkdirSync(getFixturePath('subdir1/subsub1'), 0x1ed);
fs.mkdirSync(getFixturePath('subdir1/subsub1/subsubsub'), 0x1ed);
fs.writeFileSync(deepFileA, Date.now());
fs.writeFileSync(deepFileB, Date.now());
watcher = chokidar.watch(watchPath, options)
.on('all', spy)
.on('ready', function() {
spy.should.have.been.calledWith('add', deepFileA);
spy.should.have.been.calledWith('add', deepFileB);
fs.writeFileSync(deepFileA, Date.now());
fs.writeFileSync(deepFileB, Date.now());
waitFor([[spy, 4]], function() {
spy.should.have.been.calledWith('change', deepFileA);
spy.should.have.been.calledWith('change', deepFileB);
done();
});
});
});
});
describe('watch symlinks', function() {
if (os === 'win32') return;
Expand Down

0 comments on commit b3f3293

Please sign in to comment.