diff --git a/packages/angular/cli/src/commands/add/cli.ts b/packages/angular/cli/src/commands/add/cli.ts index d65cd78e4278..55768138e4f2 100644 --- a/packages/angular/cli/src/commands/add/cli.ts +++ b/packages/angular/cli/src/commands/add/cli.ts @@ -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'; @@ -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 = { - // @angular/localize@9.x versions do not have peer dependencies setup - '@angular/localize': '9.x', +const packageVersionExclusions: Record = { + // @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 @@ -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; } diff --git a/tests/legacy-cli/e2e/tests/commands/add/version-specifier.ts b/tests/legacy-cli/e2e/tests/commands/add/version-specifier.ts index 426f8d5b61e5..5b598ccc9cfb 100644 --- a/tests/legacy-cli/e2e/tests/commands/add/version-specifier.ts +++ b/tests/legacy-cli/e2e/tests/commands/add/version-specifier.ts @@ -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')) {