Skip to content

Conversation

@clydin
Copy link
Member

@clydin clydin commented Dec 23, 2025

This PR refactors the Karma builder in @angular-devkit/build-angular to modernize its architecture, reduce technical debt, and improve type safety. The primary goals were to remove RxJS dependencies from the builder's core execution flow, decouple the builder from the Webpack/Karma plugin, and centralize the build configuration and lifecycle management within the builder itself.
See individual commits for more details.

…ncIterable

Refactor the Karma builder's `execute` function to return an `AsyncIterable`
using a `ReadableStream`. This removes the RxJS dependency and aligns the
builder with modern Angular CLI implementation patterns.

Additionally, this change fixes a race condition where the Karma server
could start even if the builder was cancelled during asynchronous
initialization. An `isCancelled` flag is now used to ensure execution
stops if a cancellation occurs before the server starts.
…webpack plugin callbacks

Decouples the Karma builder from the Webpack plugin by removing the custom
`successCb` and `failureCb` callback mechanism. The builder now idiomaticallly
listens to the standard Karma `run_complete` event on the server instance
to emit builder results.
…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.
… builder

Refactor the Karma builder's `execute` function to directly handle dynamic
imports within conditional blocks. This eliminates the need for `getExecuteWithBuilder`
and the resulting union types that required `as any` casting.

This improves type safety by allowing TypeScript to verify the arguments passed
to the specific builder implementations (Esbuild vs Webpack).
@clydin clydin added the target: minor This PR is targeted for the next minor release label Dec 23, 2025
… API for karma builder

Adds an `executeKarmaBuilder` wrapper function in the package entry point
that returns an RxJS `Observable`. This maintains backward compatibility
for the experimental public API while the internal implementation has been
migrated to use `AsyncIterable`.
…on to karma builder

Moves the instantiation of the Webpack Compiler from the Karma plugin to the
Karma builder (`browser_builder`). This allows the builder to have full ownership
of the compiler's lifecycle and configuration, including `singleRun` adjustments
and output paths. The Karma plugin now receives the `compiler` instance directly
instead of the configuration, reducing its responsibility to just integration logic.
…rom karma plugin

Removes the `createConsoleLogger` import and its usage as a fallback in the
Karma plugin. The logger is now consistently provided by the builder via
the `buildWebpack` configuration object.
Consolidates the compiler hooks in the Karma plugin. Merges separate
`compiler.hooks.done` taps into a single unified handler that manages error
reporting, file refreshing, and blocking logic.
…ter from karma plugin

Removes the `@angular-devkit/build-angular--event-reporter` and its logic.
The reporter was no longer performing significant work after the removal of
custom callbacks, and its primary remaining function was a logging hack
that is no longer required.
…nup karma middleware

Updates the `requestBlocker` and `fallbackMiddleware` functions in the Karma
plugin to use strict `IncomingMessage`, `ServerResponse`, and `NextFunction`
types from `node:http`. Also properly types the `webpackMiddleware` variable
and ensures its `close` method is called with a callback in the exit handler,
resolving a TypeScript error exposed by the stricter typing.
…cker from karma plugin

Removes the custom request blocker middleware and related hooks from the Karma
plugin. `webpack-dev-middleware` already handles blocking requests until compilation
is valid, making this custom logic redundant and unnecessary.
@clydin clydin marked this pull request as ready for review December 23, 2025 22:29
@clydin clydin added the action: review The PR is still awaiting reviews from at least one requested reviewer label Dec 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: review The PR is still awaiting reviews from at least one requested reviewer area: @angular-devkit/build-angular target: minor This PR is targeted for the next minor release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant