Skip to content

Commit 3a1970b

Browse files
committed
fix(@angular-devkit/build-angular): only import karma when running karma builder
Karma is an optional peer dependency, but with the recent changes we broke this as we imported karma outside of the execution method, which made this package to be always imported even when the Karma builder was not invoked. (cherry picked from commit 5954d24)
1 parent 45a9422 commit 3a1970b

File tree

2 files changed

+6
-5
lines changed
  • goldens/public-api/angular_devkit/build_angular
  • packages/angular_devkit/build_angular/src/builders/karma

2 files changed

+6
-5
lines changed

goldens/public-api/angular_devkit/build_angular/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import { BuilderContext } from '@angular-devkit/architect';
88
import { BuilderOutput } from '@angular-devkit/architect';
99
import { BuildResult } from '@angular-devkit/build-webpack';
10-
import { ConfigOptions } from 'karma';
10+
import type { ConfigOptions } from 'karma';
1111
import { Configuration } from 'webpack';
1212
import { DevServerBuildOutput } from '@angular-devkit/build-webpack';
1313
import { Observable } from 'rxjs';

packages/angular_devkit/build_angular/src/builders/karma/index.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import { BuilderContext, BuilderOutput, createBuilder } from '@angular-devkit/architect';
1010
import { strings } from '@angular-devkit/core';
11-
import { Config, ConfigOptions, config, constants } from 'karma';
11+
import type { Config, ConfigOptions } from 'karma';
1212
import { createRequire } from 'module';
1313
import * as path from 'path';
1414
import { Observable, from } from 'rxjs';
@@ -96,7 +96,7 @@ export function execute(
9696

9797
const karmaOptions: KarmaConfigOptions = options.karmaConfig
9898
? {}
99-
: getBuiltInKarmaConfig(context.workspaceRoot, projectName);
99+
: getBuiltInKarmaConfig(karma, context.workspaceRoot, projectName);
100100

101101
karmaOptions.singleRun = singleRun;
102102

@@ -145,7 +145,7 @@ export function execute(
145145
logger: context.logger,
146146
};
147147

148-
const parsedKarmaConfig = await config.parseConfig(
148+
const parsedKarmaConfig = await karma.config.parseConfig(
149149
options.karmaConfig && path.resolve(context.workspaceRoot, options.karmaConfig),
150150
transforms.karmaOptions ? transforms.karmaOptions(karmaOptions) : karmaOptions,
151151
{ promiseConfig: true, throwErrors: true },
@@ -184,6 +184,7 @@ export function execute(
184184
}
185185

186186
function getBuiltInKarmaConfig(
187+
karma: typeof import('karma'),
187188
workspaceRoot: string,
188189
projectName: string,
189190
): ConfigOptions & Record<string, unknown> {
@@ -218,7 +219,7 @@ function getBuiltInKarmaConfig(
218219
reporters: ['progress', 'kjhtml'],
219220
port: 9876,
220221
colors: true,
221-
logLevel: constants.LOG_INFO,
222+
logLevel: karma.constants.LOG_INFO,
222223
autoWatch: true,
223224
browsers: ['Chrome'],
224225
restartOnFileChange: true,

0 commit comments

Comments
 (0)