Skip to content

Commit e6e0f63

Browse files
authored
Merge pull request #107 from jenweber/mister-mime
update mime dependency to 2.x in order to support newer filetypes like wasm #105
2 parents ed6f07b + 6f90ea2 commit e6e0f63

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

lib/s3.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ module.exports = CoreObject.extend({
102102
}
103103
},
104104

105+
_mimeCharsetsLookup: function(mimeType, fallback) {
106+
// the node-mime library removed this method in v 2.0. This is the replacement
107+
// code for what was formerly mime.charsets.lookup
108+
return (/^text\/|^application\/(javascript|json)/).test(mimeType) ? 'UTF-8' : fallback;
109+
},
110+
105111
_putObject: function(filePath, options, filePaths) {
106112
var plugin = this.plugin;
107113
var cwd = options.cwd;
@@ -114,28 +120,28 @@ module.exports = CoreObject.extend({
114120
var expires = options.expires;
115121
var serverSideEncryption = options.serverSideEncryption;
116122

117-
mime.default_type = options.defaultMimeType || mime.lookup('bin');
123+
var defaultType = options.defaultMimeType || mime.getType('bin');
118124

119125
var basePath = path.join(cwd, filePath);
120126
var data = fs.readFileSync(basePath);
121-
var contentType = mime.lookup(basePath);
122-
var encoding = mime.charsets.lookup(contentType);
127+
var contentType = mime.getType(basePath) || defaultType;
128+
var encoding = this._mimeCharsetsLookup(contentType);
123129
var key = prefix === '' ? filePath : [prefix, filePath].join('/');
124130
var isGzipped = gzippedFilePaths.indexOf(filePath) !== -1;
125131
var isBrotliCompressed = brotliCompressedFilePaths.indexOf(filePath) !== -1;
126132

127133
if (isGzipped && path.extname(basePath) === '.gz') {
128134
var basePathUngzipped = path.basename(basePath, '.gz');
129135
if (filePaths && filePaths.indexOf(basePathUngzipped) !== -1) {
130-
contentType = mime.lookup(basePathUngzipped);
131-
encoding = mime.charsets.lookup(contentType);
136+
contentType = mime.getType(basePathUngzipped) || defaultType;
137+
encoding = this._mimeCharsetsLookup(contentType);
132138
}
133139
}
134140
if (isBrotliCompressed) {
135141
var basePathUncompressed = path.basename(basePath, '.br');
136142
if (filePaths && filePaths.indexOf(basePathUncompressed) !== -1) {
137-
contentType = mime.lookup(basePathUncompressed);
138-
encoding = mime.charsets.lookup(contentType);
143+
contentType = mime.getType(basePathUncompressed) || defaultType;
144+
encoding = this._mimeCharsetsLookup(contentType);
139145
}
140146
}
141147

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@
2222
"core-object": "^2.0.0",
2323
"ember-cli-deploy-plugin": "^0.2.2",
2424
"lodash": "^4.17.4",
25-
"mime": "^1.3.4",
25+
"mime": "^2.3.1",
2626
"minimatch": "^3.0.3",
2727
"proxy-agent": "^2.0.0",
2828
"rsvp": "^3.5.0"
2929
},
3030
"devDependencies": {
31-
"chai-as-promised": "^6.0.0",
3231
"chai": "^3.5.0",
33-
"ember-cli-release": "^1.0.0-beta.2",
32+
"chai-as-promised": "^6.0.0",
3433
"ember-cli": "^2.18.0",
34+
"ember-cli-release": "^1.0.0-beta.2",
3535
"eslint": "^3.18.0",
3636
"github": "^0.2.4",
3737
"glob": "^7.1.1",

yarn.lock

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3810,10 +3810,14 @@ mime-types@^2.1.12:
38103810
dependencies:
38113811
mime-db "~1.30.0"
38123812

3813-
[email protected], mime@^1.2.11, mime@^1.3.4:
3813+
[email protected], mime@^1.2.11:
38143814
version "1.3.4"
38153815
resolved "https://registry.yarnpkg.com/mime/-/mime-1.3.4.tgz#115f9e3b6b3daf2959983cb38f149a2d40eb5d53"
38163816

3817+
3818+
version "2.3.1"
3819+
resolved "https://registry.yarnpkg.com/mime/-/mime-2.3.1.tgz#b1621c54d63b97c47d3cfe7f7215f7d64517c369"
3820+
38173821
mimic-fn@^1.0.0:
38183822
version "1.2.0"
38193823
resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-1.2.0.tgz#820c86a39334640e99516928bd03fca88057d022"

0 commit comments

Comments
 (0)