Skip to content

Commit e49d7d4

Browse files
Merge 3c0b448 into 0285f5f
2 parents 0285f5f + 3c0b448 commit e49d7d4

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

packages/rsbuild-plugin/rslib.config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { pluginPublint } from 'rsbuild-plugin-publint';
22
import { defineConfig } from '@rslib/core';
3+
import pkg from './package.json';
34

45
export default defineConfig({
56
plugins: [pluginPublint()],
@@ -30,6 +31,9 @@ export default defineConfig({
3031
'!./src/**/*.test.*',
3132
],
3233
},
34+
define: {
35+
__RSBUILD_PLUGIN_NAME__: JSON.stringify(pkg.name),
36+
},
3337
tsconfigPath: './tsconfig.lib.json',
3438
},
3539
output: {

packages/rsbuild-plugin/src/cli/index.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { describe, expect, it } from 'vitest';
22
import { pluginModuleFederation } from './index';
3+
import pkg from '../../package.json';
4+
import { CALL_NAME_MAP } from '../constant';
35
import type { moduleFederationPlugin } from '@module-federation/sdk';
46

57
describe('pluginModuleFederation', () => {
@@ -27,4 +29,16 @@ describe('pluginModuleFederation', () => {
2729
expect(plugin).toBeDefined();
2830
expect(plugin.name).toBe('rsbuild:module-federation-enhanced');
2931
});
32+
33+
it('should use defined plugin name in dual-target guidance error', () => {
34+
const plugin = pluginModuleFederation(mockMFConfig, { target: 'dual' });
35+
const mockApi = {
36+
context: { callerName: CALL_NAME_MAP.RSLIB },
37+
getRsbuildConfig: () => ({}),
38+
};
39+
40+
expect(() => plugin.setup(mockApi as any)).toThrow(
41+
`Please set ${pkg.name} as global plugin in rslib.config.ts if you set 'target: "dual"'.`,
42+
);
43+
});
3044
});

packages/rsbuild-plugin/src/cli/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
PLUGIN_NAME,
66
} from '@module-federation/enhanced/rspack';
77
import { isRequiredVersion, getManifestFileName } from '@module-federation/sdk';
8-
import pkgJson from '../../package.json';
98
import logger from '../logger';
109
import {
1110
isRegExp,
@@ -61,9 +60,10 @@ type ExposedAPIType = {
6160
};
6261
export type { ModuleFederationOptions, ExposedAPIType };
6362

63+
declare const __RSBUILD_PLUGIN_NAME__: string;
6464
const RSBUILD_PLUGIN_MODULE_FEDERATION_NAME =
6565
'rsbuild:module-federation-enhanced';
66-
const RSBUILD_PLUGIN_NAME = '@module-federation/rsbuild-plugin';
66+
const RSBUILD_PLUGIN_NAME = __RSBUILD_PLUGIN_NAME__;
6767

6868
export { RSBUILD_PLUGIN_MODULE_FEDERATION_NAME, PLUGIN_NAME, SSR_DIR };
6969

@@ -468,7 +468,7 @@ export const pluginModuleFederation = (
468468
const match = shared.some((dep) => {
469469
if (
470470
(ext as RegExp).test(dep) ||
471-
(ext as RegExp).test(pkgJson.name)
471+
(ext as RegExp).test(RSBUILD_PLUGIN_NAME)
472472
) {
473473
sharedModule = dep;
474474
return true;
@@ -481,7 +481,7 @@ export const pluginModuleFederation = (
481481
}
482482

483483
if (typeof ext === 'string') {
484-
if (ext === pkgJson.name) {
484+
if (ext === RSBUILD_PLUGIN_NAME) {
485485
return false;
486486
}
487487

packages/rsbuild-plugin/vite.config.mts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
/// <reference types="vitest" />
22
import { defineConfig } from 'vite';
3+
import pkg from './package.json';
34

45
import tsconfigPaths from 'vite-tsconfig-paths';
56

67
export default defineConfig({
78
cacheDir: '../../node_modules/.vite/rsbuild-plugin',
9+
define: {
10+
__RSBUILD_PLUGIN_NAME__: JSON.stringify(pkg.name),
11+
},
812

913
plugins: [tsconfigPaths()],
1014

0 commit comments

Comments
 (0)