Skip to content

fix(@angular/build): improve library watch mode state invalidation and lazy asset matchers - #34426

Open
alan-agius4 wants to merge 7 commits into
angular:mainfrom
alan-agius4:fix/library-watch-mode-and-state
Open

alan-agius4 wants to merge 7 commits into
angular:mainfrom
alan-agius4:fix/library-watch-mode-and-state

Conversation

@alan-agius4

@alan-agius4 alan-agius4 commented Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Track hasPackageJsonError in the watch loop in builder.ts so loadPackageJson is retried on subsequent watch events even if package.json is not in the new changedFiles until package.json is fixed.
  • Watch styleIncludePaths in setupWatcher and also reset Sass worker pool caches (resetSassWorkerPoolCaches()) when .css files change in addition to .scss/.sass.
  • Lazily initialize #assetMatchers in BuilderState.collectAssets only when needed in incremental watch mode rather than unconditionally in new BuilderState().

Benchmark

Metric main Branch Delta
Runs (ms) 12295, 14056, 12316 13239, 12147, 12240
Mean (ms) 12889 ms 12542 ms -2.69%
Min (ms) 12295 ms 12147 ms -1.20%

…d lazy asset matchers

- Log uncaught errors in `executeBuild` and `loadPackageJson` in `builder.ts`, and track `hasPackageJsonError` in the watch loop so `loadPackageJson` is retried on subsequent watch events until `package.json` is fixed.
- Watch `styleIncludePaths` in `setupWatcher` and only call `resetSassWorkerPoolCaches()` when stylesheet files are added or removed or `package.json` changes, rather than on every in-place stylesheet edit.
- Lazily initialize `#assetMatchers` in `BuilderState.collectAssets` only on incremental watch builds rather than unconditionally in the constructor.
- Reset `compilationInstance` and clear cached `esmFiles`/`dtsFiles` and `previousBundleResults` when `compilationMode` changes, and mark entry point DTS files dirty when `declarationMap` changes.
- Prune non-asset paths from `#pendingAssetFiles` in `BuilderState.collectAssets` after `collectAssetsToEmit` completes.
@alan-agius4
alan-agius4 requested a review from clydin October 20, 2026 09:41
@alan-agius4 alan-agius4 added action: review The PR is still awaiting reviews from at least one requested reviewer target: minor This PR is targeted for the next minor release labels Oct 20, 2026
@alan-agius4
alan-agius4 marked this pull request as ready for review October 20, 2026 09:41

@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 introduces incremental build improvements for Angular libraries, including lazy asset matcher creation, pruning non-asset paths, and handling dynamic changes to compilationMode and declarationMap in watch mode. It also adds support for retrying package.json reloads after failures and watching style include paths. The review feedback suggests wrapping compilationInstance.close() in a try-catch block to avoid masking compilation errors during cleanup, and using a nullish coalescing operator when spreading styleIncludePaths to prevent potential runtime errors.

Comment thread packages/angular/build/src/builders/library/pipeline/compilation.ts Outdated
Comment thread packages/angular/build/src/builders/library/builder.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: review The PR is still awaiting reviews from at least one requested reviewer 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.

1 participant