Skip to content

Commit

Permalink
fix(watcher): watch files that match watched directory
Browse files Browse the repository at this point in the history
Closes #521
  • Loading branch information
vojtajina committed May 11, 2013
1 parent 7d790b2 commit 3940117
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ var mm = require('minimatch');
var helper = require('./helper');
var log = require('./logger').create('watcher');

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(/\/[^\/]*[\*\(].*$/, '') || '/';
Expand Down Expand Up @@ -32,7 +34,7 @@ var watchPatterns = function(patterns, watcher) {
// watch only common parents, no sub paths
pathsToWatch.forEach(function(path) {
if (!pathsToWatch.some(function(p) {
return p !== path && path.substr(0, p.length) === p;
return p !== path && path.substr(0, p.length + 1) === p + DIR_SEP;
})) {
watcher.add(path);
log.debug('Watching "%s"', path);
Expand Down
6 changes: 6 additions & 0 deletions test/unit/watcher.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ describe 'watcher', ->
expect(chokidarWatcher.watchedPaths_).to.deep.equal ['/some']


it 'should watch a file matching subpath directory', ->
# regression #521
m.watchPatterns patterns('/some/test-file.js', '/some/test/**'), chokidarWatcher
expect(chokidarWatcher.watchedPaths_).to.deep.equal ['/some/test-file.js', '/some/test']


it 'should not watch if watched false', ->
m.watchPatterns [
new config.Pattern('/some/*.js', true, true, false)
Expand Down

0 comments on commit 3940117

Please sign in to comment.