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

feat(watcher): Allow using braces in watcher #1251

Closed
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
4 changes: 4 additions & 0 deletions lib/watcher.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var chokidar = require('chokidar');
var mm = require('minimatch');
var expandBraces = require('expand-braces');

var helper = require('./helper');
var log = require('./logger').create('watcher');
Expand All @@ -19,6 +20,9 @@ var watchPatterns = function(patterns, watcher) {
var uniqueMap = {};
var path;

// expand ['a/{b,c}'] to ['a/b', 'a/c']
patterns = expandBraces(patterns);

patterns.forEach(function(pattern) {
path = baseDirFromPattern(pattern);
if (!uniqueMap[path]) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@
"chokidar": ">=0.8.2",
"glob": "~3.2.7",
"minimatch": "~0.2",
"expand-braces": "~0.1.1",
"http-proxy": "~0.10",
"optimist": "~0.6.0",
"rimraf": "~2.2.5",
Expand Down
15 changes: 15 additions & 0 deletions test/unit/watcher.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,21 @@ describe 'watcher', ->
expect(chokidarWatcher.watchedPaths_).to.deep.equal ['/some', '/a']


it 'should expand braces and watch all the patterns', ->
m.watchPatterns ['/some/{a,b}/*.js', '/a/*'], chokidarWatcher
expect(chokidarWatcher.watchedPaths_).to.deep.equal ['/some/a', '/some/b', '/a']


it 'should not watch the same path twice', ->
m.watchPatterns ['/some/a*.js', '/some/*.txt'], chokidarWatcher
expect(chokidarWatcher.watchedPaths_).to.deep.equal ['/some']


it 'should not watch the same path twice when using braces', ->
m.watchPatterns ['/some/*.{js,txt}'], chokidarWatcher
expect(chokidarWatcher.watchedPaths_).to.deep.equal ['/some']


it 'should not watch subpaths that are already watched', ->
m.watchPatterns ['/some/sub/*.js', '/some/a*.*'].map(path.normalize), chokidarWatcher
expect(chokidarWatcher.watchedPaths_).to.deep.equal [path.normalize('/some')]
Expand All @@ -75,6 +85,11 @@ describe 'watcher', ->
expect(chokidarWatcher.watchedPaths_).to.deep.equal ['/some/test-file.js', '/some/test']


it 'should watch files matching a subpath directory with braces', ->
m.watchPatterns ['/some/{a,b}/test.js'], chokidarWatcher
expect(chokidarWatcher.watchedPaths_).to.deep.equal ['/some/a/test.js', '/some/b/test.js']


describe 'getWatchedPatterns', ->

it 'should return list of watched patterns (strings)', ->
Expand Down