Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion packages/angular/cli/src/package-managers/package-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import { join, relative, resolve } from 'node:path';
import npa from 'npm-package-arg';
import { maxSatisfying, valid } from 'semver';
import { maxSatisfying, satisfies, valid, validRange } from 'semver';
import { PackageManagerError } from './error';
import { Host } from './host';
import { Logger } from './logger';
Expand Down Expand Up @@ -564,6 +564,15 @@ export class PackageManager {
{ ...options, cache: this.#manifestCache, cacheKey },
);

// Modern yarn returns the latest version instead of an error when the requested one does not exist.
if (
manifest &&
validRange(version) &&
!satisfies(manifest.version, version, { includePrerelease: true })
) {
return null;
}
Comment thread
MeAkib marked this conversation as resolved.
Resolved

// If the provided version was not a specific version, also cache the specific fetched version
if (manifest && manifest.version !== version) {
const manifestSpecifier = `${manifest.name}@${manifest.version}`;
Expand Down
15 changes: 15 additions & 0 deletions packages/angular/cli/src/package-managers/package-manager_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,21 @@ describe('PackageManager', () => {
});

describe('getRegistryManifest', () => {
it('should return null when the fetched manifest does not match the requested version', async () => {
// Modern yarn falls back to the latest version when the requested version does not exist.
const pm = new PackageManager(host, '/tmp', SUPPORTED_PACKAGE_MANAGERS['yarn']);
runCommandSpy.and.resolveTo({
stdout: JSON.stringify({ name: 'foo', version: '2.0.0' }),
stderr: '',
});

expect(await pm.getRegistryManifest('foo', '99.99.99')).toBeNull();
expect(await pm.getRegistryManifest('foo', '^99.0.0')).toBeNull();
expect(await pm.getRegistryManifest('foo', '^2.0.0')).toEqual(
jasmine.objectContaining({ version: '2.0.0' }),
);
});

it('should quote complex range specifiers when required by the host', async () => {
// Simulate a quoting host
Object.assign(host, { requiresQuoting: true });
Expand Down
Loading
⌂ Proxy