From df017b09587b47281819908a0492546fe048adf2 Mon Sep 17 00:00:00 2001 From: Chris Casola Date: Sat, 1 Apr 2017 11:35:40 -0400 Subject: [PATCH] fix(file-list): always use file from first matcher 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. --- lib/file-list.js | 7 +++++++ test/unit/file-list.spec.js | 11 +++++++++++ 2 files changed, 18 insertions(+) diff --git a/lib/file-list.js b/lib/file-list.js index 5cfc928e4..ab6f7c3ef 100644 --- a/lib/file-list.js +++ b/lib/file-list.js @@ -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 @@ -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) diff --git a/test/unit/file-list.spec.js b/test/unit/file-list.spec.js index 33867bbd1..efb95ede7 100644 --- a/test/unit/file-list.spec.js +++ b/test/unit/file-list.spec.js @@ -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')