Skip to content

Commit 6072f3b

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
1 parent fa835be commit 6072f3b

File tree

2 files changed

+29
-20
lines changed

2 files changed

+29
-20
lines changed

lib/DirectoryWatcher.js

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ class DirectoryWatcher extends EventEmitter {
106106
}
107107
}
108108
};
109-
this.watcher.on("change", this.onWatchEvent.bind(this));
110109
} else {
111110
if (IS_OSX) {
112111
this.watchInParentDirectory();
@@ -628,21 +627,34 @@ class DirectoryWatcher extends EventEmitter {
628627
}
629628
});
630629
for (const itemPath of itemPaths) {
631-
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) => {
632645
if (this.closed) return;
633646
if (err2) {
634-
if (
635-
err2.code === "ENOENT" ||
636-
err2.code === "EPERM" ||
637-
err2.code === "EACCES" ||
638-
err2.code === "EBUSY"
639-
) {
640-
this.setMissing(itemPath, initial, "scan (" + err2.code + ")");
641-
} else {
642-
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);
643657
}
644-
itemFinished();
645-
return;
646658
}
647659
if (stats.isFile() || stats.isSymbolicLink()) {
648660
if (stats.mtime) {
@@ -665,12 +677,7 @@ class DirectoryWatcher extends EventEmitter {
665677
);
666678
}
667679
itemFinished();
668-
};
669-
if (this.watcherManager.options.followSymlinks) {
670-
fs.stat(itemPath, handleStats);
671-
} else {
672-
fs.lstat(itemPath, handleStats);
673-
}
680+
});
674681
}
675682
itemFinished();
676683
});

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)