Skip to content

Commit

Permalink
fix: avoid falsy values or plugin functions in checkSingleton
Browse files Browse the repository at this point in the history
  • Loading branch information
jbroma committed Feb 5, 2025
1 parent 81fcc19 commit 5395d95
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions packages/rspack/src/ModuleFederationPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type {
Compiler,
Falsy,
ModuleFederationPluginOptions,
RspackPluginFunction,
RspackPluginInstance,
} from '@rspack/core';
import {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 5395d95

Please sign in to comment.