From 5395d95fbcaa40088c1b546ccbbbbdcead76a289 Mon Sep 17 00:00:00 2001 From: Jakub Romanczyk Date: Wed, 5 Feb 2025 18:35:56 +0100 Subject: [PATCH 1/2] fix: avoid falsy values or plugin functions in checkSingleton --- packages/rspack/src/ModuleFederationPlugin.ts | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/packages/rspack/src/ModuleFederationPlugin.ts b/packages/rspack/src/ModuleFederationPlugin.ts index 5142f895661..82c9bca7e38 100644 --- a/packages/rspack/src/ModuleFederationPlugin.ts +++ b/packages/rspack/src/ModuleFederationPlugin.ts @@ -1,6 +1,8 @@ import type { Compiler, + Falsy, ModuleFederationPluginOptions, + RspackPluginFunction, RspackPluginInstance, } from '@rspack/core'; import { @@ -48,16 +50,22 @@ export class ModuleFederationPlugin implements RspackPluginInstance { private _checkSingleton(compiler: Compiler): void { let count = 0; - compiler.options.plugins.forEach((p: any) => { - if (p.name === this.name) { - count++; - if (count > 1) { - throw new Error( - `Detect duplicate register ${this.name},please ensure ${this.name} is singleton!`, - ); + compiler.options.plugins.forEach( + (p: Falsy | RspackPluginInstance | RspackPluginFunction) => { + if (typeof p !== 'object' || !p) { + return; } - } - }); + + if (p['name'] === this.name) { + count++; + if (count > 1) { + throw new Error( + `Detect duplicate register ${this.name},please ensure ${this.name} is singleton!`, + ); + } + } + }, + ); } apply(compiler: Compiler): void { From 991d333bae9b84ce485a67e3a9a7da1391163a82 Mon Sep 17 00:00:00 2001 From: Jakub Romanczyk Date: Wed, 5 Feb 2025 18:45:47 +0100 Subject: [PATCH 2/2] chore: add changeset --- .changeset/red-ads-flow.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/red-ads-flow.md diff --git a/.changeset/red-ads-flow.md b/.changeset/red-ads-flow.md new file mode 100644 index 00000000000..2d41e6d5140 --- /dev/null +++ b/.changeset/red-ads-flow.md @@ -0,0 +1,5 @@ +--- +'@module-federation/rspack': patch +--- + +Check for falsy values when looking for duplicate ModuleFederationPlugin entries