Skip to content
Merged
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/silver-pumas-tap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rslib/core': patch
---

fix: checkMFPlugin function support array plugins
13 changes: 10 additions & 3 deletions packages/core/src/utils/helper.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fs from 'node:fs';
import fsP from 'node:fs/promises';
import path from 'node:path';
import type { RsbuildPlugins } from '@rsbuild/core';
import color from 'picocolors';

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

export function isPluginIncluded(
config: LibConfig,
pluginName: string,
plugins?: RsbuildPlugins,
): boolean {
return Boolean(
config.plugins?.some((plugin) => {
plugins?.some((plugin) => {
if (Array.isArray(plugin)) {
return isPluginIncluded(pluginName, plugin);
}
if (typeof plugin === 'object' && plugin !== null && 'name' in plugin) {
return plugin.name === pluginName;
}
Expand All @@ -182,7 +186,10 @@ export function checkMFPlugin(config: LibConfig): boolean {
}

// https://github.com/module-federation/core/blob/4e5c4b96ee45899f3ba5904b8927768980d5ad0e/packages/rsbuild-plugin/src/cli/index.ts#L17
const added = isPluginIncluded(config, 'rsbuild:module-federation-enhanced');
const added = isPluginIncluded(
'rsbuild:module-federation-enhanced',
config.plugins,
);
if (!added) {
logger.warn(
`${color.green('format: "mf"')} should be used with ${color.blue(
Expand Down
25 changes: 24 additions & 1 deletion packages/core/tests/helper.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { join } from 'node:path';
import { expect, it, vi } from 'vitest';
import { readPackageJson } from '../src/utils/helper';
import { checkMFPlugin, readPackageJson } from '../src/utils/helper';

vi.mock('rslog');

Expand All @@ -11,3 +11,26 @@ it('readPackageJson correctly', async () => {
type: 'module',
});
});

it('checkMFPlugin correctly', async () => {
expect(
checkMFPlugin({
format: 'mf',
plugins: [
{ name: 'rsbuild:module-federation-enhanced', setup: () => {} },
],
}),
).toEqual(true);

expect(
checkMFPlugin({
format: 'mf',
plugins: [
[
{ name: 'rsbuild:module-federation-enhanced', setup: () => {} },
{ name: 'plugin-foo', setup: () => {} },
],
],
}),
).toEqual(true);
});
Loading