Skip to content

Commit 7040590

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 7040590

File tree

1 file changed

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

1 file changed

+14
-6
lines changed

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

Lines changed: 14 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,17 @@ export default class AddCommandModule
508505
);
509506
}
510507

508+
// Avoid fully 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(
512+
context.packageIdentifier.name,
513+
// `save-prefix` option is ignored by some package managers so the caret is needed to ensure
514+
// that the value in the project package.json is correct.
515+
'^' + manifest.version,
516+
);
517+
}
518+
511519
context.hasSchematics = !!manifest.schematics;
512520
context.savePackage = manifest['ng-add']?.save;
513521
context.collectionName = manifest.name;

0 commit comments

Comments
 (0)