Skip to content
Merged
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
15 changes: 10 additions & 5 deletions packages/angular/cli/src/commands/add/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { analytics, tags } from '@angular-devkit/core';
import { NodePackageDoesNotSupportSchematics } from '@angular-devkit/schematics/tools';
import npa from 'npm-package-arg';
import { dirname, join } from 'path';
import { compare, intersects, prerelease, satisfies, valid } from 'semver';
import { Range, compare, intersects, prerelease, satisfies, valid } from 'semver';
import { Argv } from 'yargs';
import { PackageManager } from '../../../lib/config/workspace-schema';
import { isPackageNameSafeForAnalytics } from '../../analytics/analytics';
Expand Down Expand Up @@ -47,9 +47,11 @@ interface AddCommandArgs extends SchematicsCommandArgs {
* when attempting to find a compatible version for a package.
* The key is a package name and the value is a SemVer range of versions to exclude.
*/
const packageVersionExclusions: Record<string, string | undefined> = {
// @angular/localize@9.x versions do not have peer dependencies setup
'@angular/localize': '9.x',
const packageVersionExclusions: Record<string, string | Range> = {
// @angular/localize@9.x and earlier versions as well as @angular/localize@10.0 prereleases do not have peer dependencies setup.
'@angular/localize': '<10.0.0',
// @angular/material@7.x versions have unbounded peer dependency ranges (>=7.0.0).
'@angular/material': '7.x',
};

export class AddCommandModule
Expand Down Expand Up @@ -187,7 +189,10 @@ export class AddCommandModule
return false;
}
// Excluded package versions should not be considered
if (versionExclusions && satisfies(value.version, versionExclusions)) {
if (
versionExclusions &&
satisfies(value.version, versionExclusions, { includePrerelease: true })
) {
return false;
}

Expand Down
5 changes: 0 additions & 5 deletions tests/legacy-cli/e2e/tests/commands/add/version-specifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ export default async function () {
throw new Error('Installation was not skipped');
}

const output2 = await ng('add', '@angular/localize@latest', '--skip-confirmation');
if (output2.stdout.includes('Skipping installation: Package already installed')) {
throw new Error('Installation should not have been skipped');
}

// v12.2.0 has a package.json engine field that supports Node.js v16+
const output3 = await ng('add', '@angular/localize@12.2.0', '--skip-confirmation');
if (output3.stdout.includes('Skipping installation: Package already installed')) {
Expand Down