From 70405909fb4bf08cfd4307c1cb52ae15bb4d0a39 Mon Sep 17 00:00:00 2001 From: Charles Lyding <19598772+clydin@users.noreply.github.com> Date: Fri, 6 Mar 2026 13:49:07 -0500 Subject: [PATCH] perf(@angular/cli): avoid redundant package version resolution in ng add The `ng add` command would previously resolve the package version from the registry multiple times during execution. This change updates the package identifier with the exact version from the manifest once it has been fetched from the registry, preventing subsequent redundant lookups. Additionally, the already-parsed package identifier is now passed directly to the package manager's `getManifest` method. --- packages/angular/cli/src/commands/add/cli.ts | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/angular/cli/src/commands/add/cli.ts b/packages/angular/cli/src/commands/add/cli.ts index a41c9b54c7f3..b84de70db580 100644 --- a/packages/angular/cli/src/commands/add/cli.ts +++ b/packages/angular/cli/src/commands/add/cli.ts @@ -489,12 +489,9 @@ export default class AddCommandModule let manifest; try { - manifest = await this.context.packageManager.getManifest( - context.packageIdentifier.toString(), - { - registry, - }, - ); + manifest = await this.context.packageManager.getManifest(context.packageIdentifier, { + registry, + }); } catch (e) { assertIsError(e); throw new CommandError( @@ -508,6 +505,17 @@ export default class AddCommandModule ); } + // Avoid fully resolving the package version from the registry again in later steps + if (context.packageIdentifier.registry) { + assert(context.packageIdentifier.name, 'Registry package identifier must have a name'); + context.packageIdentifier = npa.resolve( + context.packageIdentifier.name, + // `save-prefix` option is ignored by some package managers so the caret is needed to ensure + // that the value in the project package.json is correct. + '^' + manifest.version, + ); + } + context.hasSchematics = !!manifest.schematics; context.savePackage = manifest['ng-add']?.save; context.collectionName = manifest.name;