Skip to content

Commit 409ef51

Browse files
committed
Follow symlinks
Solves #231 and updates the README to match.
1 parent dc690bb commit 409ef51

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ watchpack high level API doesn't map directly to watchers. Instead a three level
1919
- The real watchers are created by the `DirectoryWatcher`.
2020
- Files are never watched directly. This should keep the watcher count low.
2121
- Watching can be started in the past. This way watching can start after file reading.
22-
- Symlinks are not followed, instead the symlink is watched.
2322

2423
## API
2524

lib/DirectoryWatcher.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,8 @@ class DirectoryWatcher extends EventEmitter {
392392
const checkStats = () => {
393393
if (this.closed) return;
394394
this._activeEvents.set(filename, false);
395-
fs.lstat(filePath, (err, stats) => {
395+
396+
const handleStats = (err, stats) => {
396397
if (this.closed) return;
397398
if (this._activeEvents.get(filename) === true) {
398399
process.nextTick(checkStats);
@@ -438,8 +439,15 @@ class DirectoryWatcher extends EventEmitter {
438439
false,
439440
eventType
440441
);
442+
if (
443+
this.watcherManager.options.followSymlinks &&
444+
stats.isSymbolicLink()
445+
) {
446+
fs.stat(filePath, handleStats);
447+
}
441448
}
442-
});
449+
};
450+
fs.lstat(filePath, handleStats);
443451
};
444452
process.nextTick(checkStats);
445453
} else {
@@ -625,7 +633,7 @@ class DirectoryWatcher extends EventEmitter {
625633
}
626634
});
627635
for (const itemPath of itemPaths) {
628-
fs.lstat(itemPath, (err2, stats) => {
636+
const handleStats = (err2, stats) => {
629637
if (this.closed) return;
630638
if (err2) {
631639
if (
@@ -652,6 +660,12 @@ class DirectoryWatcher extends EventEmitter {
652660
true,
653661
"scan (file)"
654662
);
663+
if (
664+
this.watcherManager.options.followSymlinks &&
665+
stats.isSymbolicLink()
666+
) {
667+
fs.stat(itemPath, handleStats);
668+
}
655669
} else if (stats.isDirectory()) {
656670
if (!initial || !this.directories.has(itemPath))
657671
this.setDirectory(
@@ -662,7 +676,8 @@ class DirectoryWatcher extends EventEmitter {
662676
);
663677
}
664678
itemFinished();
665-
});
679+
};
680+
fs.lstat(itemPath, handleStats);
666681
}
667682
itemFinished();
668683
});

0 commit comments

Comments
 (0)