Skip to content

Commit c18d934

Browse files
committed
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 name and 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.
1 parent 8adfc22 commit c18d934

File tree

1 file changed

+8
-6
lines changed
  • packages/angular/cli/src/commands/add

1 file changed

+8
-6
lines changed

packages/angular/cli/src/commands/add/cli.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -489,12 +489,9 @@ export default class AddCommandModule
489489

490490
let manifest;
491491
try {
492-
manifest = await this.context.packageManager.getManifest(
493-
context.packageIdentifier.toString(),
494-
{
495-
registry,
496-
},
497-
);
492+
manifest = await this.context.packageManager.getManifest(context.packageIdentifier, {
493+
registry,
494+
});
498495
} catch (e) {
499496
assertIsError(e);
500497
throw new CommandError(
@@ -508,6 +505,11 @@ export default class AddCommandModule
508505
);
509506
}
510507

508+
// Avoid resolving the package version from the registry again in later steps
509+
if (context.packageIdentifier.registry) {
510+
context.packageIdentifier = npa.resolve(manifest.name, manifest.version);
511+
}
512+
511513
context.hasSchematics = !!manifest.schematics;
512514
context.savePackage = manifest['ng-add']?.save;
513515
context.collectionName = manifest.name;

0 commit comments

Comments
 (0)