Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(autowatch): add guard for missing file error #69

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,18 @@ Plugin.prototype.readFile = function(file, callback) {
middleware.fileSystem.readFile("/_karma_webpack_/" + file.replace(/\\/g, "/"), callback);
}
}
if(!this.waiting)
doRead();
if (!this.waiting) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why this fix is needed. Shouldn't be this.waiting truthy until all files are available?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have assumed so, but from testing on my local machine (Windows 7 x64), this.waiting was evaluating to false whenever a new file was added that matched the glob during a watch.

I really don't understand the internals that are going on here. I simply used the logic that I would have expected to run (in the this.waiting == true branch) in the case that we observed the specific error that was getting thrown. It's entirely possible there's a simpler / more elegant way to resolve this issue. If you've got any suggestions or improvements let me know and I'd be happy to update things.

try {
doRead();
} catch (e) {
// If this is an error from MemoryFileSystem's `readFileSync` method, wait for the next tick.
if (e.message.substring(0, 20) === "Path doesn't exist '") {
this.waiting = [process.nextTick.bind(process, this.readFile.bind(this, file, callback))];
} else {
throw e;
}
}
}
else
// Retry to read once a build is finished
// do it on process.nextTick to catch changes while building
Expand Down