From 1fd51966377fac4d12b15bf9b21994f1b68fb7c9 Mon Sep 17 00:00:00 2001 From: Charles Lyding <19598772+clydin@users.noreply.github.com> Date: Tue, 25 Oct 2022 12:04:25 -0400 Subject: [PATCH 1/3] fix(@angular/cli): exclude `@angular/material@7.x` from ng add package discovery `@angular/material@7.x` uses unbounded ranges for its framework peer dependencies. This can cause `ng add` to pick these versions of the package if the newer versions are not compatible since the peer dependency ranges would match any newer stable framework version. (cherry picked from commit 9260087bf7980fe4e7e216b7ddbadb2344022112) (cherry picked from commit 1a584364e70cafd84770ef45f3da9ad58a46083f) --- packages/angular/cli/src/commands/add/cli.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/angular/cli/src/commands/add/cli.ts b/packages/angular/cli/src/commands/add/cli.ts index d65cd78e4278..1fd2c58f975c 100644 --- a/packages/angular/cli/src/commands/add/cli.ts +++ b/packages/angular/cli/src/commands/add/cli.ts @@ -50,6 +50,8 @@ interface AddCommandArgs extends SchematicsCommandArgs { const packageVersionExclusions: Record = { // @angular/localize@9.x versions do not have peer dependencies setup '@angular/localize': '9.x', + // @angular/material@7.x versions have unbounded peer dependency ranges (>=7.0.0) + '@angular/material': '7.x', }; export class AddCommandModule From e0e25ccc7c632ef3202a1cdfa959a8b4bdbe1aec Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Thu, 27 Oct 2022 21:25:15 +0200 Subject: [PATCH 2/3] =?UTF-8?q?fix(@angular/cli):=20exclude=20`@angular/lo?= =?UTF-8?q?calize@<10.0.0`=20from=20ng=20add=20pa=E2=80=A6=20(#24152)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(@angular/cli): exclude `@angular/localize@<10.0.0` from ng add package discovery `@angular/localize@<10.0.0` has no peer dependencies. This can cause `ng add` to pick these versions of the package if the newer versions. See: https://app.circleci.com/pipelines/github/angular/angular-cli/27402/workflows/faa64532-541a-4bea-b599-3c53afe42019/jobs/364822 ``` Test Process error Error: Process exit error - "ng add @angular/localize --skip-confirmation": 1... STDOUT: STDERR: npm version 7.4.0 detected. When using npm 7 with the Angular CLI, npm version 7.5.6 or higher is recommended. - Determining package manager... ℹ Using package manager: npm - Searching for compatible package version... ✔ Found compatible package version: @angular/localize@10.0.0-next.7. - Loading package information from registry... ✔ Package information loaded. - Installing packages... ✔ Packages successfully installed. NOT SUPPORTED: keyword "id", use "$id" for schema ID ``` * fixup! fix(@angular/cli): exclude `@angular/localize@<10.0.0` from ng add package discovery Co-authored-by: Charles <19598772+clydin@users.noreply.github.com> Co-authored-by: Charles <19598772+clydin@users.noreply.github.com> (cherry picked from commit 65a0983a416067d160103ce244a580cf04929905) (cherry picked from commit 35e5f4278145b7ef55a75f1692c8e92d6bcd59db) --- packages/angular/cli/src/commands/add/cli.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/angular/cli/src/commands/add/cli.ts b/packages/angular/cli/src/commands/add/cli.ts index 1fd2c58f975c..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,10 +47,10 @@ 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', - // @angular/material@7.x versions have unbounded peer dependency ranges (>=7.0.0) +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', }; @@ -189,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; } From ab6bb1d6a6996c809bc55751564da5d044f8e4a3 Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Thu, 17 Nov 2022 10:46:51 +0000 Subject: [PATCH 3/3] test(@angular/cli): fix version specifier test Remove `ng add @angular/localize@latest` test. This is currently failing as `@angular/localize@latest` does not support Node.js version 14.15 --- tests/legacy-cli/e2e/tests/commands/add/version-specifier.ts | 5 ----- 1 file changed, 5 deletions(-) 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')) {