Skip to content

Commit

Permalink
Follow symlinks
Browse files Browse the repository at this point in the history
Solves webpack#231 and updates the README to match.
  • Loading branch information
ArjhanToteck committed Mar 8, 2024
1 parent dc690bb commit 409ef51
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ watchpack high level API doesn't map directly to watchers. Instead a three level
- The real watchers are created by the `DirectoryWatcher`.
- Files are never watched directly. This should keep the watcher count low.
- Watching can be started in the past. This way watching can start after file reading.
- Symlinks are not followed, instead the symlink is watched.

## API

Expand Down
23 changes: 19 additions & 4 deletions lib/DirectoryWatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,8 @@ class DirectoryWatcher extends EventEmitter {
const checkStats = () => {
if (this.closed) return;
this._activeEvents.set(filename, false);
fs.lstat(filePath, (err, stats) => {

const handleStats = (err, stats) => {
if (this.closed) return;
if (this._activeEvents.get(filename) === true) {
process.nextTick(checkStats);
Expand Down Expand Up @@ -438,8 +439,15 @@ class DirectoryWatcher extends EventEmitter {
false,
eventType
);
if (
this.watcherManager.options.followSymlinks &&
stats.isSymbolicLink()
) {
fs.stat(filePath, handleStats);
}
}
});
};
fs.lstat(filePath, handleStats);
};
process.nextTick(checkStats);
} else {
Expand Down Expand Up @@ -625,7 +633,7 @@ class DirectoryWatcher extends EventEmitter {
}
});
for (const itemPath of itemPaths) {
fs.lstat(itemPath, (err2, stats) => {
const handleStats = (err2, stats) => {
if (this.closed) return;
if (err2) {
if (
Expand All @@ -652,6 +660,12 @@ class DirectoryWatcher extends EventEmitter {
true,
"scan (file)"
);
if (
this.watcherManager.options.followSymlinks &&
stats.isSymbolicLink()
) {
fs.stat(itemPath, handleStats);
}
} else if (stats.isDirectory()) {
if (!initial || !this.directories.has(itemPath))
this.setDirectory(
Expand All @@ -662,7 +676,8 @@ class DirectoryWatcher extends EventEmitter {
);
}
itemFinished();
});
};
fs.lstat(itemPath, handleStats);
}
itemFinished();
});
Expand Down

0 comments on commit 409ef51

Please sign in to comment.