1
0
mirror of https://github.com/home-assistant/frontend.git synced 2026-05-17 21:50:19 +01:00
Files
frontend/build-scripts/safe-webpackbar.cjs
Petar Petrov d05cc25e66 Upgrade @rspack/core and @rspack/dev-server to v2 (#51674)
* Update dependency @rspack/dev-server to v2

* Upgrade @rspack/core to 2.0.0

Pairs with the @rspack/dev-server 2.0.0 bump in #51666 — dev-server v2
declares @rspack/core ^2.0.0-0 as a peer, so the two must move together.

Patches webpackbar to defend against non-string info in Rspack 2's
ProgressPlugin handler (otherwise `parseRequest` throws `split is not a
function` during compilation).

Verified locally: yarn lint:types, yarn test, yarn lint, script/build_frontend,
and all three rspack-dev-server-{demo,cast,gallery} tasks.

* Wrap webpackbar instead of patching it

Replace the yarn patch with a small SafeWebpackBar subclass that sanitizes
the progress `details` array before the upstream parseRequest sees it.
Keeps the fix local to the Rspack config where it belongs.

* Pass moduleIdentifier to webpackbar progress

Rspack 2's progress info is `{ builtModules, moduleIdentifier? }`.
moduleIdentifier is what v1 passed as a plain string, so extract it to
keep the "active module" line in the progress bar instead of blanking it.

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2026-04-23 13:16:14 +02:00

26 lines
893 B
JavaScript

// eslint-disable-next-line @typescript-eslint/naming-convention
const WebpackBar = require("webpackbar/rspack");
// Rspack 2's ProgressPlugin passes the third `info` arg as
// `{ builtModules, moduleIdentifier? }` instead of the v1 string. webpackbar@7's
// parseRequest still expects a string and crashes on `split`. Extract
// moduleIdentifier (the v1 equivalent) so progress still shows the active module.
class SafeWebpackBar extends WebpackBar {
constructor(options) {
super(options);
const inner = this.webpackbar;
const originalUpdate = inner.updateProgress.bind(inner);
inner.updateProgress = (percent, message, details = []) =>
originalUpdate(
percent,
message,
details.map((d) => {
if (typeof d === "string") return d;
return d?.moduleIdentifier ?? "";
})
);
}
}
module.exports = SafeWebpackBar;