Skip to content

Commit 42817ae

Browse files
committed
refactor(@angular/cli): correctly handle yarn classic tag manifest fetching
Introduces a `requiresManifestTagLookup` property to `PackageManagerDescriptor` to control whether a package manager needs an explicit metadata lookup for tags (or when no `fetchSpec` is provided) before attempting to fetch the full registry manifest. This change optimizes manifest fetching by enabling a preliminary metadata lookup for package managers like `yarn-classic` that require it to resolve tags to concrete versions.
1 parent c828c42 commit 42817ae

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ export interface PackageManagerDescriptor {
7373
/** The command to fetch the registry manifest of a package. */
7474
readonly getManifestCommand: readonly string[];
7575

76+
/** Whether a tag needs a lookup prior to fetching a registry manifest. */
77+
readonly requiresManifestTagLookup?: boolean;
78+
7679
/** A function that formats the arguments for field-filtered registry views. */
7780
readonly viewCommandFieldArgFormatter?: (fields: readonly string[]) => string[];
7881

@@ -166,6 +169,7 @@ export const SUPPORTED_PACKAGE_MANAGERS = {
166169
versionCommand: ['--version'],
167170
listDependenciesCommand: ['list', '--depth=0', '--json'],
168171
getManifestCommand: ['info', '--json'],
172+
requiresManifestTagLookup: true,
169173
outputParsers: {
170174
listDependencies: parseYarnClassicDependencies,
171175
getRegistryManifest: parseYarnClassicManifest,

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,13 +397,26 @@ export class PackageManager {
397397
switch (type) {
398398
case 'range':
399399
case 'version':
400-
case 'tag':
400+
case 'tag': {
401401
if (!name) {
402402
throw new Error(`Could not parse package name from specifier: ${specifier}`);
403403
}
404404

405405
// `fetchSpec` is the version, range, or tag.
406-
return this.getRegistryManifest(name, fetchSpec ?? 'latest', options);
406+
let versionSpec = fetchSpec ?? 'latest';
407+
if ((type === 'tag' || !fetchSpec) && this.descriptor.requiresManifestTagLookup) {
408+
const metadata = await this.getRegistryMetadata(name, options);
409+
if (!metadata) {
410+
return null;
411+
}
412+
versionSpec = metadata['dist-tags'][versionSpec];
413+
if (!versionSpec) {
414+
return null;
415+
}
416+
}
417+
418+
return this.getRegistryManifest(name, versionSpec, options);
419+
}
407420
case 'directory': {
408421
if (!fetchSpec) {
409422
throw new Error(`Could not parse directory path from specifier: ${specifier}`);

0 commit comments

Comments
 (0)