Skip to content

Commit ae4c28d

Browse files
committed
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 angular#32630 (cherry picked from commit 038a931)
1 parent 6ad8608 commit ae4c28d

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

packages/angular/cli/src/commands/add/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ export default class AddCommandModule
583583
await packageManager.add(
584584
packageIdentifier.toString(),
585585
'none',
586-
savePackage !== 'dependencies',
586+
savePackage === 'devDependencies',
587587
false,
588588
true,
589589
{

tests/e2e/tests/commands/add/add-material.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { assertIsError } from '../../../utils/utils';
2-
import { expectFileToMatch, rimraf } from '../../../utils/fs';
2+
import { readFile, rimraf } from '../../../utils/fs';
33
import { getActivePackageManager, uninstallPackage } from '../../../utils/packages';
44
import { ng } from '../../../utils/process';
55
import { isPrereleaseCli } from '../../../utils/project';
66
import { appendFile } from 'node:fs/promises';
7+
import assert from 'node:assert';
78

89
export default async function () {
910
// forcibly remove in case another test doesn't clean itself up
@@ -32,7 +33,12 @@ export default async function () {
3233
'--verbose',
3334
'--skip-confirmation',
3435
);
35-
await expectFileToMatch('package.json', /@angular\/material/);
36+
37+
const { dependencies } = JSON.parse(await readFile('package.json'));
38+
assert.ok(
39+
dependencies['@angular/material'],
40+
'`@angular/material` was not found added to dependencies',
41+
);
3642

3743
// Clean up existing cdk package
3844
// Not doing so can cause adding material to fail if an incompatible cdk is present

0 commit comments

Comments
 (0)