fix(@angular/build): re-analyze exports on package.json change in library builder - #34218
alan-agius4 wants to merge 3 commits into
Conversation
…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.
There was a problem hiding this comment.
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.
… in library builder
… in library builder
| packageJsonPath: string, | ||
| packageName: string, | ||
| ): Map<string, NormalizedEntryPoint> { | ||
| if (!rawExports || (typeof rawExports !== 'string' && typeof rawExports !== 'object')) { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
Do we need to check bundleName and displayName here too?
| if (!newEntryPoints.has(name)) { | ||
| buildState.previousBundleResults.delete(name); | ||
| } |
There was a problem hiding this comment.
Should this also check if the entry point path changed as well?
PR Checklist
Please check to confirm your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
When running the library builder in watch mode and updating
package.json, newly added, removed, or changed entry points inexportsare not detected or re-analyzed.Issue Number: N/A
What is the new behavior?
When
package.jsonchanges in watch mode, theexportsfield 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.tsand added unit test coverage forgetEntryPointBundleName,normalizeEntryPoints,haveEntryPointsChanged, andupdateWatchedEntryPoints.Does this PR introduce a breaking change?
Other information