Skip to content

fix(@angular/build): re-analyze exports on package.json change in library builder - #34218

Open
alan-agius4 wants to merge 3 commits into
angular:mainfrom
alan-agius4:fix/library-watch-exports
Open

alan-agius4 wants to merge 3 commits into
angular:mainfrom
alan-agius4:fix/library-watch-exports

Conversation

@alan-agius4

Copy link
Copy Markdown
Collaborator

PR Checklist

Please check to confirm your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

When running the library builder in watch mode and updating package.json, newly added, removed, or changed entry points in exports are not detected or re-analyzed.

Issue Number: N/A

What is the new behavior?

When package.json changes in watch mode, the exports field is now re-analyzed to detect any added, removed, or modified entry points. New entry points are registered into watched files and trigger a re-compilation, while removed entry points are pruned from cached bundle results.

Also refactored entry point normalization logic into pipeline/entry-points.ts and added unit test coverage for getEntryPointBundleName, normalizeEntryPoints, haveEntryPointsChanged, and updateWatchedEntryPoints.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

…rary builder

When `package.json` changes in watch mode, the `exports` field is now
re-analyzed to detect any added, removed, or modified entry points.
New entry points are registered into watched files and trigger a
re-compilation, while removed entry points are pruned from cached
bundle results.

@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 support for dynamically re-analyzing entry points and recompiling them when package.json is modified during watch mode in the Angular library builder. It refactors entry point normalization into pipeline/entry-points.ts and adds helper functions to track and update watched entry points, accompanied by comprehensive unit and behavior tests. The review feedback highlights two key improvement opportunities: throwing an error if the name field is missing or removed from package.json during watch mode to avoid inconsistent states, and typing options.entryPoints as a mutable Map instead of ReadonlyMap in updateWatchedEntryPoints to ensure type safety upon reassignment.

Comment thread packages/angular/build/src/builders/library/builder.ts Outdated
Comment thread packages/angular/build/src/builders/library/pipeline/entry-points.ts Outdated
@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 Sep 30, 2026
@alan-agius4
alan-agius4 requested a review from clydin September 30, 2026 19:35
packageJsonPath: string,
packageName: string,
): Map<string, NormalizedEntryPoint> {
if (!rawExports || (typeof rawExports !== 'string' && typeof rawExports !== 'object')) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This could be an array as well: https://nodejs.org/api/packages.html#exports


for (const [name, oldEp] of oldEntryPoints) {
const newEp = newEntryPoints.get(name);
if (!newEp || newEp.entryFilePath !== oldEp.entryFilePath || newEp.subpath !== oldEp.subpath) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we need to check bundleName and displayName here too?

Comment on lines +222 to +224
if (!newEntryPoints.has(name)) {
buildState.previousBundleResults.delete(name);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should this also check if the entry point path changed as well?

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.

2 participants