@@ -102,6 +102,12 @@ module.exports = CoreObject.extend({
102
102
}
103
103
} ,
104
104
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 ( / ^ t e x t \/ | ^ a p p l i c a t i o n \/ ( j a v a s c r i p t | j s o n ) / ) . test ( mimeType ) ? 'UTF-8' : fallback ;
109
+ } ,
110
+
105
111
_putObject : function ( filePath , options , filePaths ) {
106
112
var plugin = this . plugin ;
107
113
var cwd = options . cwd ;
@@ -114,28 +120,28 @@ module.exports = CoreObject.extend({
114
120
var expires = options . expires ;
115
121
var serverSideEncryption = options . serverSideEncryption ;
116
122
117
- mime . default_type = options . defaultMimeType || mime . lookup ( 'bin' ) ;
123
+ var defaultType = options . defaultMimeType || mime . getType ( 'bin' ) ;
118
124
119
125
var basePath = path . join ( cwd , filePath ) ;
120
126
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 ) ;
123
129
var key = prefix === '' ? filePath : [ prefix , filePath ] . join ( '/' ) ;
124
130
var isGzipped = gzippedFilePaths . indexOf ( filePath ) !== - 1 ;
125
131
var isBrotliCompressed = brotliCompressedFilePaths . indexOf ( filePath ) !== - 1 ;
126
132
127
133
if ( isGzipped && path . extname ( basePath ) === '.gz' ) {
128
134
var basePathUngzipped = path . basename ( basePath , '.gz' ) ;
129
135
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 ) ;
132
138
}
133
139
}
134
140
if ( isBrotliCompressed ) {
135
141
var basePathUncompressed = path . basename ( basePath , '.br' ) ;
136
142
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 ) ;
139
145
}
140
146
}
141
147
0 commit comments