Skip to content

Commit a15db28

Browse files
committed
perf(@angular/cli): cache resolved specific version in package manager abstraction
When fetching a package manifest for a tag or range, also cache the result using the resolved specific version. This avoids redundant lookups if the specific version is requested subsequently. Also removes an unused import.
1 parent 6bef168 commit a15db28

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

packages/angular/cli/src/package-managers/package-manager.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import { join } from 'node:path';
1616
import npa from 'npm-package-arg';
1717
import { maxSatisfying } from 'semver';
18-
import { ErrorInfo, PackageManagerError } from './error';
18+
import { PackageManagerError } from './error';
1919
import { Host } from './host';
2020
import { Logger } from './logger';
2121
import { PackageManagerDescriptor } from './package-manager-descriptor';
@@ -407,11 +407,22 @@ export class PackageManager {
407407

408408
const cacheKey = options.registry ? `${specifier}|${options.registry}` : specifier;
409409

410-
return this.#fetchAndParse(
410+
const manifest = await this.#fetchAndParse(
411411
commandArgs,
412412
(stdout, logger) => this.descriptor.outputParsers.getRegistryManifest(stdout, logger),
413413
{ ...options, cache: this.#manifestCache, cacheKey },
414414
);
415+
416+
// If the provided version was not a specific version, also cache the specific fetched version
417+
if (manifest && manifest.version !== version) {
418+
const manifestSpecifier = `${manifest.name}@${manifest.version}`;
419+
const manifestCacheKey = options.registry
420+
? `${manifestSpecifier}|${options.registry}`
421+
: manifestSpecifier;
422+
this.#manifestCache.set(manifestCacheKey, manifest);
423+
}
424+
425+
return manifest;
415426
}
416427

417428
/**

0 commit comments

Comments
 (0)