Repository navigation
fix(@angular/build): include source map hashes in optimized chunk hashes - #34583
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 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. |
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