22 MIT License http://www.opensource.org/licenses/mit-license.php
33 Author Tobias Koppers @sokra
44*/
5- import fs from 'fs' ;
65import path from 'path' ;
76
87import { promisify } from 'util' ;
@@ -42,8 +41,9 @@ export default async function loader(input, inputMap) {
4241 return ;
4342 }
4443
45- const { context, resolve, addDependency, emitWarning } = this ;
44+ const { fs , context, resolve, addDependency, emitWarning } = this ;
4645 const resolver = promisify ( resolve ) ;
46+ const reader = promisify ( fs . readFile ) . bind ( fs ) ;
4747
4848 if ( url . toLowerCase ( ) . startsWith ( 'data:' ) ) {
4949 const dataURL = parseDataURL ( url ) ;
@@ -102,9 +102,9 @@ export default async function loader(input, inputMap) {
102102 }
103103
104104 urlResolved = urlResolved . toString ( ) ;
105+
105106 addDependency ( urlResolved ) ;
106107
107- const reader = promisify ( fs . readFile ) ;
108108 const content = await reader ( urlResolved ) ;
109109 let map ;
110110
@@ -146,7 +146,7 @@ export default async function loader(input, inputMap) {
146146 if ( path . isAbsolute ( fullPath ) ) {
147147 return originalData
148148 ? { source : fullPath , content : originalData }
149- : readFile ( fullPath , 'utf-8' , emitWarning ) ;
149+ : readFile ( fullPath , emitWarning , reader ) ;
150150 }
151151
152152 let fullPathResolved ;
@@ -172,7 +172,7 @@ export default async function loader(input, inputMap) {
172172 source : fullPathResolved ,
173173 content : originalData ,
174174 }
175- : readFile ( fullPathResolved , 'utf-8' , emitWarning ) ;
175+ : readFile ( fullPathResolved , emitWarning , reader ) ;
176176 } )
177177 ) ;
178178 } catch ( error ) {
0 commit comments