Skip to content

Commit 3f6cba3

Browse files
committed
Add brotli support with ember-cli-deploy-brotli
1 parent 7fbf82b commit 3f6cba3

File tree

7 files changed

+1223
-576
lines changed

7 files changed

+1223
-576
lines changed

index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ module.exports = {
3434
gzippedFiles: function(context) {
3535
return context.gzippedFiles || []; // e.g. from ember-cli-deploy-gzip
3636
},
37+
brotliCompressedFiles: function(context) {
38+
return context.brotliCompressedFiles || []; // e.g. from ember-cli-deploy-gzip
39+
},
3740
manifestPath: function(context) {
3841
return context.manifestPath; // e.g. from ember-cli-deploy-manifest
3942
},
@@ -53,6 +56,7 @@ module.exports = {
5356
var distDir = this.readConfig('distDir');
5457
var distFiles = this.readConfig('distFiles');
5558
var gzippedFiles = this.readConfig('gzippedFiles');
59+
var brotliCompressedFiles = this.readConfig('brotliCompressedFiles');
5660
var bucket = this.readConfig('bucket');
5761
var acl = this.readConfig('acl');
5862
var prefix = this.readConfig('prefix');
@@ -74,6 +78,7 @@ module.exports = {
7478
cwd: distDir,
7579
filePaths: filesToUpload,
7680
gzippedFilePaths: gzippedFiles,
81+
brotliCompressedFilePaths: brotliCompressedFiles,
7782
prefix: prefix,
7883
bucket: bucket,
7984
acl: acl,

lib/s3.js

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,16 @@ module.exports = CoreObject.extend({
103103
},
104104

105105
_putObject: function(filePath, options, filePaths) {
106-
var plugin = this.plugin;
107-
var cwd = options.cwd;
108-
var bucket = options.bucket;
109-
var prefix = options.prefix;
110-
var acl = options.acl;
111-
var gzippedFilePaths = options.gzippedFilePaths || [];
112-
var cacheControl = options.cacheControl;
113-
var expires = options.expires;
114-
var serverSideEncryption = options.serverSideEncryption;
106+
var plugin = this.plugin;
107+
var cwd = options.cwd;
108+
var bucket = options.bucket;
109+
var prefix = options.prefix;
110+
var acl = options.acl;
111+
var gzippedFilePaths = options.gzippedFilePaths || [];
112+
var brotliCompressedFilePaths = options.brotliCompressedFilePaths || [];
113+
var cacheControl = options.cacheControl;
114+
var expires = options.expires;
115+
var serverSideEncryption = options.serverSideEncryption;
115116

116117
mime.default_type = options.defaultMimeType || mime.lookup('bin');
117118

@@ -121,9 +122,17 @@ module.exports = CoreObject.extend({
121122
var encoding = mime.charsets.lookup(contentType);
122123
var key = prefix === '' ? filePath : [prefix, filePath].join('/');
123124
var isGzipped = gzippedFilePaths.indexOf(filePath) !== -1;
125+
var isBrotliCompressed = brotliCompressedFilePaths.indexOf(filePath) !== -1;
124126

125127
if (isGzipped && path.extname(basePath) === '.gz') {
126-
var basePathUncompressed = path.basename(basePath, '.gz');
128+
var basePathUngzipped = path.basename(basePath, '.gz');
129+
if (filePaths && filePaths.indexOf(basePathUngzipped) !== -1) {
130+
contentType = mime.lookup(basePathUngzipped);
131+
encoding = mime.charsets.lookup(contentType);
132+
}
133+
}
134+
if (isBrotliCompressed) {
135+
var basePathUncompressed = path.basename(basePath, '.br');
127136
if (filePaths && filePaths.indexOf(basePathUncompressed) !== -1) {
128137
contentType = mime.lookup(basePathUncompressed);
129138
encoding = mime.charsets.lookup(contentType);
@@ -152,6 +161,9 @@ module.exports = CoreObject.extend({
152161
if (isGzipped) {
153162
params.ContentEncoding = 'gzip';
154163
}
164+
if (isBrotliCompressed) {
165+
params.ContentEncoding = 'br';
166+
}
155167

156168
return new RSVP.Promise(function(resolve, reject) {
157169
this._client.putObject(params, function(error) {

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@
3131
"chai-as-promised": "^6.0.0",
3232
"chai": "^3.5.0",
3333
"ember-cli-release": "^1.0.0-beta.2",
34-
"ember-cli": "^2.12.0",
34+
"ember-cli": "^2.18.0",
3535
"eslint": "^3.18.0",
3636
"github": "^0.2.4",
3737
"glob": "^7.1.1",
3838
"mocha": "^3.2.0",
3939
"multiline": "^1.0.2"
4040
},
4141
"engines": {
42-
"node": ">= 4"
42+
"node": "^4.5 || 6.* || >= 7.*"
4343
},
4444
"ember-addon": {
4545
"before": "ember-cli-deploy-redis"

tests/fixtures/dist/app.css.br

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
�body: {}
2+


tests/index-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ describe('s3 plugin', function() {
128128
return previous;
129129
}, []);
130130

131-
assert.equal(messages.length, 7);
131+
assert.equal(messages.length, 8);
132132
});
133133

134134
describe('required config', function() {

tests/lib/s3-test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,36 @@ describe('s3', function() {
178178
});
179179
});
180180

181+
it('sends the correct content type params for brotli-compressed files with .br extension', function () {
182+
var s3Params;
183+
s3Client.putObject = function (params, cb) {
184+
s3Params = params;
185+
cb();
186+
};
187+
188+
var options = {
189+
filePaths: ['app.css', 'app.css.br'],
190+
brotliCompressedFilePaths: ['app.css.br'],
191+
cwd: process.cwd() + '/tests/fixtures/dist',
192+
prefix: 'js-app',
193+
acl: 'public-read',
194+
bucket: 'some-bucket',
195+
cacheControl: 'max-age=1234, public',
196+
expires: '2010'
197+
};
198+
199+
var promises = subject.upload(options);
200+
201+
return assert.isFulfilled(promises)
202+
.then(function () {
203+
assert.equal(s3Params.ContentType, 'text/css; charset=utf-8');
204+
assert.equal(s3Params.Key, 'js-app/app.css.br');
205+
assert.equal(s3Params.ContentEncoding, 'br');
206+
assert.equal(s3Params.CacheControl, 'max-age=1234, public');
207+
assert.equal(s3Params.Expires, '2010');
208+
});
209+
});
210+
181211
it('sets the content type using defaultMimeType', function() {
182212
var s3Params;
183213
s3Client.putObject = function(params, cb) {

0 commit comments

Comments
 (0)