@module-federation/modern-js 0.0.0-next-20240623084034 → 0.0.0-next-20240625025206
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +259 -0
- package/dist/cjs/cli/index.js +4 -1
- package/dist/cjs/cli/utils.js +52 -10
- package/dist/cjs/cli/utils.spec.js +7 -0
- package/dist/cjs/runtime/{LiveReload.js → SSRLiveReload.js} +6 -6
- package/dist/cjs/runtime/{MFReactComponent.js → createRemoteSSRComponent.js} +60 -46
- package/dist/cjs/runtime/index.js +8 -8
- package/dist/esm/cli/index.js +116 -121
- package/dist/esm/cli/utils.js +82 -79
- package/dist/esm/cli/utils.spec.js +7 -0
- package/dist/esm/runtime/{LiveReload.js → SSRLiveReload.js} +2 -2
- package/dist/esm/runtime/{MFReactComponent.js → createRemoteSSRComponent.js} +89 -45
- package/dist/esm/runtime/index.js +5 -5
- package/dist/esm-node/cli/index.js +5 -2
- package/dist/esm-node/cli/utils.js +51 -9
- package/dist/esm-node/cli/utils.spec.js +7 -0
- package/dist/esm-node/runtime/{LiveReload.js → SSRLiveReload.js} +2 -2
- package/dist/esm-node/runtime/{MFReactComponent.js → createRemoteSSRComponent.js} +56 -42
- package/dist/esm-node/runtime/index.js +5 -5
- package/dist/types/cli/utils.d.ts +3 -1
- package/dist/types/runtime/SSRLiveReload.d.ts +2 -0
- package/dist/types/runtime/createRemoteSSRComponent.d.ts +17 -0
- package/dist/types/runtime/index.d.ts +2 -2
- package/package.json +5 -5
- package/dist/types/runtime/LiveReload.d.ts +0 -2
- package/dist/types/runtime/MFReactComponent.d.ts +0 -14
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export * from "@module-federation/enhanced/runtime";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { createRemoteSSRComponent, collectSSRAssets } from "./createRemoteSSRComponent";
|
|
3
|
+
import { SSRLiveReload } from "./SSRLiveReload";
|
|
4
4
|
export {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
SSRLiveReload,
|
|
6
|
+
collectSSRAssets,
|
|
7
|
+
createRemoteSSRComponent
|
|
8
8
|
};
|
|
@@ -3,7 +3,7 @@ import { fs } from "@modern-js/utils";
|
|
|
3
3
|
import { ModuleFederationPlugin as WebpackModuleFederationPlugin, AsyncBoundaryPlugin } from "@module-federation/enhanced";
|
|
4
4
|
import { ModuleFederationPlugin as RspackModuleFederationPlugin } from "@module-federation/enhanced/rspack";
|
|
5
5
|
import { StreamingTargetPlugin, EntryChunkTrackerPlugin } from "@module-federation/node";
|
|
6
|
-
import { getMFConfig, getTargetEnvConfig, patchWebpackConfig,
|
|
6
|
+
import { getMFConfig, getTargetEnvConfig, patchWebpackConfig, getIPV4 } from "./utils";
|
|
7
7
|
import { updateStatsAndManifest } from "./manifest";
|
|
8
8
|
import { MODERN_JS_SERVER_DIR } from "../constant";
|
|
9
9
|
const SSR_PLUGIN_IDENTIFIER = "mfPluginSSR";
|
|
@@ -53,10 +53,13 @@ const moduleFederationPlugin = (userConfig = {}) => ({
|
|
|
53
53
|
mfConfig: envConfig
|
|
54
54
|
});
|
|
55
55
|
};
|
|
56
|
-
const ipv4 =
|
|
56
|
+
const ipv4 = getIPV4();
|
|
57
57
|
return {
|
|
58
58
|
tools: {
|
|
59
59
|
rspack(config) {
|
|
60
|
+
if (enableSSR) {
|
|
61
|
+
throw new Error("@module-federation/modern-js not support ssr for rspack bundler yet!");
|
|
62
|
+
}
|
|
60
63
|
modifyBundlerConfig(config, false);
|
|
61
64
|
},
|
|
62
65
|
webpack(config, { isServer }) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { encodeName } from "@module-federation/sdk";
|
|
2
2
|
import path from "path";
|
|
3
|
+
import os from "os";
|
|
3
4
|
import { bundle } from "@modern-js/node-bundle-require";
|
|
4
|
-
import dns from "dns";
|
|
5
5
|
import { LOCALHOST } from "../constant";
|
|
6
6
|
const defaultPath = path.resolve(process.cwd(), "module-federation.config.ts");
|
|
7
7
|
const getMFConfig = async (userConfig) => {
|
|
@@ -27,7 +27,7 @@ const replaceRemoteUrl = async (mfConfig) => {
|
|
|
27
27
|
if (!mfConfig.remotes) {
|
|
28
28
|
return;
|
|
29
29
|
}
|
|
30
|
-
const ipv4 =
|
|
30
|
+
const ipv4 = getIPV4();
|
|
31
31
|
const handleRemoteObject = (remoteObject) => {
|
|
32
32
|
Object.keys(remoteObject).forEach((remoteKey) => {
|
|
33
33
|
const remote = remoteObject[remoteKey];
|
|
@@ -58,6 +58,33 @@ const patchMFConfig = (mfConfig, isServer) => {
|
|
|
58
58
|
const runtimePlugins = [
|
|
59
59
|
...mfConfig.runtimePlugins || []
|
|
60
60
|
];
|
|
61
|
+
const ModernJSRuntime = "@modern-js/runtime/mf";
|
|
62
|
+
if (mfConfig.dts !== false) {
|
|
63
|
+
var _mfConfig_dts, _mfConfig_dts1;
|
|
64
|
+
if (typeof mfConfig.dts === "boolean" || mfConfig.dts === void 0) {
|
|
65
|
+
mfConfig.dts = {
|
|
66
|
+
consumeTypes: {
|
|
67
|
+
runtimePkgs: [
|
|
68
|
+
ModernJSRuntime
|
|
69
|
+
]
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
} else if (((_mfConfig_dts = mfConfig.dts) === null || _mfConfig_dts === void 0 ? void 0 : _mfConfig_dts.consumeTypes) || ((_mfConfig_dts1 = mfConfig.dts) === null || _mfConfig_dts1 === void 0 ? void 0 : _mfConfig_dts1.consumeTypes) === void 0) {
|
|
73
|
+
var _mfConfig_dts2;
|
|
74
|
+
if (typeof mfConfig.dts.consumeTypes === "boolean" || ((_mfConfig_dts2 = mfConfig.dts) === null || _mfConfig_dts2 === void 0 ? void 0 : _mfConfig_dts2.consumeTypes) === void 0) {
|
|
75
|
+
mfConfig.dts.consumeTypes = {
|
|
76
|
+
runtimePkgs: [
|
|
77
|
+
ModernJSRuntime
|
|
78
|
+
]
|
|
79
|
+
};
|
|
80
|
+
} else {
|
|
81
|
+
mfConfig.dts.consumeTypes.runtimePkgs = mfConfig.dts.consumeTypes.runtimePkgs || [];
|
|
82
|
+
if (!mfConfig.dts.consumeTypes.runtimePkgs.includes(ModernJSRuntime)) {
|
|
83
|
+
mfConfig.dts.consumeTypes.runtimePkgs.push(ModernJSRuntime);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
61
88
|
injectRuntimePlugins(path.resolve(__dirname, "./mfRuntimePlugins/shared-strategy.js"), runtimePlugins);
|
|
62
89
|
if (isDev) {
|
|
63
90
|
injectRuntimePlugins(path.resolve(__dirname, "./mfRuntimePlugins/resolve-entry-ipv4.js"), runtimePlugins);
|
|
@@ -141,16 +168,31 @@ function patchWebpackConfig(options) {
|
|
|
141
168
|
};
|
|
142
169
|
}
|
|
143
170
|
}
|
|
144
|
-
const
|
|
171
|
+
const localIpv4 = "127.0.0.1";
|
|
172
|
+
const getIpv4Interfaces = () => {
|
|
145
173
|
try {
|
|
146
|
-
const
|
|
147
|
-
|
|
174
|
+
const interfaces = os.networkInterfaces();
|
|
175
|
+
const ipv4Interfaces = [];
|
|
176
|
+
Object.values(interfaces).forEach((detail) => {
|
|
177
|
+
detail === null || detail === void 0 ? void 0 : detail.forEach((detail2) => {
|
|
178
|
+
const familyV4Value = typeof detail2.family === "string" ? "IPv4" : 4;
|
|
179
|
+
if (detail2.family === familyV4Value && detail2.address !== localIpv4) {
|
|
180
|
+
ipv4Interfaces.push(detail2);
|
|
181
|
+
}
|
|
182
|
+
});
|
|
148
183
|
});
|
|
149
|
-
return
|
|
150
|
-
} catch (
|
|
151
|
-
return
|
|
184
|
+
return ipv4Interfaces;
|
|
185
|
+
} catch (_err) {
|
|
186
|
+
return [];
|
|
152
187
|
}
|
|
153
188
|
};
|
|
189
|
+
const getIPV4 = () => {
|
|
190
|
+
const ipv4Interfaces = getIpv4Interfaces();
|
|
191
|
+
const ipv4Interface = ipv4Interfaces[0] || {
|
|
192
|
+
address: localIpv4
|
|
193
|
+
};
|
|
194
|
+
return ipv4Interface.address;
|
|
195
|
+
};
|
|
154
196
|
const SPLIT_CHUNK_MAP = {
|
|
155
197
|
REACT: "lib-react",
|
|
156
198
|
ROUTER: "lib-router",
|
|
@@ -193,9 +235,9 @@ function autoDeleteSplitChunkCacheGroups(mfConfig, bundlerConfig) {
|
|
|
193
235
|
}
|
|
194
236
|
}
|
|
195
237
|
export {
|
|
238
|
+
getIPV4,
|
|
196
239
|
getMFConfig,
|
|
197
240
|
getTargetEnvConfig,
|
|
198
|
-
lookupIpv4,
|
|
199
241
|
patchMFConfig,
|
|
200
242
|
patchWebpackConfig
|
|
201
243
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
function
|
|
2
|
+
function SSRLiveReload() {
|
|
3
3
|
if (process.env.NODE_ENV !== "development") {
|
|
4
4
|
return null;
|
|
5
5
|
}
|
|
@@ -15,5 +15,5 @@ function LiveReload() {
|
|
|
15
15
|
});
|
|
16
16
|
}
|
|
17
17
|
export {
|
|
18
|
-
|
|
18
|
+
SSRLiveReload
|
|
19
19
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import React from "react";
|
|
3
|
-
import {
|
|
3
|
+
import { getInstance } from "@module-federation/enhanced/runtime";
|
|
4
4
|
import { ErrorBoundary } from "react-error-boundary";
|
|
5
5
|
function getLoadedRemoteInfos(instance, id) {
|
|
6
6
|
const { name, expose } = instance.remoteHandler.idToRemoteMap[id] || {};
|
|
@@ -50,7 +50,7 @@ function getTargetModuleInfo(id) {
|
|
|
50
50
|
remoteEntry
|
|
51
51
|
};
|
|
52
52
|
}
|
|
53
|
-
function
|
|
53
|
+
function collectSSRAssets(options) {
|
|
54
54
|
const { id, injectLink = true, injectScript = true } = typeof options === "string" ? {
|
|
55
55
|
id: options
|
|
56
56
|
} : options;
|
|
@@ -104,48 +104,62 @@ function collectAssets(options) {
|
|
|
104
104
|
...links
|
|
105
105
|
];
|
|
106
106
|
}
|
|
107
|
-
function
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
]
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
107
|
+
function createRemoteSSRComponent(info) {
|
|
108
|
+
return (props) => {
|
|
109
|
+
const exportName = (info === null || info === void 0 ? void 0 : info.export) || "default";
|
|
110
|
+
const LazyComponent = /* @__PURE__ */ React.lazy(async () => {
|
|
111
|
+
try {
|
|
112
|
+
const m = await info.loader();
|
|
113
|
+
if (!m) {
|
|
114
|
+
throw new Error("load remote failed");
|
|
115
|
+
}
|
|
116
|
+
const moduleId = m && m[Symbol.for("mf_module_id")];
|
|
117
|
+
const assets = collectSSRAssets({
|
|
118
|
+
id: moduleId,
|
|
119
|
+
injectLink: info.injectLink,
|
|
120
|
+
injectScript: info.injectScript
|
|
121
|
+
});
|
|
122
|
+
const Com = m[exportName];
|
|
123
|
+
if (exportName in m && typeof Com === "function") {
|
|
124
|
+
return {
|
|
125
|
+
default: () => /* @__PURE__ */ _jsxs(_Fragment, {
|
|
126
|
+
children: [
|
|
127
|
+
assets,
|
|
128
|
+
/* @__PURE__ */ _jsx(Com, {
|
|
129
|
+
...props
|
|
130
|
+
})
|
|
131
|
+
]
|
|
132
|
+
})
|
|
133
|
+
};
|
|
134
|
+
} else {
|
|
135
|
+
throw Error(`Make sure that ${moduleId} has the correct export when export is ${String(exportName)}`);
|
|
136
|
+
}
|
|
137
|
+
} catch (err) {
|
|
138
|
+
if (!info.fallback) {
|
|
139
|
+
throw err;
|
|
140
|
+
}
|
|
141
|
+
const FallbackFunctionComponent = info.fallback;
|
|
142
|
+
const FallbackNode = /* @__PURE__ */ _jsx(FallbackFunctionComponent, {
|
|
143
|
+
error: err,
|
|
144
|
+
resetErrorBoundary: () => {
|
|
145
|
+
console.log('SSR mode not support "resetErrorBoundary" !');
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
return {
|
|
149
|
+
default: () => FallbackNode
|
|
150
|
+
};
|
|
134
151
|
}
|
|
135
152
|
});
|
|
136
|
-
return {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
children: /* @__PURE__ */ _jsx(Component, {})
|
|
145
|
-
})
|
|
146
|
-
});
|
|
153
|
+
return /* @__PURE__ */ _jsx(ErrorBoundary, {
|
|
154
|
+
FallbackComponent: info.fallback,
|
|
155
|
+
children: /* @__PURE__ */ _jsx(React.Suspense, {
|
|
156
|
+
fallback: info.loading,
|
|
157
|
+
children: /* @__PURE__ */ _jsx(LazyComponent, {})
|
|
158
|
+
})
|
|
159
|
+
});
|
|
160
|
+
};
|
|
147
161
|
}
|
|
148
162
|
export {
|
|
149
|
-
|
|
150
|
-
|
|
163
|
+
collectSSRAssets,
|
|
164
|
+
createRemoteSSRComponent
|
|
151
165
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export * from "@module-federation/enhanced/runtime";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { createRemoteSSRComponent, collectSSRAssets } from "./createRemoteSSRComponent";
|
|
3
|
+
import { SSRLiveReload } from "./SSRLiveReload";
|
|
4
4
|
export {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
SSRLiveReload,
|
|
6
|
+
collectSSRAssets,
|
|
7
|
+
createRemoteSSRComponent
|
|
8
8
|
};
|
|
@@ -14,6 +14,7 @@ export declare const patchMFConfig: (mfConfig: moduleFederationPlugin.ModuleFede
|
|
|
14
14
|
runtime?: moduleFederationPlugin.EntryRuntime | undefined;
|
|
15
15
|
shareScope?: string | undefined;
|
|
16
16
|
shared?: moduleFederationPlugin.Shared | undefined;
|
|
17
|
+
getPublicPath?: string | undefined;
|
|
17
18
|
implementation?: string | undefined;
|
|
18
19
|
manifest?: boolean | moduleFederationPlugin.PluginManifestOptions | undefined;
|
|
19
20
|
dev?: boolean | moduleFederationPlugin.PluginDevOptions | undefined;
|
|
@@ -31,6 +32,7 @@ export declare function getTargetEnvConfig(mfConfig: moduleFederationPlugin.Modu
|
|
|
31
32
|
runtime?: moduleFederationPlugin.EntryRuntime | undefined;
|
|
32
33
|
shareScope?: string | undefined;
|
|
33
34
|
shared?: moduleFederationPlugin.Shared | undefined;
|
|
35
|
+
getPublicPath?: string | undefined;
|
|
34
36
|
implementation?: string | undefined;
|
|
35
37
|
manifest?: boolean | moduleFederationPlugin.PluginManifestOptions | undefined;
|
|
36
38
|
dev?: boolean | moduleFederationPlugin.PluginDevOptions | undefined;
|
|
@@ -43,4 +45,4 @@ export declare function patchWebpackConfig<T>(options: {
|
|
|
43
45
|
modernjsConfig: UserConfig<AppTools>;
|
|
44
46
|
mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions;
|
|
45
47
|
}): void;
|
|
46
|
-
export declare const
|
|
48
|
+
export declare const getIPV4: () => string;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ErrorBoundaryPropsWithComponent } from 'react-error-boundary';
|
|
3
|
+
type IProps = {
|
|
4
|
+
id: string;
|
|
5
|
+
injectScript?: boolean;
|
|
6
|
+
injectLink?: boolean;
|
|
7
|
+
};
|
|
8
|
+
export declare function collectSSRAssets(options: IProps): React.ReactNode[];
|
|
9
|
+
export declare function createRemoteSSRComponent<T, E extends keyof T>(info: {
|
|
10
|
+
loader: () => Promise<T>;
|
|
11
|
+
loading: React.ReactNode;
|
|
12
|
+
fallback: ErrorBoundaryPropsWithComponent['FallbackComponent'];
|
|
13
|
+
injectScript?: boolean;
|
|
14
|
+
injectLink?: boolean;
|
|
15
|
+
export?: E;
|
|
16
|
+
}): (props: T[E] extends (...args: any) => any ? Parameters<T[E]>[0] extends undefined ? Record<string, never> : Parameters<T[E]>[0] : Record<string, never>) => React.JSX.Element;
|
|
17
|
+
export {};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export * from '@module-federation/enhanced/runtime';
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
2
|
+
export { createRemoteSSRComponent, collectSSRAssets, } from './createRemoteSSRComponent';
|
|
3
|
+
export { SSRLiveReload } from './SSRLiveReload';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/modern-js",
|
|
3
|
-
"version": "0.0.0-next-
|
|
3
|
+
"version": "0.0.0-next-20240625025206",
|
|
4
4
|
"files": [
|
|
5
5
|
"dist/",
|
|
6
6
|
"types.d.ts",
|
|
@@ -47,9 +47,9 @@
|
|
|
47
47
|
"@modern-js/node-bundle-require": "^2.49.2",
|
|
48
48
|
"node-fetch": "~3.3.0",
|
|
49
49
|
"react-error-boundary": "4.0.13",
|
|
50
|
-
"@module-federation/sdk": "0.0.0-next-
|
|
51
|
-
"@module-federation/enhanced": "0.0.0-next-
|
|
52
|
-
"@module-federation/node": "0.0.0-next-
|
|
50
|
+
"@module-federation/sdk": "0.0.0-next-20240625025206",
|
|
51
|
+
"@module-federation/enhanced": "0.0.0-next-20240625025206",
|
|
52
|
+
"@module-federation/node": "0.0.0-next-20240625025206"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@modern-js/app-tools": "^2.49.2",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"@modern-js/runtime": "^2.49.2",
|
|
58
58
|
"@modern-js/module-tools": "^2.35.0",
|
|
59
59
|
"@modern-js/tsconfig": "^2.35.0",
|
|
60
|
-
"@module-federation/manifest": "0.0.0-next-
|
|
60
|
+
"@module-federation/manifest": "0.0.0-next-20240625025206"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
63
63
|
"react": ">=17",
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { ErrorBoundaryPropsWithComponent } from 'react-error-boundary';
|
|
3
|
-
type Id = string;
|
|
4
|
-
type IProps = {
|
|
5
|
-
id: Id;
|
|
6
|
-
loading: React.ReactNode;
|
|
7
|
-
fallback: ErrorBoundaryPropsWithComponent['FallbackComponent'];
|
|
8
|
-
injectScript?: boolean;
|
|
9
|
-
injectLink?: boolean;
|
|
10
|
-
remoteProps?: Record<string, any>;
|
|
11
|
-
};
|
|
12
|
-
declare function collectAssets(options: IProps): React.ReactNode[];
|
|
13
|
-
declare function MFReactComponent(props: IProps): React.JSX.Element;
|
|
14
|
-
export { MFReactComponent, collectAssets };
|