Skip to content

Commit 5a2de62

Browse files
author
nyqykk
committed
feat: support hint when users enable mf format but not regist mf rsbuild plugin
1 parent 7c63d69 commit 5a2de62

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

packages/core/src/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import type {
4242
import { getDefaultExtension } from './utils/extension';
4343
import {
4444
calcLongestCommonPath,
45+
checkMFPlugin,
4546
color,
4647
isEmptyObject,
4748
isObject,
@@ -919,6 +920,7 @@ const composeExternalHelpersConfig = (
919920
};
920921

921922
async function composeLibRsbuildConfig(config: LibConfig, configPath: string) {
923+
checkMFPlugin(config);
922924
const rootPath = dirname(configPath);
923925
const pkgJson = readPackageJson(rootPath);
924926
const { compilerOptions } = await loadTsconfig(

packages/core/src/utils/helper.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import fs from 'node:fs';
22
import fsP from 'node:fs/promises';
33
import path from 'node:path';
44
import color from 'picocolors';
5-
import type { PkgJson } from '../types';
5+
6+
import type { LibConfig, PkgJson } from '../types';
67
import { logger } from './logger';
78

89
/**
@@ -160,4 +161,35 @@ export function omit<T extends object, U extends keyof T>(
160161
);
161162
}
162163

164+
export function isPluginIncluded(
165+
config: LibConfig,
166+
pluginName: string,
167+
): boolean {
168+
return Boolean(
169+
config.plugins?.some((plugin) => {
170+
if (typeof plugin === 'object' && plugin !== null && 'name' in plugin) {
171+
return plugin.name === pluginName;
172+
}
173+
return false;
174+
}),
175+
);
176+
}
177+
178+
export function checkMFPlugin(config: LibConfig): boolean {
179+
if (config.format !== 'mf') {
180+
return true;
181+
}
182+
183+
const added = isPluginIncluded(config, 'rsbuild:module-federation-enhanced');
184+
if (!added) {
185+
logger.warn(
186+
`${color.green('mf format')} is enabled, but the ${color.blue(
187+
'@module-federation/rsbuild-plugin',
188+
)} plugin was not found in plugins.`,
189+
);
190+
process.exit(1);
191+
}
192+
return added;
193+
}
194+
163195
export { color };

0 commit comments

Comments
 (0)