Skip to content

Commit e1c0be3

Browse files
authored
fix(angular): install @angular/build when using vitest test runner (#31169)
## Current Behavior The application and library generators do not install the `@angular/build` package when using the `vitest` test runner. This can cause resolution issues depending on the package manager because the package is a peer dependency of the `@analogjs/vite-plugin-angular` package. ## Expected Behavior The application and library generators should install the `@angular/build` package when using the `vitest` test runner. ## Related Issue(s) Fixes #30646
1 parent 8cf4b55 commit e1c0be3

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

packages/angular/src/generators/utils/add-vitest.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
import { ensurePackage, type Tree } from '@nx/devkit';
1+
import {
2+
addDependenciesToPackageJson,
3+
ensurePackage,
4+
type Tree,
5+
} from '@nx/devkit';
26
import { nxVersion } from '../../utils/versions';
7+
import { getInstalledAngularDevkitVersion, versions } from './version-utils';
38

49
export type AddVitestOptions = {
510
name: string;
@@ -25,4 +30,18 @@ export async function addVitest(
2530
coverageProvider: 'v8',
2631
addPlugin: options.addPlugin ?? false,
2732
});
33+
34+
if (!options.skipPackageJson) {
35+
const angularDevkitVersion =
36+
getInstalledAngularDevkitVersion(tree) ??
37+
versions(tree).angularDevkitVersion;
38+
39+
addDependenciesToPackageJson(
40+
tree,
41+
{},
42+
{ '@angular/build': angularDevkitVersion },
43+
undefined,
44+
true
45+
);
46+
}
2847
}

packages/angular/src/generators/utils/version-utils.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ import {
88
import * as latestVersions from '../../utils/versions';
99
import { angularVersion } from '../../utils/versions';
1010

11+
export function getInstalledAngularDevkitVersion(tree: Tree): string | null {
12+
return (
13+
getInstalledPackageVersion(tree, '@angular-devkit/build-angular') ??
14+
getInstalledPackageVersion(tree, '@angular/build')
15+
);
16+
}
17+
1118
export function getInstalledAngularVersion(tree: Tree): string {
1219
const pkgJson = readJson(tree, 'package.json');
1320
const installedAngularVersion =

0 commit comments

Comments
 (0)