Skip to content

Commit 05c4898

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 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 05c4898

File tree

1 file changed

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

1 file changed

+9
-6
lines changed

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

Lines changed: 9 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,12 @@ 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+
assert(context.packageIdentifier.name, 'Registry package identifier must have a name');
511+
context.packageIdentifier = npa.resolve(context.packageIdentifier.name, manifest.version);
512+
}
513+
511514
context.hasSchematics = !!manifest.schematics;
512515
context.savePackage = manifest['ng-add']?.save;
513516
context.collectionName = manifest.name;

0 commit comments

Comments
 (0)