Skip to content

Commit

Permalink
Fix issue where Glob 7.x can't handle the leading ! in the exclude pa…
Browse files Browse the repository at this point in the history
…ttern
  • Loading branch information
iandotkelly committed Jul 9, 2016
1 parent 30e092b commit 7d750c9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
21 changes: 15 additions & 6 deletions glob-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,26 +80,35 @@ GlobAll.prototype.run = function() {
};

GlobAll.prototype.globNext = function() {
var g, pattern;
var g, pattern, include = true;
if (this.patterns.length === 0) {
return this.globbedAll();
}
pattern = this.patterns[0]; // peek!
// check whether this is an exclude pattern and
// strip the leading ! if it is
if (pattern.charAt(0) === "!") {
include = false;
pattern = pattern.substr(1);
}
// run
if (this.opts.sync) {
// sync - callback straight away
g = new Glob(pattern, this.opts);
this.globs.push(g);
this.globbedOne(null, g.found);
this.globbedOne(null, include, g.found);
} else {
// async
g = new Glob(pattern, this.opts, this.globbedOne);
var self = this;
g = new Glob(pattern, this.opts, function(err, files) {
self.globbedOne(err, include, files);
});
this.globs.push(g);
}
};

// collect results
GlobAll.prototype.globbedOne = function(err, files) {
GlobAll.prototype.globbedOne = function(err, include, files) {
// handle callback error early
if (err) {
if (!this.callback) {
Expand All @@ -121,14 +130,14 @@ GlobAll.prototype.globbedOne = function(err, files) {
var existing = this.set[path];
// new item
if (!existing) {
if (f.include) {
if (include) {
this.set[path] = f;
this.emit("match", path);
}
continue;
}
// compare or delete
if (f.include) {
if (include) {
this.set[path] = f.compare(existing);
} else {
delete this.set[path];
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"url": "https://github.com/jpillora/node-glob-all.git"
},
"dependencies": {
"glob": "^4.0.6",
"glob": "^7.0.5",
"yargs": "~1.2.6"
},
"devDependencies": {
Expand Down

0 comments on commit 7d750c9

Please sign in to comment.