Skip to content

Commit 9ec3868

Browse files
authoredAug 27, 2020
Merge pull request #176 from webpack/feature/logging
add logging for recursive watchers
2 parents ce3b818 + 0158fd5 commit 9ec3868

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed
 

‎.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ matrix:
1313
stage: basic
1414
- os: osx
1515
node_js: "14"
16+
env: WATCHPACK_RECURSIVE_WATCHER_LOGGING=1
1617
stage: basic
1718
- os: osx
1819
node_js: "14"

‎azure-pipelines.yml

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ jobs:
7070
- script: |
7171
set -e
7272
export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"
73+
export WATCHPACK_RECURSIVE_WATCHER_LOGGING=1
7374
yarn cover --report lcovonly
7475
displayName: "Run tests with coverage"
7576

‎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

‎test/ManyWatchers.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const fixtures = path.join(__dirname, "fixtures");
1111
const testHelper = new TestHelper(fixtures);
1212

1313
describe("ManyWatchers", function() {
14-
this.timeout(180000);
14+
this.timeout(240000);
1515
beforeEach(testHelper.before);
1616
afterEach(testHelper.after);
1717

0 commit comments

Comments
 (0)
Please sign in to comment.