Skip to content

Commit 14afce2

Browse files
committed
fix(cdk/schematics): account for new karma builder (#30907)
angular/angular-cli#29640 introduced a new Karma builder that appears to be the default in v20. These changes update our code so that the new builder is recognized. I also move the names of the builders out into a constant so they're easier to update. (cherry picked from commit 22876a9)
1 parent 4d0dcc4 commit 14afce2

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

src/cdk/schematics/utils/project-targets.ts

+13-12
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@
99
import {JsonValue, workspaces} from '@angular-devkit/core';
1010
import {SchematicsException} from '@angular-devkit/schematics';
1111

12+
/** Possible names of CLI builders used to configure the project. */
13+
const PROJECT_BUILDERS = new Set([
14+
'@angular-devkit/build-angular:browser-esbuild',
15+
'@angular-devkit/build-angular:application',
16+
'@angular-devkit/build-angular:browser',
17+
'@angular/build:application',
18+
]);
19+
20+
/** Possible name of CLI builders used to run tests in the project. */
21+
const TEST_BUILDERS = new Set(['@angular-devkit/build-angular:karma', '@angular/build:karma']);
22+
1223
/** Resolves the architect options for the build target of the given project. */
1324
export function getProjectTargetOptions(
1425
project: workspaces.ProjectDefinition,
@@ -29,24 +40,14 @@ export function getProjectTargetOptions(
2940
export function getProjectBuildTargets(
3041
project: workspaces.ProjectDefinition,
3142
): workspaces.TargetDefinition[] {
32-
return getTargetsByBuilderName(
33-
project,
34-
builder =>
35-
builder === '@angular-devkit/build-angular:application' ||
36-
builder === '@angular-devkit/build-angular:browser' ||
37-
builder === '@angular-devkit/build-angular:browser-esbuild' ||
38-
builder === '@angular/build:application',
39-
);
43+
return getTargetsByBuilderName(project, builder => !!builder && PROJECT_BUILDERS.has(builder));
4044
}
4145

4246
/** Gets all of the default CLI-provided testing targets in a project. */
4347
export function getProjectTestTargets(
4448
project: workspaces.ProjectDefinition,
4549
): workspaces.TargetDefinition[] {
46-
return getTargetsByBuilderName(
47-
project,
48-
builder => builder === '@angular-devkit/build-angular:karma',
49-
);
50+
return getTargetsByBuilderName(project, builder => !!builder && TEST_BUILDERS.has(builder));
5051
}
5152

5253
/** Gets all targets from the given project that pass a predicate check. */

0 commit comments

Comments
 (0)