Skip to content

Commit 33af26a

Browse files
CaptainWang98willxywang
andauthored
fix: generated alias should not trigger warning (#359)
* feat: warn if shared dependency is resolved to somewhere (#354) * test: checkAliasConflicts should work with undefined alias * fix(test): log should be called 4 times * fix: generated alias should not trigger warning --------- Co-authored-by: willxywang <[email protected]>
1 parent 222b1b8 commit 33af26a

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

src/plugins/__tests__/pluginCheckAliasConflicts.test.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,4 +223,52 @@ describe('pluginCheckAliasConflicts', () => {
223223

224224
expect(mockLogger.warn).not.toHaveBeenCalled();
225225
});
226+
227+
it('should skip Module Federation internal aliases (replacement $1)', () => {
228+
const plugin = checkAliasConflicts({
229+
shared: {
230+
vue: {
231+
name: 'vue',
232+
version: '3.2.45',
233+
scope: 'default',
234+
from: 'host',
235+
shareConfig: {
236+
requiredVersion: '^3.2.45',
237+
} as any,
238+
},
239+
'react-dom': {
240+
name: 'react-dom',
241+
version: '18.0.0',
242+
scope: 'default',
243+
from: 'host',
244+
shareConfig: {
245+
requiredVersion: '^18.0.0',
246+
} as any,
247+
},
248+
},
249+
});
250+
251+
const mockConfig = {
252+
logger: mockLogger,
253+
resolve: {
254+
alias: [
255+
{
256+
find: /^vue$/,
257+
replacement: '$1',
258+
customResolver: () => {},
259+
},
260+
{
261+
find: /^react-dom$/,
262+
replacement: '$1',
263+
customResolver: () => {},
264+
},
265+
],
266+
},
267+
};
268+
269+
plugin.configResolved!(mockConfig as any);
270+
271+
// Should not warn for internal MF aliases with replacement '$1'
272+
expect(mockLogger.warn).not.toHaveBeenCalled();
273+
});
226274
});

src/plugins/pluginCheckAliasConflicts.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ export function checkAliasConflicts(options: { shared?: NormalizedShared }): Plu
2525
// Skip if replacement is not a string (e.g., customResolver)
2626
if (typeof replacement !== 'string') continue;
2727

28+
// Skip Module Federation internal aliases (used for proxying shared modules)
29+
// These are generated with replacement '$1' and should not trigger warnings
30+
if (replacement === '$1') continue;
31+
2832
// Check if alias pattern matches the shared module
2933
let isMatch = false;
3034
if (typeof findPattern === 'string') {

0 commit comments

Comments
 (0)