Skip to content

Commit b403508

Browse files
committed
Fixed polling
Calling stats synchronously seemed to do the trick Also fixed some formatting in watchEventSource.js because lint told me to Fixed polling error Fixed polling error
1 parent c54bf67 commit b403508

File tree

2 files changed

+30
-20
lines changed

2 files changed

+30
-20
lines changed

lib/DirectoryWatcher.js

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ class DirectoryWatcher extends EventEmitter {
111111
this.watchInParentDirectory();
112112
}
113113
this.watcher = watchEventSource.watch(this.path);
114-
this.watcher.on("change", this.onWatchEvent.bind(this));
115114
this.watcher.on("error", this.onWatcherError.bind(this));
115+
this.watcher.on("change", this.onWatchEvent.bind(this));
116116
}
117117
} catch (err) {
118118
this.onWatcherError(err);
@@ -627,21 +627,34 @@ class DirectoryWatcher extends EventEmitter {
627627
}
628628
});
629629
for (const itemPath of itemPaths) {
630-
const handleStats = (err2, stats) => {
630+
const handleStatsError = err2 => {
631+
if (
632+
err2.code === "ENOENT" ||
633+
err2.code === "EPERM" ||
634+
err2.code === "EACCES" ||
635+
err2.code === "EBUSY"
636+
) {
637+
this.setMissing(itemPath, initial, "scan (" + err2.code + ")");
638+
} else {
639+
this.onScanError(err2);
640+
}
641+
itemFinished();
642+
return;
643+
};
644+
fs.lstat(itemPath, (err2, stats) => {
631645
if (this.closed) return;
632646
if (err2) {
633-
if (
634-
err2.code === "ENOENT" ||
635-
err2.code === "EPERM" ||
636-
err2.code === "EACCES" ||
637-
err2.code === "EBUSY"
638-
) {
639-
this.setMissing(itemPath, initial, "scan (" + err2.code + ")");
640-
} else {
641-
this.onScanError(err2);
647+
handleStatsError(err2);
648+
}
649+
if (
650+
stats.isSymbolicLink() &&
651+
this.watcherManager.options.followSymlinks
652+
) {
653+
try {
654+
stats = fs.statSync(itemPath);
655+
} catch (err3) {
656+
handleStatsError(err3);
642657
}
643-
itemFinished();
644-
return;
645658
}
646659
if (stats.isFile() || stats.isSymbolicLink()) {
647660
if (stats.mtime) {
@@ -664,12 +677,7 @@ class DirectoryWatcher extends EventEmitter {
664677
);
665678
}
666679
itemFinished();
667-
};
668-
if (this.watcherManager.options.followSymlinks) {
669-
fs.stat(itemPath, handleStats);
670-
} else {
671-
fs.lstat(itemPath, handleStats);
672-
}
680+
});
673681
}
674682
itemFinished();
675683
});

lib/watchEventSource.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ class RecursiveWatcher {
9898
if (!filename) {
9999
if (recursiveWatcherLogging) {
100100
process.stderr.write(
101-
`[watchpack] dispatch ${type} event in recursive watcher (${this.rootPath}) to all watchers\n`
101+
`[watchpack] dispatch ${type} event in recursive watcher (${
102+
this.rootPath
103+
}) to all watchers\n`
102104
);
103105
}
104106
for (const w of this.mapWatcherToPath.keys()) {

0 commit comments

Comments
 (0)