Skip to content

perf(@angular/cli): cache root manifest and resolve restricted package exports in ng add#32717

Open
clydin wants to merge 1 commit intoangular:mainfrom
clydin:cli/add-perf-package-json
Open

perf(@angular/cli): cache root manifest and resolve restricted package exports in ng add#32717
clydin wants to merge 1 commit intoangular:mainfrom
clydin:cli/add-perf-package-json

Conversation

@clydin
Copy link
Member

@clydin clydin commented Mar 6, 2026

This change enhances the ng add command's performance by caching the root project manifest (package.json) to avoid redundant disk reads and JSON parsing during peer dependency conflict checks.

Additionally, it improves the robustness of package.json resolution for installed packages. Previously, resolving package.json could fail if a third-party package used the Node.js "exports" field without explicitly exporting its package.json. The CLI now correctly handles this by falling back to resolving the package's entry point and traversing upwards to find the manifest.

@clydin clydin added the target: minor This PR is targeted for the next minor release label Mar 6, 2026
@angular-robot angular-robot bot added area: performance Issues related to performance area: @angular/cli labels Mar 6, 2026
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

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 two valuable improvements to the ng add command. First, it caches the root project's package.json, which effectively reduces redundant file reads and parsing, leading to better performance. Second, it enhances the package resolution logic to robustly locate a package's package.json even when it's not directly exported, by implementing a fallback strategy that traverses up from the package's main entry point.

My review has identified a couple of minor areas for improvement: an unused import and an empty catch block that could benefit from logging for better debuggability. Apart from these points, the changes are well-implemented and address the stated goals of performance and robustness.

@clydin clydin force-pushed the cli/add-perf-package-json branch from ebf81d6 to 11bc2e6 Compare March 6, 2026 19:47
…e exports in ng add

This change enhances the `ng add` command's performance by caching the root project manifest (`package.json`) to avoid redundant disk reads and JSON parsing during peer dependency conflict checks.

Additionally, it improves the robustness of `package.json` resolution for installed packages. Previously, resolving `package.json` could fail if a third-party package used the Node.js `"exports"` field without explicitly exporting its `package.json`. The CLI now correctly handles this by falling back to resolving the package's entry point and traversing upwards to find the manifest.
@clydin clydin force-pushed the cli/add-perf-package-json branch from 11bc2e6 to 695ec87 Compare March 6, 2026 19:49
@clydin clydin requested review from alan-agius4 March 6, 2026 20:06
@clydin clydin added action: review The PR is still awaiting reviews from at least one requested reviewer labels Mar 6, 2026
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/cli area: performance Issues related to performance 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