@@ -16,7 +16,8 @@ function Plugin(
16
16
/* config.files */ files ,
17
17
/* config.frameworks */ frameworks ,
18
18
customFileHandlers ,
19
- emitter ) {
19
+ emitter
20
+ ) {
20
21
webpackOptions = _ . clone ( webpackOptions ) || { }
21
22
webpackMiddlewareOptions = _ . clone ( webpackMiddlewareOptions || webpackServerOptions ) || { }
22
23
@@ -193,7 +194,7 @@ Plugin.prototype.readFile = function(file, callback) {
193
194
var middleware = this . middleware
194
195
var optionsCount = this . optionsCount
195
196
196
- function doRead ( ) {
197
+ var doRead = function ( ) {
197
198
if ( optionsCount > 1 ) {
198
199
async . times ( optionsCount , function ( idx , callback ) {
199
200
middleware . fileSystem . readFile ( '/_karma_webpack_/' + idx + '/' + file . replace ( / \\ / g, '/' ) , callback )
@@ -212,20 +213,27 @@ Plugin.prototype.readFile = function(file, callback) {
212
213
callback ( null , Buffer . concat ( contents ) )
213
214
} )
214
215
} else {
215
- middleware . fileSystem . readFile ( '/_karma_webpack_/' + file . replace ( / \\ / g, '/' ) , callback )
216
- }
217
- }
218
- if ( ! this . waiting ) {
219
- try {
220
- doRead ( )
221
- } catch ( e ) {
222
- // If this is an error from `readFileSync` method, wait for the next tick. Credit #69 @mewdriller
223
- if ( e . message . substring ( 0 , 20 ) === "Path doesn't exist '" ) { // eslint-disable-line quotes
224
- this . waiting = [ process . nextTick . bind ( process , this . readFile . bind ( this , file , callback ) ) ]
225
- } else {
226
- throw e
216
+ try {
217
+ var fileContents = middleware . fileSystem . readFileSync ( '/_karma_webpack_/' + file . replace ( / \\ / g, '/' ) )
218
+
219
+ callback ( undefined , fileContents )
220
+ } catch ( e ) {
221
+ // If this is an error from `readFileSync` method, wait for the next tick.
222
+ // Credit #69 @mewdriller
223
+ if ( e . code === 'ENOENT' ) {
224
+ // eslint-disable-line quotes
225
+ this . waiting = [ process . nextTick . bind ( process , this . readFile . bind ( this , file , callback ) ) ]
226
+
227
+ // throw otherwise
228
+ } else {
229
+ callback ( e )
230
+ }
227
231
}
228
232
}
233
+ } . bind ( this )
234
+
235
+ if ( ! this . waiting ) {
236
+ doRead ( )
229
237
} else {
230
238
// Retry to read once a build is finished
231
239
// do it on process.nextTick to catch changes while building
0 commit comments