fix(@angular/build): prevent chokidar from scanning unimported node_modules in watch mode - #34168
Merged
Merged
Conversation
There was a problem hiding this comment.
Code Review
This pull request enhances the file watcher to support detecting changes in linked packages inside node_modules (such as those created via npm link) when preserveSymlinks is enabled, while continuing to ignore unimported packages. The feedback focuses on addressing a potential watcher leak when packages are removed by implementing reference counting, and optimizing performance by avoiding expensive path normalization in isNodeModulesIgnored through a quick initial string check.
clydin
force-pushed
the
fix-chokidar-node-modules-watch
branch
2 times, most recently
from
September 24, 2026 23:13
a797fb2 to
df9dfab
Compare
alan-agius4
reviewed
Sep 25, 2026
clydin
force-pushed
the
fix-chokidar-node-modules-watch
branch
from
September 25, 2026 14:18
df9dfab to
3db30e3
Compare
alan-agius4
approved these changes
Sep 25, 2026
…odules in watch mode When using Chokidar (such as when `preserveSymlinks: true` is configured or polling is active), Chokidar's initial filesystem scan previously walked the entire `workspaceRoot`, including all of `node_modules`. Because `await once(watcher, 'ready')` blocks until the initial scan completes, this caused watch mode in commands like `ng test`, `ng serve`, and `ng build --watch` to hang for minutes before emitting the first build result. This commit introduces selective `node_modules` filtering in Chokidar: - `node_modules` packages corresponding to imported build files (e.g. `npm link` libraries, both unscoped and scoped) are allowed and their directories watched, retaining native symlink traversal. - All other unimported subdirectories in `node_modules` are pruned and ignored during the initial scan and subsequent directory visits. - Packages added dynamically via `watcher.add()` are registered and watched on the fly. Fixes angular#34162
clydin
force-pushed
the
fix-chokidar-node-modules-watch
branch
from
September 25, 2026 14:21
3db30e3 to
dcd5c67
Compare
Member
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When using Chokidar (such as when
preserveSymlinks: trueis configured or polling is active), Chokidar's initial filesystem scan previously walked the entireworkspaceRoot, including all ofnode_modules. Becauseawait once(watcher, 'ready')blocks until the initial scan completes, this caused watch mode in commands likeng test,ng serve, andng build --watchto hang for minutes before emitting the first build result.Fixes #34162