@module-federation/modern-js 0.0.0-next-20240621075348 → 0.0.0-next-20240624115757
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/dist/cjs/cli/index.js +1 -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} +62 -44
- package/dist/cjs/runtime/index.js +8 -8
- package/dist/esm/cli/index.js +2 -2
- 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} +91 -47
- package/dist/esm/runtime/index.js +5 -5
- package/dist/esm-node/cli/index.js +2 -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} +58 -40
- package/dist/esm-node/runtime/index.js +5 -5
- package/dist/types/cli/utils.d.ts +1 -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 +6 -5
- package/dist/types/runtime/LiveReload.d.ts +0 -2
- package/dist/types/runtime/MFReactComponent.d.ts +0 -12
package/dist/cjs/cli/index.js
CHANGED
package/dist/cjs/cli/utils.js
CHANGED
|
@@ -28,17 +28,17 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
var utils_exports = {};
|
|
30
30
|
__export(utils_exports, {
|
|
31
|
+
getIPV4: () => getIPV4,
|
|
31
32
|
getMFConfig: () => getMFConfig,
|
|
32
33
|
getTargetEnvConfig: () => getTargetEnvConfig,
|
|
33
|
-
lookupIpv4: () => lookupIpv4,
|
|
34
34
|
patchMFConfig: () => patchMFConfig,
|
|
35
35
|
patchWebpackConfig: () => patchWebpackConfig
|
|
36
36
|
});
|
|
37
37
|
module.exports = __toCommonJS(utils_exports);
|
|
38
38
|
var import_sdk = require("@module-federation/sdk");
|
|
39
39
|
var import_path = __toESM(require("path"));
|
|
40
|
+
var import_os = __toESM(require("os"));
|
|
40
41
|
var import_node_bundle_require = require("@modern-js/node-bundle-require");
|
|
41
|
-
var import_dns = __toESM(require("dns"));
|
|
42
42
|
var import_constant = require("../constant");
|
|
43
43
|
const defaultPath = import_path.default.resolve(process.cwd(), "module-federation.config.ts");
|
|
44
44
|
const getMFConfig = async (userConfig) => {
|
|
@@ -64,7 +64,7 @@ const replaceRemoteUrl = async (mfConfig) => {
|
|
|
64
64
|
if (!mfConfig.remotes) {
|
|
65
65
|
return;
|
|
66
66
|
}
|
|
67
|
-
const ipv4 =
|
|
67
|
+
const ipv4 = getIPV4();
|
|
68
68
|
const handleRemoteObject = (remoteObject) => {
|
|
69
69
|
Object.keys(remoteObject).forEach((remoteKey) => {
|
|
70
70
|
const remote = remoteObject[remoteKey];
|
|
@@ -95,6 +95,33 @@ const patchMFConfig = (mfConfig, isServer) => {
|
|
|
95
95
|
const runtimePlugins = [
|
|
96
96
|
...mfConfig.runtimePlugins || []
|
|
97
97
|
];
|
|
98
|
+
const ModernJSRuntime = "@modern-js/runtime/mf";
|
|
99
|
+
if (mfConfig.dts !== false) {
|
|
100
|
+
var _mfConfig_dts, _mfConfig_dts1;
|
|
101
|
+
if (typeof mfConfig.dts === "boolean" || mfConfig.dts === void 0) {
|
|
102
|
+
mfConfig.dts = {
|
|
103
|
+
consumeTypes: {
|
|
104
|
+
runtimePkgs: [
|
|
105
|
+
ModernJSRuntime
|
|
106
|
+
]
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
} 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) {
|
|
110
|
+
var _mfConfig_dts2;
|
|
111
|
+
if (typeof mfConfig.dts.consumeTypes === "boolean" || ((_mfConfig_dts2 = mfConfig.dts) === null || _mfConfig_dts2 === void 0 ? void 0 : _mfConfig_dts2.consumeTypes) === void 0) {
|
|
112
|
+
mfConfig.dts.consumeTypes = {
|
|
113
|
+
runtimePkgs: [
|
|
114
|
+
ModernJSRuntime
|
|
115
|
+
]
|
|
116
|
+
};
|
|
117
|
+
} else {
|
|
118
|
+
mfConfig.dts.consumeTypes.runtimePkgs = mfConfig.dts.consumeTypes.runtimePkgs || [];
|
|
119
|
+
if (!mfConfig.dts.consumeTypes.runtimePkgs.includes(ModernJSRuntime)) {
|
|
120
|
+
mfConfig.dts.consumeTypes.runtimePkgs.push(ModernJSRuntime);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
98
125
|
injectRuntimePlugins(import_path.default.resolve(__dirname, "./mfRuntimePlugins/shared-strategy.js"), runtimePlugins);
|
|
99
126
|
if (isDev) {
|
|
100
127
|
injectRuntimePlugins(import_path.default.resolve(__dirname, "./mfRuntimePlugins/resolve-entry-ipv4.js"), runtimePlugins);
|
|
@@ -178,16 +205,31 @@ function patchWebpackConfig(options) {
|
|
|
178
205
|
};
|
|
179
206
|
}
|
|
180
207
|
}
|
|
181
|
-
const
|
|
208
|
+
const localIpv4 = "127.0.0.1";
|
|
209
|
+
const getIpv4Interfaces = () => {
|
|
182
210
|
try {
|
|
183
|
-
const
|
|
184
|
-
|
|
211
|
+
const interfaces = import_os.default.networkInterfaces();
|
|
212
|
+
const ipv4Interfaces = [];
|
|
213
|
+
Object.values(interfaces).forEach((detail) => {
|
|
214
|
+
detail === null || detail === void 0 ? void 0 : detail.forEach((detail2) => {
|
|
215
|
+
const familyV4Value = typeof detail2.family === "string" ? "IPv4" : 4;
|
|
216
|
+
if (detail2.family === familyV4Value && detail2.address !== localIpv4) {
|
|
217
|
+
ipv4Interfaces.push(detail2);
|
|
218
|
+
}
|
|
219
|
+
});
|
|
185
220
|
});
|
|
186
|
-
return
|
|
187
|
-
} catch (
|
|
188
|
-
return
|
|
221
|
+
return ipv4Interfaces;
|
|
222
|
+
} catch (_err) {
|
|
223
|
+
return [];
|
|
189
224
|
}
|
|
190
225
|
};
|
|
226
|
+
const getIPV4 = () => {
|
|
227
|
+
const ipv4Interfaces = getIpv4Interfaces();
|
|
228
|
+
const ipv4Interface = ipv4Interfaces[0] || {
|
|
229
|
+
address: localIpv4
|
|
230
|
+
};
|
|
231
|
+
return ipv4Interface.address;
|
|
232
|
+
};
|
|
191
233
|
const SPLIT_CHUNK_MAP = {
|
|
192
234
|
REACT: "lib-react",
|
|
193
235
|
ROUTER: "lib-router",
|
|
@@ -231,9 +273,9 @@ function autoDeleteSplitChunkCacheGroups(mfConfig, bundlerConfig) {
|
|
|
231
273
|
}
|
|
232
274
|
// Annotate the CommonJS export names for ESM import in node:
|
|
233
275
|
0 && (module.exports = {
|
|
276
|
+
getIPV4,
|
|
234
277
|
getMFConfig,
|
|
235
278
|
getTargetEnvConfig,
|
|
236
|
-
lookupIpv4,
|
|
237
279
|
patchMFConfig,
|
|
238
280
|
patchWebpackConfig
|
|
239
281
|
});
|
|
@@ -16,13 +16,13 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var
|
|
20
|
-
__export(
|
|
21
|
-
|
|
19
|
+
var SSRLiveReload_exports = {};
|
|
20
|
+
__export(SSRLiveReload_exports, {
|
|
21
|
+
SSRLiveReload: () => SSRLiveReload
|
|
22
22
|
});
|
|
23
|
-
module.exports = __toCommonJS(
|
|
23
|
+
module.exports = __toCommonJS(SSRLiveReload_exports);
|
|
24
24
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
25
|
-
function
|
|
25
|
+
function SSRLiveReload() {
|
|
26
26
|
if (process.env.NODE_ENV !== "development") {
|
|
27
27
|
return null;
|
|
28
28
|
}
|
|
@@ -39,5 +39,5 @@ function LiveReload() {
|
|
|
39
39
|
}
|
|
40
40
|
// Annotate the CommonJS export names for ESM import in node:
|
|
41
41
|
0 && (module.exports = {
|
|
42
|
-
|
|
42
|
+
SSRLiveReload
|
|
43
43
|
});
|
|
@@ -26,15 +26,16 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var
|
|
30
|
-
__export(
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
var createRemoteSSRComponent_exports = {};
|
|
30
|
+
__export(createRemoteSSRComponent_exports, {
|
|
31
|
+
collectSSRAssets: () => collectSSRAssets,
|
|
32
|
+
createRemoteSSRComponent: () => createRemoteSSRComponent
|
|
33
33
|
});
|
|
34
|
-
module.exports = __toCommonJS(
|
|
34
|
+
module.exports = __toCommonJS(createRemoteSSRComponent_exports);
|
|
35
35
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
36
36
|
var import_react = __toESM(require("react"));
|
|
37
37
|
var import_runtime = require("@module-federation/enhanced/runtime");
|
|
38
|
+
var import_react_error_boundary = require("react-error-boundary");
|
|
38
39
|
function getLoadedRemoteInfos(instance, id) {
|
|
39
40
|
const { name, expose } = instance.remoteHandler.idToRemoteMap[id] || {};
|
|
40
41
|
if (!name) {
|
|
@@ -83,7 +84,7 @@ function getTargetModuleInfo(id) {
|
|
|
83
84
|
remoteEntry
|
|
84
85
|
};
|
|
85
86
|
}
|
|
86
|
-
function
|
|
87
|
+
function collectSSRAssets(options) {
|
|
87
88
|
const { id, injectLink = true, injectScript = true } = typeof options === "string" ? {
|
|
88
89
|
id: options
|
|
89
90
|
} : options;
|
|
@@ -137,46 +138,63 @@ function collectAssets(options) {
|
|
|
137
138
|
...links
|
|
138
139
|
];
|
|
139
140
|
}
|
|
140
|
-
function
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
]
|
|
141
|
+
function createRemoteSSRComponent(info) {
|
|
142
|
+
return (props) => {
|
|
143
|
+
const exportName = (info === null || info === void 0 ? void 0 : info.export) || "default";
|
|
144
|
+
const LazyComponent = /* @__PURE__ */ import_react.default.lazy(async () => {
|
|
145
|
+
try {
|
|
146
|
+
const m = await info.loader();
|
|
147
|
+
if (!m) {
|
|
148
|
+
throw new Error("load remote failed");
|
|
149
|
+
}
|
|
150
|
+
const moduleId = m && m[Symbol.for("mf_module_id")];
|
|
151
|
+
const assets = collectSSRAssets({
|
|
152
|
+
id: moduleId,
|
|
153
|
+
injectLink: info.injectLink,
|
|
154
|
+
injectScript: info.injectScript
|
|
155
|
+
});
|
|
156
|
+
const Com = m[exportName];
|
|
157
|
+
if (exportName in m && typeof Com === "function") {
|
|
158
|
+
return {
|
|
159
|
+
default: () => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
|
|
160
|
+
children: [
|
|
161
|
+
assets,
|
|
162
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Com, {
|
|
163
|
+
...props
|
|
164
|
+
})
|
|
165
|
+
]
|
|
166
|
+
})
|
|
167
|
+
};
|
|
168
|
+
} else {
|
|
169
|
+
throw Error(`Make sure that ${moduleId} has the correct export when export is ${String(exportName)}`);
|
|
170
|
+
}
|
|
171
|
+
} catch (err) {
|
|
172
|
+
if (!info.fallback) {
|
|
173
|
+
throw err;
|
|
174
|
+
}
|
|
175
|
+
const FallbackFunctionComponent = info.fallback;
|
|
176
|
+
const FallbackNode = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FallbackFunctionComponent, {
|
|
177
|
+
error: err,
|
|
178
|
+
resetErrorBoundary: () => {
|
|
179
|
+
console.log('SSR mode not support "resetErrorBoundary" !');
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
return {
|
|
183
|
+
default: () => FallbackNode
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_error_boundary.ErrorBoundary, {
|
|
188
|
+
FallbackComponent: info.fallback,
|
|
189
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.default.Suspense, {
|
|
190
|
+
fallback: info.loading,
|
|
191
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LazyComponent, {})
|
|
156
192
|
})
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
if (!fallback) {
|
|
160
|
-
throw err;
|
|
161
|
-
}
|
|
162
|
-
const FallbackNode = typeof fallback === "function" ? fallback(err) : fallback;
|
|
163
|
-
if (/* @__PURE__ */ import_react.default.isValidElement(FallbackNode)) {
|
|
164
|
-
return {
|
|
165
|
-
default: () => FallbackNode
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
const FallbackFunctionComponent = FallbackNode;
|
|
169
|
-
return {
|
|
170
|
-
default: () => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FallbackFunctionComponent, {})
|
|
171
|
-
};
|
|
172
|
-
}));
|
|
173
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.default.Suspense, {
|
|
174
|
-
fallback: loading,
|
|
175
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {})
|
|
176
|
-
});
|
|
193
|
+
});
|
|
194
|
+
};
|
|
177
195
|
}
|
|
178
196
|
// Annotate the CommonJS export names for ESM import in node:
|
|
179
197
|
0 && (module.exports = {
|
|
180
|
-
|
|
181
|
-
|
|
198
|
+
collectSSRAssets,
|
|
199
|
+
createRemoteSSRComponent
|
|
182
200
|
});
|
|
@@ -19,18 +19,18 @@ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "defau
|
|
|
19
19
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
20
|
var runtime_exports = {};
|
|
21
21
|
__export(runtime_exports, {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
SSRLiveReload: () => import_SSRLiveReload.SSRLiveReload,
|
|
23
|
+
collectSSRAssets: () => import_createRemoteSSRComponent.collectSSRAssets,
|
|
24
|
+
createRemoteSSRComponent: () => import_createRemoteSSRComponent.createRemoteSSRComponent
|
|
25
25
|
});
|
|
26
26
|
module.exports = __toCommonJS(runtime_exports);
|
|
27
27
|
__reExport(runtime_exports, require("@module-federation/enhanced/runtime"), module.exports);
|
|
28
|
-
var
|
|
29
|
-
var
|
|
28
|
+
var import_createRemoteSSRComponent = require("./createRemoteSSRComponent");
|
|
29
|
+
var import_SSRLiveReload = require("./SSRLiveReload");
|
|
30
30
|
// Annotate the CommonJS export names for ESM import in node:
|
|
31
31
|
0 && (module.exports = {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
SSRLiveReload,
|
|
33
|
+
collectSSRAssets,
|
|
34
|
+
createRemoteSSRComponent,
|
|
35
35
|
...require("@module-federation/enhanced/runtime")
|
|
36
36
|
});
|
package/dist/esm/cli/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import { fs } from "@modern-js/utils";
|
|
|
5
5
|
import { ModuleFederationPlugin as WebpackModuleFederationPlugin, AsyncBoundaryPlugin } from "@module-federation/enhanced";
|
|
6
6
|
import { ModuleFederationPlugin as RspackModuleFederationPlugin } from "@module-federation/enhanced/rspack";
|
|
7
7
|
import { StreamingTargetPlugin, EntryChunkTrackerPlugin } from "@module-federation/node";
|
|
8
|
-
import { getMFConfig, getTargetEnvConfig, patchWebpackConfig,
|
|
8
|
+
import { getMFConfig, getTargetEnvConfig, patchWebpackConfig, getIPV4 } from "./utils";
|
|
9
9
|
import { updateStatsAndManifest } from "./manifest";
|
|
10
10
|
import { MODERN_JS_SERVER_DIR } from "../constant";
|
|
11
11
|
var SSR_PLUGIN_IDENTIFIER = "mfPluginSSR";
|
|
@@ -72,7 +72,7 @@ var moduleFederationPlugin = function() {
|
|
|
72
72
|
};
|
|
73
73
|
return [
|
|
74
74
|
4,
|
|
75
|
-
|
|
75
|
+
getIPV4()
|
|
76
76
|
];
|
|
77
77
|
case 1:
|
|
78
78
|
ipv4 = _state2.sent();
|
package/dist/esm/cli/utils.js
CHANGED
|
@@ -5,8 +5,8 @@ import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
|
5
5
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
6
6
|
import { encodeName } from "@module-federation/sdk";
|
|
7
7
|
import path from "path";
|
|
8
|
+
import os from "os";
|
|
8
9
|
import { bundle } from "@modern-js/node-bundle-require";
|
|
9
|
-
import dns from "dns";
|
|
10
10
|
import { LOCALHOST } from "../constant";
|
|
11
11
|
var defaultPath = path.resolve(process.cwd(), "module-federation.config.ts");
|
|
12
12
|
var getMFConfig = function() {
|
|
@@ -64,47 +64,39 @@ var replaceRemoteUrl = function() {
|
|
|
64
64
|
var _ref = _async_to_generator(function(mfConfig) {
|
|
65
65
|
var ipv4, handleRemoteObject;
|
|
66
66
|
return _ts_generator(this, function(_state) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
67
|
+
if (!mfConfig.remotes) {
|
|
68
|
+
return [
|
|
69
|
+
2
|
|
70
|
+
];
|
|
71
|
+
}
|
|
72
|
+
ipv4 = getIPV4();
|
|
73
|
+
handleRemoteObject = function(remoteObject) {
|
|
74
|
+
Object.keys(remoteObject).forEach(function(remoteKey) {
|
|
75
|
+
var remote = remoteObject[remoteKey];
|
|
76
|
+
if (Array.isArray(remote)) {
|
|
77
|
+
return;
|
|
73
78
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
lookupIpv4()
|
|
77
|
-
];
|
|
78
|
-
case 1:
|
|
79
|
-
ipv4 = _state.sent();
|
|
80
|
-
handleRemoteObject = function(remoteObject) {
|
|
81
|
-
Object.keys(remoteObject).forEach(function(remoteKey) {
|
|
82
|
-
var remote = remoteObject[remoteKey];
|
|
83
|
-
if (Array.isArray(remote)) {
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
if (typeof remote === "string" && remote.includes(LOCALHOST)) {
|
|
87
|
-
remoteObject[remoteKey] = remote.replace(LOCALHOST, ipv4);
|
|
88
|
-
}
|
|
89
|
-
if (typeof remote === "object" && !Array.isArray(remote.external) && remote.external.includes(LOCALHOST)) {
|
|
90
|
-
remote.external = remote.external.replace(LOCALHOST, ipv4);
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
};
|
|
94
|
-
if (Array.isArray(mfConfig.remotes)) {
|
|
95
|
-
mfConfig.remotes.forEach(function(remoteObject) {
|
|
96
|
-
if (typeof remoteObject === "string") {
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
handleRemoteObject(remoteObject);
|
|
100
|
-
});
|
|
101
|
-
} else if (typeof mfConfig.remotes !== "string") {
|
|
102
|
-
handleRemoteObject(mfConfig.remotes);
|
|
79
|
+
if (typeof remote === "string" && remote.includes(LOCALHOST)) {
|
|
80
|
+
remoteObject[remoteKey] = remote.replace(LOCALHOST, ipv4);
|
|
103
81
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
82
|
+
if (typeof remote === "object" && !Array.isArray(remote.external) && remote.external.includes(LOCALHOST)) {
|
|
83
|
+
remote.external = remote.external.replace(LOCALHOST, ipv4);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
if (Array.isArray(mfConfig.remotes)) {
|
|
88
|
+
mfConfig.remotes.forEach(function(remoteObject) {
|
|
89
|
+
if (typeof remoteObject === "string") {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
handleRemoteObject(remoteObject);
|
|
93
|
+
});
|
|
94
|
+
} else if (typeof mfConfig.remotes !== "string") {
|
|
95
|
+
handleRemoteObject(mfConfig.remotes);
|
|
107
96
|
}
|
|
97
|
+
return [
|
|
98
|
+
2
|
|
99
|
+
];
|
|
108
100
|
});
|
|
109
101
|
});
|
|
110
102
|
return function replaceRemoteUrl2(mfConfig) {
|
|
@@ -114,6 +106,33 @@ var replaceRemoteUrl = function() {
|
|
|
114
106
|
var patchMFConfig = function(mfConfig, isServer) {
|
|
115
107
|
var isDev = process.env.NODE_ENV === "development";
|
|
116
108
|
var runtimePlugins = _to_consumable_array(mfConfig.runtimePlugins || []);
|
|
109
|
+
var ModernJSRuntime = "@modern-js/runtime/mf";
|
|
110
|
+
if (mfConfig.dts !== false) {
|
|
111
|
+
var _mfConfig_dts, _mfConfig_dts1;
|
|
112
|
+
if (typeof mfConfig.dts === "boolean" || mfConfig.dts === void 0) {
|
|
113
|
+
mfConfig.dts = {
|
|
114
|
+
consumeTypes: {
|
|
115
|
+
runtimePkgs: [
|
|
116
|
+
ModernJSRuntime
|
|
117
|
+
]
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
} 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) {
|
|
121
|
+
var _mfConfig_dts2;
|
|
122
|
+
if (typeof mfConfig.dts.consumeTypes === "boolean" || ((_mfConfig_dts2 = mfConfig.dts) === null || _mfConfig_dts2 === void 0 ? void 0 : _mfConfig_dts2.consumeTypes) === void 0) {
|
|
123
|
+
mfConfig.dts.consumeTypes = {
|
|
124
|
+
runtimePkgs: [
|
|
125
|
+
ModernJSRuntime
|
|
126
|
+
]
|
|
127
|
+
};
|
|
128
|
+
} else {
|
|
129
|
+
mfConfig.dts.consumeTypes.runtimePkgs = mfConfig.dts.consumeTypes.runtimePkgs || [];
|
|
130
|
+
if (!mfConfig.dts.consumeTypes.runtimePkgs.includes(ModernJSRuntime)) {
|
|
131
|
+
mfConfig.dts.consumeTypes.runtimePkgs.push(ModernJSRuntime);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
117
136
|
injectRuntimePlugins(path.resolve(__dirname, "./mfRuntimePlugins/shared-strategy.js"), runtimePlugins);
|
|
118
137
|
if (isDev) {
|
|
119
138
|
injectRuntimePlugins(path.resolve(__dirname, "./mfRuntimePlugins/resolve-entry-ipv4.js"), runtimePlugins);
|
|
@@ -191,47 +210,31 @@ function patchWebpackConfig(options) {
|
|
|
191
210
|
});
|
|
192
211
|
}
|
|
193
212
|
}
|
|
194
|
-
var
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
return [
|
|
207
|
-
4,
|
|
208
|
-
dns.promises.lookup(LOCALHOST, {
|
|
209
|
-
family: 4
|
|
210
|
-
})
|
|
211
|
-
];
|
|
212
|
-
case 1:
|
|
213
|
-
res = _state.sent();
|
|
214
|
-
return [
|
|
215
|
-
2,
|
|
216
|
-
res.address
|
|
217
|
-
];
|
|
218
|
-
case 2:
|
|
219
|
-
err = _state.sent();
|
|
220
|
-
return [
|
|
221
|
-
2,
|
|
222
|
-
"127.0.0.1"
|
|
223
|
-
];
|
|
224
|
-
case 3:
|
|
225
|
-
return [
|
|
226
|
-
2
|
|
227
|
-
];
|
|
228
|
-
}
|
|
213
|
+
var localIpv4 = "127.0.0.1";
|
|
214
|
+
var getIpv4Interfaces = function() {
|
|
215
|
+
try {
|
|
216
|
+
var interfaces = os.networkInterfaces();
|
|
217
|
+
var ipv4Interfaces = [];
|
|
218
|
+
Object.values(interfaces).forEach(function(detail) {
|
|
219
|
+
detail === null || detail === void 0 ? void 0 : detail.forEach(function(detail2) {
|
|
220
|
+
var familyV4Value = typeof detail2.family === "string" ? "IPv4" : 4;
|
|
221
|
+
if (detail2.family === familyV4Value && detail2.address !== localIpv4) {
|
|
222
|
+
ipv4Interfaces.push(detail2);
|
|
223
|
+
}
|
|
224
|
+
});
|
|
229
225
|
});
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
return
|
|
226
|
+
return ipv4Interfaces;
|
|
227
|
+
} catch (_err) {
|
|
228
|
+
return [];
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
var getIPV4 = function() {
|
|
232
|
+
var ipv4Interfaces = getIpv4Interfaces();
|
|
233
|
+
var ipv4Interface = ipv4Interfaces[0] || {
|
|
234
|
+
address: localIpv4
|
|
233
235
|
};
|
|
234
|
-
|
|
236
|
+
return ipv4Interface.address;
|
|
237
|
+
};
|
|
235
238
|
var SPLIT_CHUNK_MAP = {
|
|
236
239
|
REACT: "lib-react",
|
|
237
240
|
ROUTER: "lib-router",
|
|
@@ -291,9 +294,9 @@ function autoDeleteSplitChunkCacheGroups(mfConfig, bundlerConfig) {
|
|
|
291
294
|
}
|
|
292
295
|
}
|
|
293
296
|
export {
|
|
297
|
+
getIPV4,
|
|
294
298
|
getMFConfig,
|
|
295
299
|
getTargetEnvConfig,
|
|
296
|
-
lookupIpv4,
|
|
297
300
|
patchMFConfig,
|
|
298
301
|
patchWebpackConfig
|
|
299
302
|
};
|
|
@@ -10,7 +10,7 @@ function _templateObject() {
|
|
|
10
10
|
return data;
|
|
11
11
|
}
|
|
12
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
-
function
|
|
13
|
+
function SSRLiveReload() {
|
|
14
14
|
if (process.env.NODE_ENV !== "development") {
|
|
15
15
|
return null;
|
|
16
16
|
}
|
|
@@ -22,5 +22,5 @@ function LiveReload() {
|
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
24
|
export {
|
|
25
|
-
|
|
25
|
+
SSRLiveReload
|
|
26
26
|
};
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
1
2
|
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
2
3
|
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
3
4
|
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
5
|
+
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
4
6
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
5
7
|
import React from "react";
|
|
6
|
-
import {
|
|
8
|
+
import { getInstance } from "@module-federation/enhanced/runtime";
|
|
9
|
+
import { ErrorBoundary } from "react-error-boundary";
|
|
7
10
|
function getLoadedRemoteInfos(instance, id) {
|
|
8
11
|
var _ref = instance.remoteHandler.idToRemoteMap[id] || {}, name = _ref.name, expose = _ref.expose;
|
|
9
12
|
if (!name) {
|
|
@@ -53,7 +56,7 @@ function getTargetModuleInfo(id) {
|
|
|
53
56
|
remoteEntry
|
|
54
57
|
};
|
|
55
58
|
}
|
|
56
|
-
function
|
|
59
|
+
function collectSSRAssets(options) {
|
|
57
60
|
var _ref = typeof options === "string" ? {
|
|
58
61
|
id: options
|
|
59
62
|
} : options, id = _ref.id, _ref_injectLink = _ref.injectLink, injectLink = _ref_injectLink === void 0 ? true : _ref_injectLink, _ref_injectScript = _ref.injectScript, injectScript = _ref_injectScript === void 0 ? true : _ref_injectScript;
|
|
@@ -93,53 +96,94 @@ function collectAssets(options) {
|
|
|
93
96
|
}
|
|
94
97
|
return _to_consumable_array(scripts).concat(_to_consumable_array(links));
|
|
95
98
|
}
|
|
96
|
-
function
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
]
|
|
114
|
-
|
|
99
|
+
function createRemoteSSRComponent(info) {
|
|
100
|
+
return function(props) {
|
|
101
|
+
var exportName = (info === null || info === void 0 ? void 0 : info.export) || "default";
|
|
102
|
+
var LazyComponent = /* @__PURE__ */ React.lazy(/* @__PURE__ */ _async_to_generator(function() {
|
|
103
|
+
var m, moduleId, assets, Com, err, FallbackFunctionComponent, FallbackNode;
|
|
104
|
+
return _ts_generator(this, function(_state) {
|
|
105
|
+
switch (_state.label) {
|
|
106
|
+
case 0:
|
|
107
|
+
_state.trys.push([
|
|
108
|
+
0,
|
|
109
|
+
2,
|
|
110
|
+
,
|
|
111
|
+
3
|
|
112
|
+
]);
|
|
113
|
+
return [
|
|
114
|
+
4,
|
|
115
|
+
info.loader()
|
|
116
|
+
];
|
|
117
|
+
case 1:
|
|
118
|
+
m = _state.sent();
|
|
119
|
+
if (!m) {
|
|
120
|
+
throw new Error("load remote failed");
|
|
121
|
+
}
|
|
122
|
+
moduleId = m && m[Symbol.for("mf_module_id")];
|
|
123
|
+
assets = collectSSRAssets({
|
|
124
|
+
id: moduleId,
|
|
125
|
+
injectLink: info.injectLink,
|
|
126
|
+
injectScript: info.injectScript
|
|
127
|
+
});
|
|
128
|
+
Com = m[exportName];
|
|
129
|
+
if (exportName in m && typeof Com === "function") {
|
|
130
|
+
return [
|
|
131
|
+
2,
|
|
132
|
+
{
|
|
133
|
+
default: function() {
|
|
134
|
+
return /* @__PURE__ */ _jsxs(_Fragment, {
|
|
135
|
+
children: [
|
|
136
|
+
assets,
|
|
137
|
+
/* @__PURE__ */ _jsx(Com, _object_spread({}, props))
|
|
138
|
+
]
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
];
|
|
143
|
+
} else {
|
|
144
|
+
throw Error("Make sure that ".concat(moduleId, " has the correct export when export is ").concat(String(exportName)));
|
|
145
|
+
}
|
|
146
|
+
return [
|
|
147
|
+
3,
|
|
148
|
+
3
|
|
149
|
+
];
|
|
150
|
+
case 2:
|
|
151
|
+
err = _state.sent();
|
|
152
|
+
if (!info.fallback) {
|
|
153
|
+
throw err;
|
|
154
|
+
}
|
|
155
|
+
FallbackFunctionComponent = info.fallback;
|
|
156
|
+
FallbackNode = /* @__PURE__ */ _jsx(FallbackFunctionComponent, {
|
|
157
|
+
error: err,
|
|
158
|
+
resetErrorBoundary: function() {
|
|
159
|
+
console.log('SSR mode not support "resetErrorBoundary" !');
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
return [
|
|
163
|
+
2,
|
|
164
|
+
{
|
|
165
|
+
default: function() {
|
|
166
|
+
return FallbackNode;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
];
|
|
170
|
+
case 3:
|
|
171
|
+
return [
|
|
172
|
+
2
|
|
173
|
+
];
|
|
115
174
|
}
|
|
116
|
-
};
|
|
117
|
-
})
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
default: function() {
|
|
125
|
-
return FallbackNode;
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
var FallbackFunctionComponent = FallbackNode;
|
|
130
|
-
return {
|
|
131
|
-
default: function() {
|
|
132
|
-
return /* @__PURE__ */ _jsx(FallbackFunctionComponent, {});
|
|
133
|
-
}
|
|
134
|
-
};
|
|
175
|
+
});
|
|
176
|
+
}));
|
|
177
|
+
return /* @__PURE__ */ _jsx(ErrorBoundary, {
|
|
178
|
+
FallbackComponent: info.fallback,
|
|
179
|
+
children: /* @__PURE__ */ _jsx(React.Suspense, {
|
|
180
|
+
fallback: info.loading,
|
|
181
|
+
children: /* @__PURE__ */ _jsx(LazyComponent, {})
|
|
182
|
+
})
|
|
135
183
|
});
|
|
136
|
-
}
|
|
137
|
-
return /* @__PURE__ */ _jsx(React.Suspense, {
|
|
138
|
-
fallback: loading,
|
|
139
|
-
children: /* @__PURE__ */ _jsx(Component, {})
|
|
140
|
-
});
|
|
184
|
+
};
|
|
141
185
|
}
|
|
142
186
|
export {
|
|
143
|
-
|
|
144
|
-
|
|
187
|
+
collectSSRAssets,
|
|
188
|
+
createRemoteSSRComponent
|
|
145
189
|
};
|
|
@@ -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,7 +53,7 @@ const moduleFederationPlugin = (userConfig = {}) => ({
|
|
|
53
53
|
mfConfig: envConfig
|
|
54
54
|
});
|
|
55
55
|
};
|
|
56
|
-
const ipv4 = await
|
|
56
|
+
const ipv4 = await getIPV4();
|
|
57
57
|
return {
|
|
58
58
|
tools: {
|
|
59
59
|
rspack(config) {
|
|
@@ -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,7 @@
|
|
|
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
|
+
import { ErrorBoundary } from "react-error-boundary";
|
|
4
5
|
function getLoadedRemoteInfos(instance, id) {
|
|
5
6
|
const { name, expose } = instance.remoteHandler.idToRemoteMap[id] || {};
|
|
6
7
|
if (!name) {
|
|
@@ -49,7 +50,7 @@ function getTargetModuleInfo(id) {
|
|
|
49
50
|
remoteEntry
|
|
50
51
|
};
|
|
51
52
|
}
|
|
52
|
-
function
|
|
53
|
+
function collectSSRAssets(options) {
|
|
53
54
|
const { id, injectLink = true, injectScript = true } = typeof options === "string" ? {
|
|
54
55
|
id: options
|
|
55
56
|
} : options;
|
|
@@ -103,45 +104,62 @@ function collectAssets(options) {
|
|
|
103
104
|
...links
|
|
104
105
|
];
|
|
105
106
|
}
|
|
106
|
-
function
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
]
|
|
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
|
+
};
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
return /* @__PURE__ */ _jsx(ErrorBoundary, {
|
|
154
|
+
FallbackComponent: info.fallback,
|
|
155
|
+
children: /* @__PURE__ */ _jsx(React.Suspense, {
|
|
156
|
+
fallback: info.loading,
|
|
157
|
+
children: /* @__PURE__ */ _jsx(LazyComponent, {})
|
|
122
158
|
})
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
if (!fallback) {
|
|
126
|
-
throw err;
|
|
127
|
-
}
|
|
128
|
-
const FallbackNode = typeof fallback === "function" ? fallback(err) : fallback;
|
|
129
|
-
if (/* @__PURE__ */ React.isValidElement(FallbackNode)) {
|
|
130
|
-
return {
|
|
131
|
-
default: () => FallbackNode
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
const FallbackFunctionComponent = FallbackNode;
|
|
135
|
-
return {
|
|
136
|
-
default: () => /* @__PURE__ */ _jsx(FallbackFunctionComponent, {})
|
|
137
|
-
};
|
|
138
|
-
}));
|
|
139
|
-
return /* @__PURE__ */ _jsx(React.Suspense, {
|
|
140
|
-
fallback: loading,
|
|
141
|
-
children: /* @__PURE__ */ _jsx(Component, {})
|
|
142
|
-
});
|
|
159
|
+
});
|
|
160
|
+
};
|
|
143
161
|
}
|
|
144
162
|
export {
|
|
145
|
-
|
|
146
|
-
|
|
163
|
+
collectSSRAssets,
|
|
164
|
+
createRemoteSSRComponent
|
|
147
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
|
};
|
|
@@ -43,4 +43,4 @@ export declare function patchWebpackConfig<T>(options: {
|
|
|
43
43
|
modernjsConfig: UserConfig<AppTools>;
|
|
44
44
|
mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions;
|
|
45
45
|
}): void;
|
|
46
|
-
export declare const
|
|
46
|
+
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-20240624115757",
|
|
4
4
|
"files": [
|
|
5
5
|
"dist/",
|
|
6
6
|
"types.d.ts",
|
|
@@ -46,9 +46,10 @@
|
|
|
46
46
|
"@modern-js/utils": "^2.49.2",
|
|
47
47
|
"@modern-js/node-bundle-require": "^2.49.2",
|
|
48
48
|
"node-fetch": "~3.3.0",
|
|
49
|
-
"
|
|
50
|
-
"@module-federation/
|
|
51
|
-
"@module-federation/
|
|
49
|
+
"react-error-boundary": "4.0.13",
|
|
50
|
+
"@module-federation/sdk": "0.0.0-next-20240624115757",
|
|
51
|
+
"@module-federation/enhanced": "0.0.0-next-20240624115757",
|
|
52
|
+
"@module-federation/node": "0.0.0-next-20240624115757"
|
|
52
53
|
},
|
|
53
54
|
"devDependencies": {
|
|
54
55
|
"@modern-js/app-tools": "^2.49.2",
|
|
@@ -56,7 +57,7 @@
|
|
|
56
57
|
"@modern-js/runtime": "^2.49.2",
|
|
57
58
|
"@modern-js/module-tools": "^2.35.0",
|
|
58
59
|
"@modern-js/tsconfig": "^2.35.0",
|
|
59
|
-
"@module-federation/manifest": "0.0.0-next-
|
|
60
|
+
"@module-federation/manifest": "0.0.0-next-20240624115757"
|
|
60
61
|
},
|
|
61
62
|
"peerDependencies": {
|
|
62
63
|
"react": ">=17",
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
type Id = string;
|
|
3
|
-
type IProps = {
|
|
4
|
-
id: Id;
|
|
5
|
-
injectScript?: boolean;
|
|
6
|
-
injectLink?: boolean;
|
|
7
|
-
loading?: React.ReactNode;
|
|
8
|
-
fallback?: ((err: Error) => React.FC | React.ReactElement) | React.FC | React.ReactElement;
|
|
9
|
-
} | Id;
|
|
10
|
-
declare function collectAssets(options: IProps): React.ReactNode[];
|
|
11
|
-
declare function MFReactComponent(props: IProps): React.JSX.Element;
|
|
12
|
-
export { MFReactComponent, collectAssets };
|