Repository navigation
fix(@angular/build): coalesce external watcher directories to avoid macOS FSEvents limit - #34347
Merged
Merged
Conversation
…acOS FSEvents limit Previously, `ParcelExternalManager` immediately created a separate `@parcel/watcher` subscription for the parent directory of every watched file outside the workspace root. In monorepo setups where an application imports from hundreds of external library directories and hoisted `node_modules` packages, this exceeded macOS's ~512 per-process `FSEvents` stream limit, causing subsequent subscriptions to silently fail and miss file changes. To prevent exhausting native watcher streams, `ParcelExternalManager` now normalizes external `node_modules` file paths to their package root directory and batches synchronous file additions and removals within a microtask so nested child directories are subsumed before subscribing. When the number of external target directories exceeds the subscription budget of 256, a prefix tree is used to iteratively collapse the deepest branching subdirectories into common ancestors while preferring directories that do not contain `workspaceRoot`. Additionally, if `parcelWatcher.subscribe()` rejects for an existing directory on disk, the manager dynamically lowers its subscription budget and re-reconciles into higher-level ancestor directories. Closes angular#34246
clydin
force-pushed
the
fix/external-watcher-fsevents-limit
branch
from
October 15, 2026 02:09
b903d5f to
cf1f3a3
Compare
clydin
marked this pull request as ready for review
October 15, 2026 02:09
There was a problem hiding this comment.
Code Review
This pull request refactors the ParcelExternalManager in the Angular build package to optimize directory subscriptions when using @parcel/watcher. It introduces a directory prefix tree (trie) to coalesce multiple external directory subscriptions into common ancestors when the subscription count exceeds a budget (defaulting to 256), preventing macOS FSEvents stream limit errors. Additionally, it adds comprehensive unit tests to verify batching, path normalization, coalescing logic, and dynamic budget reduction. There are no review comments, and the changes look solid and well-tested.
alan-agius4
approved these changes
Oct 15, 2026
Collaborator
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.
Previously,
ParcelExternalManagerimmediately created a separate@parcel/watchersubscription for the parent directory of every watched file outside the workspace root. In monorepo setups where an application imports from hundreds of external library directories and hoistednode_modulespackages, this exceeded macOS's ~512 per-processFSEventsstream limit, causing subsequent subscriptions to silently fail and miss file changes.To prevent exhausting native watcher streams,
ParcelExternalManagernow normalizes externalnode_modulesfile paths to their package root directory and batches synchronous file additions and removals within a microtask so nested child directories are subsumed before subscribing. When the number of external target directories exceeds the subscription budget of 256, a prefix tree is used to iteratively collapse the deepest branching subdirectories into common ancestors while preferring directories that do not containworkspaceRoot. Additionally, ifparcelWatcher.subscribe()rejects for an existing directory on disk, the manager dynamically lowers its subscription budget and re-reconciles into higher-level ancestor directories.Closes #34246