Repository navigation
refactor(@angular/build): extract shared breadth-first initial file analysis - #34407
Conversation
cc5e7af to
294c059
Compare
There was a problem hiding this comment.
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.
…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.
294c059 to
7751600
Compare
|
This PR was merged into the repository. The changes were merged into the following branches:
|
|
This pull request has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Previously, both
BundlerContextandoptimizeChunksmaintained separate implementations for discovering transitive initial files and calculating their import depths from the esbuild metafile. Both implementations used a depth-first stack traversal viaArray.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
findTransitiveInitialFileshelper 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.