Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(watcher): honor 'watched: false' in patterns. #620

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions lib/watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var mm = require('minimatch');

var helper = require('./helper');
var log = require('./logger').create('watcher');
var _ = require('lodash');

var DIR_SEP = require('path').sep;

Expand Down Expand Up @@ -45,20 +46,25 @@ var watchPatterns = function(patterns, watcher) {
// Function to test if an item is on the exclude list
// and therefore should not be watched by chokidar
// TODO(vojta): ignore non-matched files as well
var createIgnore = function(excludes) {
var createIgnore = function(excludes, patterns) {
var ex = _(patterns)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you need lodash ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, I see, the map('pattern'), ignore my previous comment

.filter(function(p) { return !(p.watched); })
.map('pattern')
.concat(excludes);

return function(item) {
var matchExclude = function(pattern) {
log.debug('Excluding %s', pattern);
return mm(item, pattern, {dot: true});
};
return excludes.some(matchExclude);
return ex.some(matchExclude);
};
};

exports.watch = function(patterns, excludes, fileList) {
var options = {
ignorePermissionErrors: true,
ignored: createIgnore(excludes)
ignored: createIgnore(excludes, patterns)
};
var chokidarWatcher = new chokidar.FSWatcher(options);

Expand Down
18 changes: 18 additions & 0 deletions test/unit/watcher.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,21 @@ describe 'watcher', ->
expect(ignore '/some/files/deep/.npm').to.equal false
expect(ignore '.#files.js').to.equal true
expect(ignore '/some/files/deeper/nested/.#files.js').to.equal true

it 'should ignore patterns with watched: false', ->
ignore = m.createIgnore [], [{pattern: 'app/*.html', watched: false}]
expect(ignore 'app/app.html').to.equal true

it 'should not ignore patterns with watched: true', ->
ignore = m.createIgnore [], [{pattern: 'app/*.html', watched: true}]
expect(ignore 'app/app.html').to.equal false

it 'should combine exclude and patterns', ->
ignore = m.createIgnore ['app/*.ignoreme'], [
{pattern: 'app/*.html', watched: false},
{pattern: 'app/*.js', watched: true}]

expect(ignore 'app/please.ignoreme').to.equal true
expect(ignore 'app/dontwatch.html').to.equal true
expect(ignore 'app/dowatch.js').to.equal false