Skip to content

Commit 907ed72

Browse files
authored
fix(readFile): handle path doesn't exist error (#208)
1 parent ea79a26 commit 907ed72

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/karma-webpack.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function Plugin(
3030
// Webpack 2.1.0-beta.7+ will throw in error if both entry and plugins are not specified in options
3131
// https://github.com/webpack/webpack/commit/b3bc5427969e15fd3663d9a1c57dbd1eb2c94805
3232
if (!webpackOptions.entry) {
33-
webpackOptions.entry = function(){
33+
webpackOptions.entry = function() {
3434
return {}
3535
}
3636
};
@@ -206,7 +206,16 @@ Plugin.prototype.readFile = function(file, callback) {
206206
}
207207
}
208208
if (!this.waiting) {
209-
doRead()
209+
try {
210+
doRead()
211+
} catch (e) {
212+
// If this is an error from `readFileSync` method, wait for the next tick. Credit #69 @mewdriller
213+
if (e.message.substring(0, 20) === "Path doesn't exist '") { // eslint-disable-line quotes
214+
this.waiting = [process.nextTick.bind(process, this.readFile.bind(this, file, callback))]
215+
} else {
216+
throw e
217+
}
218+
}
210219
} else {
211220
// Retry to read once a build is finished
212221
// do it on process.nextTick to catch changes while building

0 commit comments

Comments
 (0)