Skip to content

Commit

Permalink
fix(watcher): allow parentheses in a pattern
Browse files Browse the repository at this point in the history
Closes #728
  • Loading branch information
vojtajina committed Nov 16, 2013
1 parent 4858f39 commit 438eb8d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
4 changes: 3 additions & 1 deletion lib/watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ var DIR_SEP = require('path').sep;

// Get parent folder, that be watched (does not contain any special globbing character)
var baseDirFromPattern = function(pattern) {
return pattern.replace(/\/[^\/]*[\*\(].*$/, '') || '/';
return pattern.replace(/\/[^\/]*\*.*$/, '') // remove parts with *
.replace(/\/[^\/]*[\!\+]\(.*$/, '') // remove parts with !(...) and +(...)
.replace(/\/[^\/]*\)\?.*$/, '') || '/'; // remove parts with (...)?
};

var watchPatterns = function(patterns, watcher) {
Expand Down
21 changes: 18 additions & 3 deletions test/unit/watcher.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,24 @@ describe 'watcher', ->
expect(m.baseDirFromPattern '/some/p*/file.js').to.equal '/some'


it 'should remove part with parenthesis', ->
expect(m.baseDirFromPattern '/some/p/(a|b).js').to.equal '/some/p'
expect(m.baseDirFromPattern '/some/p(c|b)*.js').to.equal '/some'
it 'should remove part with !(x)', ->
expect(m.baseDirFromPattern '/some/p/!(a|b).js').to.equal '/some/p'
expect(m.baseDirFromPattern '/some/p!(c|b)*.js').to.equal '/some'


it 'should remove part with +(x)', ->
expect(m.baseDirFromPattern '/some/p/+(a|b).js').to.equal '/some/p'
expect(m.baseDirFromPattern '/some/p+(c|bb).js').to.equal '/some'


it 'should remove part with (x)?', ->
expect(m.baseDirFromPattern '/some/p/(a|b)?.js').to.equal '/some/p'
expect(m.baseDirFromPattern '/some/p(c|b)?.js').to.equal '/some'


it 'should allow paths with parentheses', ->
expect(m.baseDirFromPattern '/some/x (a|b)/a.js').to.equal '/some/x (a|b)/a.js'
expect(m.baseDirFromPattern '/some/p(c|b)/*.js').to.equal '/some/p(c|b)'


it 'should ignore exact files', ->
Expand Down

0 comments on commit 438eb8d

Please sign in to comment.