Skip to content

Commit 994f2b0

Browse files
committedAug 27, 2020
add logging
1 parent ce3b818 commit 994f2b0

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
 

‎lib/watchEventSource.js

+29
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ const SUPPORTS_RECURSIVE_WATCHING = IS_OSX || IS_WIN;
1616
const watcherLimit =
1717
+process.env.WATCHPACK_WATCHER_LIMIT || (IS_OSX ? 2000 : 10000);
1818

19+
const recursiveWatcherLogging = !!process.env
20+
.WATCHPACK_RECURSIVE_WATCHER_LOGGING;
21+
1922
let isBatch = false;
2023
let watcherCount = 0;
2124

@@ -93,12 +96,28 @@ class RecursiveWatcher {
9396
this.watcher = watcher;
9497
watcher.on("change", (type, filename) => {
9598
if (!filename) {
99+
if (recursiveWatcherLogging) {
100+
process.stderr.write(
101+
`[watchpack] dispatch ${type} event in recursive watcher (${
102+
this.rootPath
103+
}) to all watchers\n`
104+
);
105+
}
96106
for (const w of this.mapWatcherToPath.keys()) {
97107
w.emit("change", type);
98108
}
99109
} else {
100110
const dir = path.dirname(filename);
101111
const watchers = this.mapPathToWatchers.get(dir);
112+
if (recursiveWatcherLogging) {
113+
process.stderr.write(
114+
`[watchpack] dispatch ${type} event in recursive watcher (${
115+
this.rootPath
116+
}) for '${filename}' to ${
117+
watchers ? watchers.size : 0
118+
} watchers\n`
119+
);
120+
}
102121
if (watchers === undefined) return;
103122
for (const w of watchers) {
104123
w.emit("change", type, path.basename(filename));
@@ -118,6 +137,11 @@ class RecursiveWatcher {
118137
});
119138
}
120139
watcherCount++;
140+
if (recursiveWatcherLogging) {
141+
process.stderr.write(
142+
`[watchpack] created recursive watcher at ${rootPath}\n`
143+
);
144+
}
121145
}
122146

123147
add(filePath, watcher) {
@@ -147,6 +171,11 @@ class RecursiveWatcher {
147171
recursiveWatchers.delete(this.rootPath);
148172
watcherCount--;
149173
if (this.watcher) this.watcher.close();
174+
if (recursiveWatcherLogging) {
175+
process.stderr.write(
176+
`[watchpack] closed recursive watcher at ${this.rootPath}\n`
177+
);
178+
}
150179
}
151180
}
152181

0 commit comments

Comments
 (0)
Please sign in to comment.