From e956a9f8f0df491d5c4c21e6ea200f1e23fab9e3 Mon Sep 17 00:00:00 2001 From: Alan Agius <17563226+alan-agius4@users.noreply.github.com> Date: Mon, 2 Mar 2026 08:28:32 +0000 Subject: [PATCH] fix(@angular/cli): correct dev dependency detection logic in `ng add` Previously, the logic for determining whether to install a package as a dev dependency in `ng add` was using a negative check (`!== 'dependencies'`). This has been changed to an explicit check (`=== 'devDependencies'`) to ensure the same behaviour as previous versions. Closes #32630 --- packages/angular/cli/src/commands/add/cli.ts | 2 +- tests/e2e/tests/commands/add/add-material.ts | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/angular/cli/src/commands/add/cli.ts b/packages/angular/cli/src/commands/add/cli.ts index a27c6405f18f..a41c9b54c7f3 100644 --- a/packages/angular/cli/src/commands/add/cli.ts +++ b/packages/angular/cli/src/commands/add/cli.ts @@ -583,7 +583,7 @@ export default class AddCommandModule await packageManager.add( packageIdentifier.toString(), 'none', - savePackage !== 'dependencies', + savePackage === 'devDependencies', false, true, { diff --git a/tests/e2e/tests/commands/add/add-material.ts b/tests/e2e/tests/commands/add/add-material.ts index 238e5d94dddb..a7453f035a6f 100644 --- a/tests/e2e/tests/commands/add/add-material.ts +++ b/tests/e2e/tests/commands/add/add-material.ts @@ -1,9 +1,10 @@ import { assertIsError } from '../../../utils/utils'; -import { expectFileToMatch, rimraf } from '../../../utils/fs'; +import { readFile, rimraf } from '../../../utils/fs'; import { getActivePackageManager, uninstallPackage } from '../../../utils/packages'; import { ng } from '../../../utils/process'; import { isPrereleaseCli } from '../../../utils/project'; import { appendFile } from 'node:fs/promises'; +import assert from 'node:assert'; export default async function () { // forcibly remove in case another test doesn't clean itself up @@ -32,7 +33,12 @@ export default async function () { '--verbose', '--skip-confirmation', ); - await expectFileToMatch('package.json', /@angular\/material/); + + const { dependencies } = JSON.parse(await readFile('package.json')); + assert.ok( + dependencies['@angular/material'], + '`@angular/material` was not found added to dependencies', + ); // Clean up existing cdk package // Not doing so can cause adding material to fail if an incompatible cdk is present