Skip to content

Commit b5eef18

Browse files
committed
Add the gzipped file to the context's distFiles when keep is true
By not adding the gzipped files to the distFiles we end up leaving them out of several things e.g. they're never added to the manifest for a build and they're never uploaded with the S3 plugin. In much the same way as the json-config plugin adds the built json file to the context, this PR will mean the gzip plugin now adds all of the gzipped files to the context.
1 parent e00f9c3 commit b5eef18

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ module.exports = {
5353
return this._gzipFiles(distDir, distFiles, filePattern, keep)
5454
.then(function(gzippedFiles) {
5555
self.log('gzipped ' + gzippedFiles.length + ' files ok', { verbose: true });
56+
if (keep) {
57+
self.log('keep is enabled, added gzipped files to `context.distFiles`', { verbose: true });
58+
return {
59+
distFiles: gzippedFiles,
60+
gzippedFiles: gzippedFiles
61+
}
62+
}
5663
return { gzippedFiles: gzippedFiles };
5764
})
5865
.catch(this._errorMessage.bind(this));

tests/unit/index-nodetest.js

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -155,15 +155,30 @@ describe('gzip plugin', function() {
155155
});
156156
});
157157

158-
it('gzips the matching files with .gz suffix when keep is enabled', function(done) {
159-
context.config.gzip.keep = true;
160-
return assert.isFulfilled(plugin.willUpload(context))
161-
.then(function(result) {
162-
assert.deepEqual(result, { gzippedFiles: ['assets/foo.js.gz'] });
163-
done();
164-
}).catch(function(reason){
165-
done(reason);
166-
});
158+
describe('when keep is enabled', function() {
159+
beforeEach(function() {
160+
context.config.gzip.keep = true;
161+
});
162+
163+
it('gzips the matching files with .gz suffix', function(done) {
164+
return assert.isFulfilled(plugin.willUpload(context))
165+
.then(function(result) {
166+
assert.deepEqual(result.gzippedFiles, ['assets/foo.js.gz']);
167+
done();
168+
}).catch(function(reason){
169+
done(reason);
170+
});
171+
});
172+
173+
it('adds the gzipped files to the distFiles', function(done) {
174+
return assert.isFulfilled(plugin.willUpload(context))
175+
.then(function(result) {
176+
assert.include(result.distFiles, 'assets/foo.js.gz');
177+
done();
178+
}).catch(function(reason){
179+
done(reason);
180+
});
181+
});
167182
});
168183
});
169184
});

0 commit comments

Comments
 (0)