Skip to content

Commit 00a2781

Browse files
committed
fix(preprocessor): Lookup patterns once invoked
Don't lookup the list of patterns of files to preprocess until the preprocessor is called. This because patterns might be added after the preprocessor is created, and those will be missed if the patterns are looked up too early. Closes #1340
1 parent 7943931 commit 00a2781

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

lib/preprocessor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ var isBinary = Object.create(null);
3030

3131
// TODO(vojta): instantiate preprocessors at the start to show warnings immediately
3232
var createPreprocessor = function(config, basePath, injector) {
33-
var patterns = Object.keys(config);
3433
var alreadyDisplayedWarnings = Object.create(null);
3534

3635
return function(file, done) {
36+
var patterns = Object.keys(config);
3737
var thisFileIsBinary = isBinary[path.extname(file.originalPath)];
3838
var preprocessors = [];
3939
var nextPreprocessor = function(error, content) {

test/unit/preprocessor.spec.coffee

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,26 @@ describe 'preprocessor', ->
3939
done()
4040

4141

42+
it 'should check patterns after creation when invoked', (done) ->
43+
fakePreprocessor = sinon.spy (content, file, done) ->
44+
file.path = file.path + '-preprocessed'
45+
done null, 'new-content'
46+
47+
injector = new di.Injector [{'preprocessor:fake': ['factory', -> fakePreprocessor]}]
48+
config = {'**/*.txt': ['fake']}
49+
pp = m.createPreprocessor config, null, injector
50+
51+
file = {originalPath: '/some/a.js', path: 'path'}
52+
53+
config['**/*.js'] = ['fake']
54+
55+
pp file, ->
56+
expect(fakePreprocessor).to.have.been.called
57+
expect(file.path).to.equal 'path-preprocessed'
58+
expect(file.content).to.equal 'new-content'
59+
done()
60+
61+
4262
it 'should ignore not matching file', (done) ->
4363
fakePreprocessor = sinon.spy (content, file, done) ->
4464
done null, ''

0 commit comments

Comments
 (0)