@@ -51,9 +51,9 @@ function assetToScriptElement(asset, extraProps) {
51
51
)
52
52
}
53
53
54
- function assetToStyleString ( asset ) {
54
+ function assetToStyleString ( asset , { inputFileSystem } ) {
55
55
return new Promise ( ( resolve , reject ) => {
56
- fs . readFile ( asset . path , 'utf8' , ( err , data ) => {
56
+ inputFileSystem . readFile ( asset . path , 'utf8' , ( err , data ) => {
57
57
if ( err ) {
58
58
reject ( err )
59
59
return
@@ -69,9 +69,9 @@ function assetToStyleTag(asset, extraProps) {
69
69
} "${ extraPropsToString ( asset , extraProps ) } >`
70
70
}
71
71
72
- function assetToStyleTagInline ( asset , extraProps ) {
72
+ function assetToStyleTagInline ( asset , extraProps , { inputFileSystem } ) {
73
73
return new Promise ( ( resolve , reject ) => {
74
- fs . readFile ( asset . path , 'utf8' , ( err , data ) => {
74
+ inputFileSystem . readFile ( asset . path , 'utf8' , ( err , data ) => {
75
75
if ( err ) {
76
76
reject ( err )
77
77
return
@@ -100,9 +100,9 @@ function assetToStyleElement(asset, extraProps) {
100
100
)
101
101
}
102
102
103
- function assetToStyleElementInline ( asset , extraProps ) {
103
+ function assetToStyleElementInline ( asset , extraProps , { inputFileSystem } ) {
104
104
return new Promise ( ( resolve , reject ) => {
105
- fs . readFile ( asset . path , 'utf8' , ( err , data ) => {
105
+ inputFileSystem . readFile ( asset . path , 'utf8' , ( err , data ) => {
106
106
if ( err ) {
107
107
reject ( err )
108
108
return
@@ -162,6 +162,7 @@ class ChunkExtractor {
162
162
namespace = '' ,
163
163
outputPath,
164
164
publicPath,
165
+ inputFileSystem = fs ,
165
166
} = { } ) {
166
167
this . namespace = namespace
167
168
this . stats = stats || smartRequire ( statsFile )
@@ -170,6 +171,7 @@ class ChunkExtractor {
170
171
this . statsFile = statsFile
171
172
this . entrypoints = Array . isArray ( entrypoints ) ? entrypoints : [ entrypoints ]
172
173
this . chunks = [ ]
174
+ this . inputFileSystem = inputFileSystem
173
175
}
174
176
175
177
resolvePublicUrl ( filename ) {
@@ -342,7 +344,7 @@ class ChunkExtractor {
342
344
getCssString ( ) {
343
345
const mainAssets = this . getMainAssets ( 'style' )
344
346
const promises = mainAssets . map ( asset =>
345
- assetToStyleString ( asset ) . then ( data => data ) ,
347
+ assetToStyleString ( asset , this ) . then ( data => data ) ,
346
348
)
347
349
return Promise . all ( promises ) . then ( results => joinTags ( results ) )
348
350
}
@@ -355,7 +357,7 @@ class ChunkExtractor {
355
357
getInlineStyleTags ( extraProps = { } ) {
356
358
const mainAssets = this . getMainAssets ( 'style' )
357
359
const promises = mainAssets . map ( asset =>
358
- assetToStyleTagInline ( asset , extraProps ) . then ( data => data ) ,
360
+ assetToStyleTagInline ( asset , extraProps , this ) . then ( data => data ) ,
359
361
)
360
362
return Promise . all ( promises ) . then ( results => joinTags ( results ) )
361
363
}
@@ -368,7 +370,7 @@ class ChunkExtractor {
368
370
getInlineStyleElements ( extraProps = { } ) {
369
371
const mainAssets = this . getMainAssets ( 'style' )
370
372
const promises = mainAssets . map ( asset =>
371
- assetToStyleElementInline ( asset , extraProps ) . then ( data => data ) ,
373
+ assetToStyleElementInline ( asset , extraProps , this ) . then ( data => data ) ,
372
374
)
373
375
return Promise . all ( promises ) . then ( results => results )
374
376
}
0 commit comments