Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(rspack): avoid falsy values in checkSingleton #3487

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/red-ads-flow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@module-federation/rspack': patch
---

Check for falsy values when looking for duplicate ModuleFederationPlugin entries
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