@@ -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 ( / ^ 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+
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
0 commit comments