Skip to content

Commit

Permalink
add logging
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Aug 27, 2020
1 parent ce3b818 commit 994f2b0
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions lib/watchEventSource.js
Expand Up @@ -16,6 +16,9 @@ const SUPPORTS_RECURSIVE_WATCHING = IS_OSX || IS_WIN;
const watcherLimit =
+process.env.WATCHPACK_WATCHER_LIMIT || (IS_OSX ? 2000 : 10000);

const recursiveWatcherLogging = !!process.env
.WATCHPACK_RECURSIVE_WATCHER_LOGGING;

let isBatch = false;
let watcherCount = 0;

Expand Down Expand Up @@ -93,12 +96,28 @@ class RecursiveWatcher {
this.watcher = watcher;
watcher.on("change", (type, filename) => {
if (!filename) {
if (recursiveWatcherLogging) {
process.stderr.write(
`[watchpack] dispatch ${type} event in recursive watcher (${
this.rootPath
}) to all watchers\n`
);
}
for (const w of this.mapWatcherToPath.keys()) {
w.emit("change", type);
}
} else {
const dir = path.dirname(filename);
const watchers = this.mapPathToWatchers.get(dir);
if (recursiveWatcherLogging) {
process.stderr.write(
`[watchpack] dispatch ${type} event in recursive watcher (${
this.rootPath
}) for '${filename}' to ${
watchers ? watchers.size : 0
} watchers\n`
);
}
if (watchers === undefined) return;
for (const w of watchers) {
w.emit("change", type, path.basename(filename));
Expand All @@ -118,6 +137,11 @@ class RecursiveWatcher {
});
}
watcherCount++;
if (recursiveWatcherLogging) {
process.stderr.write(
`[watchpack] created recursive watcher at ${rootPath}\n`
);
}
}

add(filePath, watcher) {
Expand Down Expand Up @@ -147,6 +171,11 @@ class RecursiveWatcher {
recursiveWatchers.delete(this.rootPath);
watcherCount--;
if (this.watcher) this.watcher.close();
if (recursiveWatcherLogging) {
process.stderr.write(
`[watchpack] closed recursive watcher at ${this.rootPath}\n`
);
}
}
}

Expand Down

0 comments on commit 994f2b0

Please sign in to comment.