Repository navigation
fix(@angular/build): include source map hashes in optimized chunk hashes - #34583
Open
alan-agius4 wants to merge 1 commit into
Open
alan-agius4 wants to merge 1 commit into
alan-agius4 wants to merge 1 commit into
Conversation
When `sourceMap.scripts` is enabled, `injectDebugIds` appends a `//# debugId=<uuid>` comment derived from the chunk's source map content to each emitted browser JS file after chunk optimization. While esbuild includes source map content when computing output chunk hashes, `optimizeChunks` strips the esbuild hash and relies on Rolldown to compute `[hash]` for optimized chunks. Because Rolldown only hashed the JS code and not the input source maps, a source change that only altered the source map (such as adding or removing type definitions or comments that shifted line numbers) changed the `debugId` bytes in the emitted JS file and its SRI hash in `index.html` without changing the chunk's filename. Implement `augmentChunkHash` in the chunk optimizer's `angular-bundle` plugin to include the input source map hashes when source maps are enabled, and invalidate cached `BuildOutputFile` hashes when `contents` are mutated. Closes angular#34574
There was a problem hiding this comment.
Code Review
This pull request ensures that optimized chunk filenames are updated when source map changes occur, even if the emitted JS code remains unchanged. This is achieved by augmenting the chunk hash with module source map hashes in the chunk optimizer and updating convertOutputFile to dynamically calculate and cache file hashes when contents change. A test case has been added to verify this behavior. The review feedback suggests improving type safety in bundler-files.ts by using a type assertion and nullish coalescing when initializing cachedHash to prevent potential TypeScript compilation errors under strict null checks.
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
sourceMap.scriptsis enabled,injectDebugIdsappends a//# debugId=<uuid>comment derived from the chunk's source map content to each emitted browser JS file after chunk optimization.While esbuild includes source map content when computing output chunk hashes,
optimizeChunksstrips the esbuild hash and relies on Rolldown to compute[hash]for optimized chunks. Because Rolldown only hashed the JS code and not the input source maps, a source change that only altered the source map (such as adding or removing type definitions or comments that shifted line numbers) changed thedebugIdbytes in the emitted JS file and its SRI hash inindex.htmlwithout changing the chunk's filename.Implement
augmentChunkHashin the chunk optimizer'sangular-bundleplugin to include the input source map hashes when source maps are enabled, and invalidate cachedBuildOutputFilehashes whencontentsare mutated.Closes #34574