From 6072f3b1c60cedab433701eaf9fe32ef50065ce1 Mon Sep 17 00:00:00 2001 From: ArjhanToteck <38510221+ArjhanToteck@users.noreply.github.com> Date: Fri, 15 Mar 2024 20:09:57 -0600 Subject: [PATCH] Fixed polling Calling stats synchronously seemed to do the trick Also fixed some formatting in watchEventSource.js because lint told me to --- lib/DirectoryWatcher.js | 45 ++++++++++++++++++++++++----------------- lib/watchEventSource.js | 4 +++- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/lib/DirectoryWatcher.js b/lib/DirectoryWatcher.js index 00f8322..720c3c4 100644 --- a/lib/DirectoryWatcher.js +++ b/lib/DirectoryWatcher.js @@ -106,7 +106,6 @@ class DirectoryWatcher extends EventEmitter { } } }; - this.watcher.on("change", this.onWatchEvent.bind(this)); } else { if (IS_OSX) { this.watchInParentDirectory(); @@ -628,21 +627,34 @@ class DirectoryWatcher extends EventEmitter { } }); for (const itemPath of itemPaths) { - const handleStats = (err2, stats) => { + const handleStatsError = err2 => { + if ( + err2.code === "ENOENT" || + err2.code === "EPERM" || + err2.code === "EACCES" || + err2.code === "EBUSY" + ) { + this.setMissing(itemPath, initial, "scan (" + err2.code + ")"); + } else { + this.onScanError(err2); + } + itemFinished(); + return; + }; + fs.lstat(itemPath, (err2, stats) => { if (this.closed) return; if (err2) { - if ( - err2.code === "ENOENT" || - err2.code === "EPERM" || - err2.code === "EACCES" || - err2.code === "EBUSY" - ) { - this.setMissing(itemPath, initial, "scan (" + err2.code + ")"); - } else { - this.onScanError(err2); + handleStatsError(err2); + } + if ( + stats.isSymbolicLink() && + this.watcherManager.options.followSymlinks + ) { + try { + stats = fs.statSync(itemPath); + } catch (err3) { + handleStatsError(err3); } - itemFinished(); - return; } if (stats.isFile() || stats.isSymbolicLink()) { if (stats.mtime) { @@ -665,12 +677,7 @@ class DirectoryWatcher extends EventEmitter { ); } itemFinished(); - }; - if (this.watcherManager.options.followSymlinks) { - fs.stat(itemPath, handleStats); - } else { - fs.lstat(itemPath, handleStats); - } + }); } itemFinished(); }); diff --git a/lib/watchEventSource.js b/lib/watchEventSource.js index 6df9ab0..3583c2e 100644 --- a/lib/watchEventSource.js +++ b/lib/watchEventSource.js @@ -98,7 +98,9 @@ class RecursiveWatcher { if (!filename) { if (recursiveWatcherLogging) { process.stderr.write( - `[watchpack] dispatch ${type} event in recursive watcher (${this.rootPath}) to all watchers\n` + `[watchpack] dispatch ${type} event in recursive watcher (${ + this.rootPath + }) to all watchers\n` ); } for (const w of this.mapWatcherToPath.keys()) {