Skip to content

Commit d3c1c16

Browse files
authored
fix: checkMFPlugin function support array plugins (#419)
1 parent 567c514 commit d3c1c16

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

.changeset/silver-pumas-tap.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@rslib/core': patch
3+
---
4+
5+
fix: checkMFPlugin function support array plugins

packages/core/src/utils/helper.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import fs from 'node:fs';
22
import fsP from 'node:fs/promises';
33
import path from 'node:path';
4+
import type { RsbuildPlugins } from '@rsbuild/core';
45
import color from 'picocolors';
56

67
import type { LibConfig, PkgJson } from '../types';
@@ -163,11 +164,14 @@ export function omit<T extends object, U extends keyof T>(
163164
}
164165

165166
export function isPluginIncluded(
166-
config: LibConfig,
167167
pluginName: string,
168+
plugins?: RsbuildPlugins,
168169
): boolean {
169170
return Boolean(
170-
config.plugins?.some((plugin) => {
171+
plugins?.some((plugin) => {
172+
if (Array.isArray(plugin)) {
173+
return isPluginIncluded(pluginName, plugin);
174+
}
171175
if (typeof plugin === 'object' && plugin !== null && 'name' in plugin) {
172176
return plugin.name === pluginName;
173177
}
@@ -182,7 +186,10 @@ export function checkMFPlugin(config: LibConfig): boolean {
182186
}
183187

184188
// https://github.com/module-federation/core/blob/4e5c4b96ee45899f3ba5904b8927768980d5ad0e/packages/rsbuild-plugin/src/cli/index.ts#L17
185-
const added = isPluginIncluded(config, 'rsbuild:module-federation-enhanced');
189+
const added = isPluginIncluded(
190+
'rsbuild:module-federation-enhanced',
191+
config.plugins,
192+
);
186193
if (!added) {
187194
logger.warn(
188195
`${color.green('format: "mf"')} should be used with ${color.blue(

packages/core/tests/helper.test.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { join } from 'node:path';
22
import { expect, it, vi } from 'vitest';
3-
import { readPackageJson } from '../src/utils/helper';
3+
import { checkMFPlugin, readPackageJson } from '../src/utils/helper';
44

55
vi.mock('rslog');
66

@@ -11,3 +11,26 @@ it('readPackageJson correctly', async () => {
1111
type: 'module',
1212
});
1313
});
14+
15+
it('checkMFPlugin correctly', async () => {
16+
expect(
17+
checkMFPlugin({
18+
format: 'mf',
19+
plugins: [
20+
{ name: 'rsbuild:module-federation-enhanced', setup: () => {} },
21+
],
22+
}),
23+
).toEqual(true);
24+
25+
expect(
26+
checkMFPlugin({
27+
format: 'mf',
28+
plugins: [
29+
[
30+
{ name: 'rsbuild:module-federation-enhanced', setup: () => {} },
31+
{ name: 'plugin-foo', setup: () => {} },
32+
],
33+
],
34+
}),
35+
).toEqual(true);
36+
});

0 commit comments

Comments
 (0)