Adds Exclusion Support to Gaze. Fixes GH-7 #21

Closed
wants to merge 2 commits into
from

4 participants

@itsjamie

This is the same request as #20, just squashed into one commit. To make it easier to look at/maintain.

If both this and gruntjs/grunt-contrib-watch#43 are applied, gruntjs/grunt-contrib-watch#20 is fixed for me.

@itsjamie itsjamie Adds Exclusion Support to Gaze. Fixes GH-7
Add test case for exclusions in Gaze.

Testcase..

Fix test cases on this branch.

Code Review mchoy. Ran local tests, 42 passes. Yay. Tested locally as well using my project, and it worked the way I expected it too. Yay!

Minor fixes.
425882d
@itsjamie

@shama should be good for review now, I went through and fixed all the things I saw after I took a second look today.

I've got a version run through JSHint available if you want it. you can see it at...
jamie-stackhouse/gaze@13bfeeb
^ also includes some revised edits to the tests that was closed. However, it's gaze.js is definitely better, I'll update this branch with it.

@chrisirhc chrisirhc commented on the diff Feb 11, 2013
lib/gaze.js
@@ -388,11 +442,20 @@ Gaze.prototype._addToWatched = function(files) {
// Returns true if the file matches this._patterns
Gaze.prototype._isMatch = function(file) {
var matched = false;
- this._patterns.forEach(function(pattern) {
- if (matched || (matched = minimatch(file, pattern)) ) {
- return false;
+
+ //using for to allow early exit on first negation match.
+ //backwards because this will allow early exits if our negation match
+ for (var i = this._patterns.length - 1; i >= 0; i--) {
+ if (minimatch(file, this._patterns[i])) {
+ if (this._patterns[i].indexOf('!') === 0) {
+ //First time a negation is hit, we can hop out of the forEach.
+ matched = false;
+ continue;
@chrisirhc
chrisirhc added a line comment Feb 11, 2013

(Just reading this to try to help out in reviewing.. If you don't mind.)
Did you mean break here?

Alternatively, you can use the Array.some() method.

@itsjamie
itsjamie added a line comment Feb 12, 2013

Thanks for the hint on array.some, didn't know about it.

Yea, it should be a break. Oops :o

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@shama
Owner

I really appreciate the work you put into this @jamie-stackhouse. Although I think we should upstream this functionality. I found this lib fileset which does exactly what we're trying to accomplish here. Just waiting for a merged PR to get published and will integrate. I have the integration started in the patterns branch.

@chrisirhc

Thanks for the update, @shama, and I'll be integrating it to the incremental building plugin I'm working on!

@cowboy
Collaborator

FWIW, I'm going to be extrapolating all of grunt.file.expand and grunt.file.match functionality into a separate lib once grunt 0.4.0 has been released.

@itsjamie

Hey, seeing as how the issue related to this pull request is going to be solved, I'mma close it.

Thanks!

@itsjamie itsjamie closed this Feb 14, 2013
@shama
Owner

Thanks again for pinpointing this issue Jamie! Fixed on 5578985.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment