Skip to content

refactor(@angular/build): extract shared breadth-first initial file analysis - #34407

Open
clydin wants to merge 1 commit into
angular:mainfrom
clydin:refactor/transitive-initial-files
Open

clydin wants to merge 1 commit into
angular:mainfrom
clydin:refactor/transitive-initial-files

Conversation

@clydin

@clydin clydin commented Oct 19, 2026

Copy link
Copy Markdown
Member

Previously, both BundlerContext and optimizeChunks maintained separate implementations for discovering transitive initial files and calculating their import depths from the esbuild metafile. Both implementations used a depth-first stack traversal via Array.prototype.pop(), which visited deeper branches in reverse import order and failed to propagate updated minimum depths to the transitive dependencies of already-visited chunks in diamond dependency graphs.

This commit extracts a shared findTransitiveInitialFiles helper that uses a breadth-first queue traversal over direct static imports. Processing chunks in breadth-first order guarantees that each file is discovered at its true shortest import depth on first visit, preserves the natural declaration order of imports at each depth level, and eliminates the duplicated metafile traversal logic across initial bundling and chunk optimization.

@clydin clydin added the target: minor This PR is targeted for the next minor release label Oct 19, 2026
@clydin
clydin force-pushed the refactor/transitive-initial-files branch 2 times, most recently from cc5e7af to 294c059 Compare October 19, 2026 22:03
@clydin
clydin marked this pull request as ready for review October 19, 2026 22:10

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the transitive initial files analysis by centralizing the logic into a new helper function, findTransitiveInitialFiles, in bundler-files.ts and adding comprehensive unit tests. The chunk optimizer and bundler context have been updated to use this new helper. Feedback on the changes suggests replacing the for...of loop in findTransitiveInitialFiles with a standard index-based for loop to avoid potential issues when mutating the queue array during iteration.

Comment thread packages/angular/build/src/tools/esbuild/bundler-files.ts Outdated
…nalysis

Previously, both `BundlerContext` and `optimizeChunks` maintained separate implementations for
discovering transitive initial files and calculating their import depths from the esbuild
metafile. Both implementations used a depth-first stack traversal via `Array.prototype.pop()`,
which visited deeper branches in reverse import order and failed to propagate updated minimum
depths to the transitive dependencies of already-visited chunks in diamond dependency graphs.

This commit extracts a shared `findTransitiveInitialFiles` helper that uses a breadth-first
queue traversal over direct static imports. Processing chunks in breadth-first order guarantees
that each file is discovered at its true shortest import depth on first visit, preserves the
natural declaration order of imports at each depth level, and eliminates the duplicated
metafile traversal logic across initial bundling and chunk optimization.
@clydin
clydin force-pushed the refactor/transitive-initial-files branch from 294c059 to 7751600 Compare October 19, 2026 22:15
@clydin clydin added the action: review The PR is still awaiting reviews from at least one requested reviewer label Oct 19, 2026
@clydin
clydin requested a review from alan-agius4 October 19, 2026 22:15
@alan-agius4 alan-agius4 added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: merge The PR is ready for merge by the caretaker area: @angular/build target: minor This PR is targeted for the next minor release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants