Skip to content

Commit

Permalink
fix(file-list): always use file from first matcher
Browse files Browse the repository at this point in the history
If a file is matched by multiple patterns, only the file from
the first pattern should be used.

This fixes issues that occurr when the same file appears in
multiple buckets. One such issue is that the watcher reruns
the preprocessors on the first occurrence of the file but
the second version of the file is the one being included in
the context. This results in the browser not requesting the
updated version of the file after the watch fires.
  • Loading branch information
chriscasola committed Apr 1, 2017
1 parent bcfac8a commit df017b0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/file-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ List.prototype._isRefreshing = function () {
List.prototype._refresh = function () {
var self = this
var buckets = this.buckets
var matchedFiles = new Set()

var promise = Promise.map(this._patterns, function (patternObject) {
var pattern = patternObject.pattern
Expand All @@ -174,6 +175,12 @@ List.prototype._refresh = function () {
return Promise.resolve()
}

if (matchedFiles.has(path)) {
return Promise.resolve()
}

matchedFiles.add(path)

var mtime = mg.statCache[path].mtime
var doNotCache = patternObject.nocache
var file = new File(path, mtime, doNotCache)
Expand Down
11 changes: 11 additions & 0 deletions test/unit/file-list.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,17 @@ describe('FileList', () => {
})
})

it('uses the file from the first matcher if two matchers match the same file', () => {
list = new List(patterns('/a.*', '*.txt'), [], emitter, preprocess, 100)
return list.refresh().then(() => {
var first = pathsFrom(list.buckets.get('/a.*'))
var second = pathsFrom(list.buckets.get('*.txt'))

expect(first).to.contain('/a.txt')
expect(second).not.to.contain('/a.txt')
})
})

it('cancels refreshs', () => {
var checkResult = (files) => {
expect(_.pluck(files.served, 'path')).to.contain('/some/a.js', '/some/b.js', '/some/c.js')
Expand Down

0 comments on commit df017b0

Please sign in to comment.