From 5395d95fbcaa40088c1b546ccbbbbdcead76a289 Mon Sep 17 00:00:00 2001 From: Jakub Romanczyk Date: Wed, 5 Feb 2025 18:35:56 +0100 Subject: [PATCH] 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 {