Skip to content

Commit

Permalink
fix: test
Browse files Browse the repository at this point in the history
  • Loading branch information
2heal1 committed Dec 30, 2024
1 parent 7a054e6 commit 812b668
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { FederationRuntimePlugin } from '@module-federation/enhanced/runtim
import nodeFetch from 'node-fetch';

const injectNodeFetchPlugin: () => FederationRuntimePlugin = () => ({
name: 'node-fetch-plugin',
name: 'inject-node-fetch-plugin',
beforeInit(args) {
if (!globalThis.fetch) {
// @ts-expect-error inject node-fetch
Expand Down
18 changes: 0 additions & 18 deletions packages/modernjs/src/cli/mfRuntimePlugins/node.ts

This file was deleted.

22 changes: 22 additions & 0 deletions packages/modernjs/src/cli/mfRuntimePlugins/shared-strategy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type { FederationRuntimePlugin } from '@module-federation/enhanced/runtime';

const sharedStrategy: () => FederationRuntimePlugin = () => ({
name: 'shared-strategy-plugin',
beforeInit(args) {
const { userOptions } = args;
const shared = userOptions.shared;
if (shared) {
Object.keys(shared).forEach((sharedKey) => {
const sharedConfigs = shared[sharedKey];
const arraySharedConfigs = Array.isArray(sharedConfigs)
? sharedConfigs
: [sharedConfigs];
arraySharedConfigs.forEach((s) => {
s.strategy = 'loaded-first';
});
});
}
return args;
},
});
export default sharedStrategy;
1 change: 1 addition & 0 deletions packages/modernjs/src/cli/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ describe('patchMFConfig', async () => {
runtimePlugins: [
require.resolve('@module-federation/modern-js/shared-strategy'),
],
shareStrategy: 'loaded-first',
shared: {
react: {
eager: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/modernjs/src/cli/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export const patchMFConfig = (

if (isServer) {
injectRuntimePlugins(
path.resolve(__dirname, './mfRuntimePlugins/node.js'),
require.resolve('@module-federation/node/runtimePlugin'),
runtimePlugins,
);
if (isDev) {
Expand Down

0 comments on commit 812b668

Please sign in to comment.