2
2
MIT License http://www.opensource.org/licenses/mit-license.php
3
3
Author Tobias Koppers @sokra
4
4
*/
5
- import fs from 'fs' ;
6
5
import path from 'path' ;
7
6
8
7
import { promisify } from 'util' ;
@@ -42,8 +41,9 @@ export default async function loader(input, inputMap) {
42
41
return ;
43
42
}
44
43
45
- const { context, resolve, addDependency, emitWarning } = this ;
44
+ const { fs , context, resolve, addDependency, emitWarning } = this ;
46
45
const resolver = promisify ( resolve ) ;
46
+ const reader = promisify ( fs . readFile ) . bind ( fs ) ;
47
47
48
48
if ( url . toLowerCase ( ) . startsWith ( 'data:' ) ) {
49
49
const dataURL = parseDataURL ( url ) ;
@@ -102,9 +102,9 @@ export default async function loader(input, inputMap) {
102
102
}
103
103
104
104
urlResolved = urlResolved . toString ( ) ;
105
+
105
106
addDependency ( urlResolved ) ;
106
107
107
- const reader = promisify ( fs . readFile ) ;
108
108
const content = await reader ( urlResolved ) ;
109
109
let map ;
110
110
@@ -146,7 +146,7 @@ export default async function loader(input, inputMap) {
146
146
if ( path . isAbsolute ( fullPath ) ) {
147
147
return originalData
148
148
? { source : fullPath , content : originalData }
149
- : readFile ( fullPath , 'utf-8' , emitWarning ) ;
149
+ : readFile ( fullPath , emitWarning , reader ) ;
150
150
}
151
151
152
152
let fullPathResolved ;
@@ -172,7 +172,7 @@ export default async function loader(input, inputMap) {
172
172
source : fullPathResolved ,
173
173
content : originalData ,
174
174
}
175
- : readFile ( fullPathResolved , 'utf-8' , emitWarning ) ;
175
+ : readFile ( fullPathResolved , emitWarning , reader ) ;
176
176
} )
177
177
) ;
178
178
} catch ( error ) {
0 commit comments