Skip to content

Commit 6cf7955

Browse files
fix(preprocessor): calculate sha1 on content returned from a preprocessor
Fixes #1204
1 parent 449b0f5 commit 6cf7955

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

lib/preprocessor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ var createPreprocessor = function(config, basePath, injector) {
5252
if (!preprocessors.length) {
5353
file.contentPath = null;
5454
file.content = content;
55+
file.sha = sha1(content);
5556
return done();
5657
}
5758

@@ -93,7 +94,6 @@ var createPreprocessor = function(config, basePath, injector) {
9394
if (err) {
9495
throw err;
9596
}
96-
file.sha = sha1(buffer);
9797
nextPreprocessor(null, thisFileIsBinary ? buffer : buffer.toString());
9898
});
9999
};

test/unit/preprocessor.spec.coffee

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ describe 'preprocessor', ->
1111
mockFs = mocks.fs.create
1212
some:
1313
'a.js': mocks.fs.file 0, 'content'
14+
'b.js': mocks.fs.file 0, 'content'
1415
'a.txt': mocks.fs.file 0, 'some-text'
1516
'photo.png': mocks.fs.file 0, 'binary'
1617

@@ -96,6 +97,28 @@ describe 'preprocessor', ->
9697
expect(file.sha).not.to.equal previousSHA
9798
done()
9899

100+
it 'should compute SHA from content returned by a processor', (done) ->
101+
fakePreprocessor = sinon.spy (content, file, done) ->
102+
done null, content + '-processed'
103+
104+
injector = new di.Injector [{
105+
'preprocessor:fake': ['factory', -> fakePreprocessor]
106+
}]
107+
108+
pp = m.createPreprocessor {'**/a.js': ['fake']}, null, injector
109+
110+
fileProcess = {originalPath: '/some/a.js', path: 'path'}
111+
fileSkip = {originalPath: '/some/b.js', path: 'path'}
112+
113+
pp fileProcess, ->
114+
pp fileSkip, ->
115+
expect(fileProcess.sha).to.exist
116+
expect(fileProcess.sha.length).to.equal 40
117+
expect(fileSkip.sha).to.exist
118+
expect(fileSkip.sha.length).to.equal 40
119+
expect(fileProcess.sha).not.to.equal fileSkip.sha
120+
done()
121+
99122

100123
it 'should return error if any preprocessor fails', (done) ->
101124
failingPreprocessor = sinon.spy (content, file, done) ->

0 commit comments

Comments
 (0)