Skip to content

Commit f323928

Browse files
fix(rspack): avoid falsy values in checkSingleton (#3487)
Co-authored-by: Zack Jackson <[email protected]>
1 parent d312b12 commit f323928

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

.changeset/red-ads-flow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@module-federation/rspack': patch
3+
---
4+
5+
Check for falsy values when looking for duplicate ModuleFederationPlugin entries

packages/rspack/src/ModuleFederationPlugin.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import type {
22
Compiler,
3+
Falsy,
34
ModuleFederationPluginOptions,
5+
RspackPluginFunction,
46
RspackPluginInstance,
57
} from '@rspack/core';
68
import {
@@ -49,16 +51,22 @@ export class ModuleFederationPlugin implements RspackPluginInstance {
4951

5052
private _checkSingleton(compiler: Compiler): void {
5153
let count = 0;
52-
compiler.options.plugins.forEach((p: any) => {
53-
if (p.name === this.name) {
54-
count++;
55-
if (count > 1) {
56-
throw new Error(
57-
`Detect duplicate register ${this.name},please ensure ${this.name} is singleton!`,
58-
);
54+
compiler.options.plugins.forEach(
55+
(p: Falsy | RspackPluginInstance | RspackPluginFunction) => {
56+
if (typeof p !== 'object' || !p) {
57+
return;
5958
}
60-
}
61-
});
59+
60+
if (p['name'] === this.name) {
61+
count++;
62+
if (count > 1) {
63+
throw new Error(
64+
`Detect duplicate register ${this.name},please ensure ${this.name} is singleton!`,
65+
);
66+
}
67+
}
68+
},
69+
);
6270
}
6371

6472
apply(compiler: Compiler): void {

0 commit comments

Comments
 (0)