Skip to content

Commit e865c64

Browse files
committed
refactor(@angular-devkit/build-angular): convert karma builder entry to AsyncIterable
Refactor the Karma builder's main `execute` function to return an `AsyncIterable` instead of an RxJS `Observable`. This continues the effort to reduce RxJS usage in the CLI builders and aligns the implementation with modern Angular CLI patterns.
1 parent 327dc81 commit e865c64

File tree

1 file changed

+28
-31
lines changed
  • packages/angular_devkit/build_angular/src/builders/karma

1 file changed

+28
-31
lines changed

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

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import { strings } from '@angular-devkit/core';
1717
import type { ConfigOptions } from 'karma';
1818
import { createRequire } from 'node:module';
1919
import * as path from 'node:path';
20-
import { Observable, from, mergeMap } from 'rxjs';
2120
import { Configuration } from 'webpack';
2221
import { ExecutionTransformer } from '../../transforms';
2322
import { normalizeFileReplacements } from '../../utils';
@@ -31,45 +30,43 @@ export type KarmaConfigOptions = ConfigOptions & {
3130
/**
3231
* @experimental Direct usage of this function is considered experimental.
3332
*/
34-
export function execute(
33+
export async function* execute(
3534
options: KarmaBuilderOptions,
3635
context: BuilderContext,
3736
transforms: {
3837
webpackConfiguration?: ExecutionTransformer<Configuration>;
3938
// The karma options transform cannot be async without a refactor of the builder implementation
4039
karmaOptions?: (options: KarmaConfigOptions) => KarmaConfigOptions;
4140
} = {},
42-
): Observable<BuilderOutput> {
41+
): AsyncIterable<BuilderOutput> {
4342
// Check Angular version.
4443
assertCompatibleAngularVersion(context.workspaceRoot);
4544

46-
return from(getExecuteWithBuilder(options, context)).pipe(
47-
mergeMap(([useEsbuild, executeWithBuilder]) => {
48-
if (useEsbuild) {
49-
if (transforms.webpackConfiguration) {
50-
context.logger.warn(
51-
`This build is using the application builder but transforms.webpackConfiguration was provided. The transform will be ignored.`,
52-
);
53-
}
54-
55-
if (options.fileReplacements) {
56-
options.fileReplacements = normalizeFileReplacements(options.fileReplacements, './');
57-
}
58-
59-
if (typeof options.polyfills === 'string') {
60-
options.polyfills = [options.polyfills];
61-
}
62-
63-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
64-
return executeWithBuilder(options as any, context, transforms);
65-
} else {
66-
const karmaOptions = getBaseKarmaOptions(options, context);
67-
68-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
69-
return executeWithBuilder(options as any, context, karmaOptions, transforms);
70-
}
71-
}),
72-
);
45+
const [useEsbuild, executeWithBuilder] = await getExecuteWithBuilder(options, context);
46+
47+
if (useEsbuild) {
48+
if (transforms.webpackConfiguration) {
49+
context.logger.warn(
50+
`This build is using the application builder but transforms.webpackConfiguration was provided. The transform will be ignored.`,
51+
);
52+
}
53+
54+
if (options.fileReplacements) {
55+
options.fileReplacements = normalizeFileReplacements(options.fileReplacements, './');
56+
}
57+
58+
if (typeof options.polyfills === 'string') {
59+
options.polyfills = [options.polyfills];
60+
}
61+
62+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
63+
yield* executeWithBuilder(options as any, context, transforms);
64+
} else {
65+
const karmaOptions = getBaseKarmaOptions(options, context);
66+
67+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
68+
yield* executeWithBuilder(options as any, context, karmaOptions, transforms);
69+
}
7370
}
7471

7572
function getBaseKarmaOptions(
@@ -169,7 +166,7 @@ function getBuiltInKarmaConfig(
169166
}
170167

171168
export type { KarmaBuilderOptions };
172-
export default createBuilder<Record<string, string> & KarmaBuilderOptions>(execute);
169+
export default createBuilder<KarmaBuilderOptions>(execute);
173170

174171
async function getExecuteWithBuilder(
175172
options: KarmaBuilderOptions,

0 commit comments

Comments
 (0)