@module-federation/modern-js 0.0.0-next-20240819040425 → 0.0.0-next-20240820034939

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.
Files changed (75) hide show
  1. package/dist/cjs/cli/ast/constant.js +49 -0
  2. package/dist/cjs/cli/ast/generateRoutes.js +140 -0
  3. package/dist/cjs/cli/ast/generateSerializableRoutes.js +91 -0
  4. package/dist/cjs/cli/ast/generateSlimRoutes.js +106 -0
  5. package/dist/cjs/cli/ast/index.js +34 -0
  6. package/dist/cjs/cli/bundler-plugins/SerializableRoutesPlugin.js +65 -0
  7. package/dist/cjs/cli/constant.js +6 -0
  8. package/dist/cjs/cli/dataLoaderPlugin.js +288 -0
  9. package/dist/cjs/cli/index.js +6 -1
  10. package/dist/cjs/cli/server/dataLoaderPlugin.js +83 -0
  11. package/dist/cjs/cli/ssrPlugin.js +4 -4
  12. package/dist/cjs/cli/utils.js +7 -3
  13. package/dist/cjs/interfaces/route.js +16 -0
  14. package/dist/cjs/runtime/constant.js +34 -0
  15. package/dist/cjs/runtime/dataLoader.js +87 -0
  16. package/dist/cjs/runtime/index.js +4 -1
  17. package/dist/cjs/runtime/utils.js +43 -0
  18. package/dist/cjs/runtime/withMFRouteId.js +31 -0
  19. package/dist/cjs/ssr-runtime/plugin.js +8 -7
  20. package/dist/esm/cli/ast/constant.js +18 -0
  21. package/dist/esm/cli/ast/generateRoutes.js +107 -0
  22. package/dist/esm/cli/ast/generateSerializableRoutes.js +58 -0
  23. package/dist/esm/cli/ast/generateSlimRoutes.js +75 -0
  24. package/dist/esm/cli/ast/index.js +8 -0
  25. package/dist/esm/cli/bundler-plugins/SerializableRoutesPlugin.js +45 -0
  26. package/dist/esm/cli/constant.js +4 -0
  27. package/dist/esm/cli/dataLoaderPlugin.js +325 -0
  28. package/dist/esm/cli/index.js +6 -1
  29. package/dist/esm/cli/server/dataLoaderPlugin.js +146 -0
  30. package/dist/esm/cli/ssrPlugin.js +2 -2
  31. package/dist/esm/cli/utils.js +5 -2
  32. package/dist/esm/interfaces/route.js +0 -0
  33. package/dist/esm/runtime/constant.js +8 -0
  34. package/dist/esm/runtime/dataLoader.js +125 -0
  35. package/dist/esm/runtime/index.js +3 -1
  36. package/dist/esm/runtime/utils.js +16 -0
  37. package/dist/esm/runtime/withMFRouteId.js +7 -0
  38. package/dist/esm/ssr-runtime/plugin.js +8 -10
  39. package/dist/esm-node/cli/ast/constant.js +18 -0
  40. package/dist/esm-node/cli/ast/generateRoutes.js +106 -0
  41. package/dist/esm-node/cli/ast/generateSerializableRoutes.js +57 -0
  42. package/dist/esm-node/cli/ast/generateSlimRoutes.js +72 -0
  43. package/dist/esm-node/cli/ast/index.js +8 -0
  44. package/dist/esm-node/cli/bundler-plugins/SerializableRoutesPlugin.js +30 -0
  45. package/dist/esm-node/cli/constant.js +4 -0
  46. package/dist/esm-node/cli/dataLoaderPlugin.js +252 -0
  47. package/dist/esm-node/cli/index.js +6 -1
  48. package/dist/esm-node/cli/server/dataLoaderPlugin.js +63 -0
  49. package/dist/esm-node/cli/ssrPlugin.js +2 -2
  50. package/dist/esm-node/cli/utils.js +5 -2
  51. package/dist/esm-node/interfaces/route.js +0 -0
  52. package/dist/esm-node/runtime/constant.js +8 -0
  53. package/dist/esm-node/runtime/dataLoader.js +63 -0
  54. package/dist/esm-node/runtime/index.js +3 -1
  55. package/dist/esm-node/runtime/utils.js +19 -0
  56. package/dist/esm-node/runtime/withMFRouteId.js +7 -0
  57. package/dist/esm-node/ssr-runtime/plugin.js +8 -7
  58. package/dist/types/cli/ast/constant.d.ts +8 -0
  59. package/dist/types/cli/ast/generateRoutes.d.ts +7 -0
  60. package/dist/types/cli/ast/generateSerializableRoutes.d.ts +5 -0
  61. package/dist/types/cli/ast/generateSlimRoutes.d.ts +7 -0
  62. package/dist/types/cli/ast/index.d.ts +3 -0
  63. package/dist/types/cli/bundler-plugins/SerializableRoutesPlugin.d.ts +12 -0
  64. package/dist/types/cli/constant.d.ts +2 -0
  65. package/dist/types/cli/dataLoaderPlugin.d.ts +6 -0
  66. package/dist/types/cli/server/dataLoaderPlugin.d.ts +5 -0
  67. package/dist/types/cli/utils.d.ts +2 -0
  68. package/dist/types/interfaces/route.d.ts +13 -0
  69. package/dist/types/runtime/constant.d.ts +3 -0
  70. package/dist/types/runtime/dataLoader.d.ts +7 -0
  71. package/dist/types/runtime/index.d.ts +1 -0
  72. package/dist/types/runtime/utils.d.ts +1 -0
  73. package/dist/types/runtime/withMFRouteId.d.ts +1 -0
  74. package/dist/types/types/index.d.ts +11 -0
  75. package/package.json +40 -11
@@ -0,0 +1,325 @@
1
+ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
+ import { _ as _define_property } from "@swc/helpers/_/_define_property";
3
+ import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
4
+ import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
5
+ import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
6
+ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
7
+ import path from "path";
8
+ import { fs } from "@modern-js/utils";
9
+ import { transformName2Prefix } from "../runtime/utils";
10
+ import { PLUGIN_IDENTIFIER } from "../constant";
11
+ import { MF_FULL_ROUTES, MF_SLIM_ROUTES, MF_ROUTES_META } from "../runtime/constant";
12
+ import { generateRoutes, generateSlimRoutes } from "./ast";
13
+ import { MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME, META_NAME } from "./constant";
14
+ import { getIPV4, replaceRemoteUrl } from "./utils";
15
+ import { SerializableRoutesPlugin, SERIALIZABLE_ROUTES } from "./bundler-plugins/SerializableRoutesPlugin";
16
+ function generateExtraExposeFiles(options) {
17
+ var routesFilePath = options.routesFilePath, mfConfig = options.mfConfig, isServer = options.isServer, baseName = options.baseName;
18
+ var outputDir = path.resolve(process.cwd(), "node_modules/.federation");
19
+ fs.ensureDirSync(outputDir);
20
+ var addSuffix = function(fileName) {
21
+ if (!isServer) {
22
+ return "".concat(fileName, ".jsx");
23
+ }
24
+ return "".concat(fileName, ".server.jsx");
25
+ };
26
+ var routesFileContent = fs.readFileSync(routesFilePath, "utf-8");
27
+ var outputSlimRoutesPath = path.resolve(outputDir, addSuffix(MF_SLIM_ROUTES));
28
+ var outputFullRoutesPath = path.resolve(outputDir, addSuffix(MF_FULL_ROUTES));
29
+ var outputRoutesMetaPath = path.resolve(outputDir, "".concat(MF_ROUTES_META, ".js"));
30
+ generateSlimRoutes({
31
+ sourceCode: routesFileContent,
32
+ filePath: outputSlimRoutesPath,
33
+ prefix: transformName2Prefix(mfConfig.name),
34
+ baseName
35
+ });
36
+ generateRoutes({
37
+ sourceCode: routesFileContent,
38
+ filePath: outputFullRoutesPath,
39
+ prefix: transformName2Prefix(mfConfig.name),
40
+ baseName
41
+ });
42
+ fs.writeFileSync(outputRoutesMetaPath, "export const baseName = '".concat(baseName, "';"));
43
+ return {
44
+ outputSlimRoutesPath,
45
+ outputFullRoutesPath,
46
+ outputRoutesMetaPath
47
+ };
48
+ }
49
+ function addExpose(options) {
50
+ var mfConfig = options.mfConfig;
51
+ var _generateExtraExposeFiles = generateExtraExposeFiles(options), outputSlimRoutesPath = _generateExtraExposeFiles.outputSlimRoutesPath, outputFullRoutesPath = _generateExtraExposeFiles.outputFullRoutesPath, outputRoutesMetaPath = _generateExtraExposeFiles.outputRoutesMetaPath;
52
+ var fullRoutesKey = "./".concat(MF_FULL_ROUTES);
53
+ var slimRoutesKey = "./".concat(MF_SLIM_ROUTES);
54
+ var routeMetaKey = "./".concat(MF_ROUTES_META);
55
+ if (!mfConfig.exposes) {
56
+ var _obj;
57
+ mfConfig.exposes = (_obj = {}, _define_property(_obj, fullRoutesKey, outputFullRoutesPath), _define_property(_obj, slimRoutesKey, outputSlimRoutesPath), _define_property(_obj, routeMetaKey, outputRoutesMetaPath), _obj);
58
+ } else {
59
+ if (!Array.isArray(mfConfig.exposes)) {
60
+ if (!mfConfig.exposes[fullRoutesKey]) {
61
+ mfConfig.exposes[fullRoutesKey] = outputFullRoutesPath;
62
+ }
63
+ if (!mfConfig.exposes[slimRoutesKey]) {
64
+ mfConfig.exposes[slimRoutesKey] = outputSlimRoutesPath;
65
+ }
66
+ if (!mfConfig.exposes[routeMetaKey]) {
67
+ mfConfig.exposes[routeMetaKey] = outputRoutesMetaPath;
68
+ }
69
+ }
70
+ }
71
+ }
72
+ function addShared(options) {
73
+ var metaName = options.metaName, mfConfig = options.mfConfig;
74
+ var alias = "@".concat(metaName, "/runtime/router");
75
+ if (!mfConfig.shared) {
76
+ mfConfig.shared = _define_property({}, alias, {
77
+ singleton: true
78
+ });
79
+ } else {
80
+ if (!Array.isArray(mfConfig.shared)) {
81
+ mfConfig.shared[alias] = {
82
+ singleton: true
83
+ };
84
+ } else {
85
+ mfConfig.shared.push(alias);
86
+ }
87
+ }
88
+ }
89
+ function patchMfConfig(options) {
90
+ addShared(options);
91
+ addExpose(options);
92
+ }
93
+ function _fetchSSRByRouteIds(partialSSRRemotes, mfConfig, transformRuntimeFn) {
94
+ return __fetchSSRByRouteIds.apply(this, arguments);
95
+ }
96
+ function __fetchSSRByRouteIds() {
97
+ __fetchSSRByRouteIds = _async_to_generator(function(partialSSRRemotes, mfConfig, transformRuntimeFn) {
98
+ var partialMfConfig, runtimeInitOptions, remoteProviderRouteIds, collectIds;
99
+ return _ts_generator(this, function(_state) {
100
+ switch (_state.label) {
101
+ case 0:
102
+ partialMfConfig = {
103
+ name: mfConfig.name,
104
+ remotes: _object_spread({}, mfConfig.remotes)
105
+ };
106
+ runtimeInitOptions = transformRuntimeFn(partialMfConfig);
107
+ replaceRemoteUrl(runtimeInitOptions, "ipv4");
108
+ if (!runtimeInitOptions.remotes.length || !partialSSRRemotes.length) {
109
+ return [
110
+ 2,
111
+ void 0
112
+ ];
113
+ }
114
+ remoteProviderRouteIds = /* @__PURE__ */ new Set();
115
+ collectIds = function(route) {
116
+ remoteProviderRouteIds.add(route.id);
117
+ if (route.children) {
118
+ route.children.forEach(function(r) {
119
+ collectIds(r);
120
+ });
121
+ }
122
+ };
123
+ return [
124
+ 4,
125
+ Promise.all(runtimeInitOptions.remotes.map(function() {
126
+ var _ref = _async_to_generator(function(remote) {
127
+ var entry, ipv4, url, serializableRoutesUrl, serializableRoutesRet, serializableRoutes;
128
+ return _ts_generator(this, function(_state2) {
129
+ switch (_state2.label) {
130
+ case 0:
131
+ entry = "entry" in remote ? remote.entry : "";
132
+ if (!entry) {
133
+ return [
134
+ 2,
135
+ void 0
136
+ ];
137
+ }
138
+ ipv4 = getIPV4();
139
+ url = new URL(entry);
140
+ serializableRoutesUrl = url.href.replace(url.pathname, "/".concat(SERIALIZABLE_ROUTES)).replace("localhost", ipv4);
141
+ return [
142
+ 4,
143
+ fetch(serializableRoutesUrl)
144
+ ];
145
+ case 1:
146
+ serializableRoutesRet = _state2.sent();
147
+ return [
148
+ 4,
149
+ serializableRoutesRet.json()
150
+ ];
151
+ case 2:
152
+ serializableRoutes = _state2.sent();
153
+ serializableRoutes.forEach(function(serializableRoute) {
154
+ collectIds(serializableRoute);
155
+ });
156
+ return [
157
+ 2
158
+ ];
159
+ }
160
+ });
161
+ });
162
+ return function(remote) {
163
+ return _ref.apply(this, arguments);
164
+ };
165
+ }()))
166
+ ];
167
+ case 1:
168
+ _state.sent();
169
+ return [
170
+ 2,
171
+ _to_consumable_array(remoteProviderRouteIds)
172
+ ];
173
+ }
174
+ });
175
+ });
176
+ return __fetchSSRByRouteIds.apply(this, arguments);
177
+ }
178
+ function _transformRuntimeOptions(buildOptions) {
179
+ var remotes = buildOptions.remotes || {};
180
+ var runtimeRemotes = Object.entries(remotes).map(function(remote) {
181
+ var _remote = _sliced_to_array(remote, 2), _alias = _remote[0], nameAndEntry = _remote[1];
182
+ var _nameAndEntry_split = _sliced_to_array(nameAndEntry.split("@"), 2), name = _nameAndEntry_split[0], entry = _nameAndEntry_split[1];
183
+ return {
184
+ name,
185
+ entry
186
+ };
187
+ });
188
+ return {
189
+ name: buildOptions.name,
190
+ remotes: runtimeRemotes
191
+ };
192
+ }
193
+ var moduleFederationDataLoaderPlugin = function(enable, internalOptions, userConfig) {
194
+ return {
195
+ name: "@modern-js/plugin-module-federation-data-loader",
196
+ pre: [
197
+ "@modern-js/plugin-module-federation-config"
198
+ ],
199
+ post: [
200
+ "@modern-js/plugin-router",
201
+ "@modern-js/plugin-module-federation"
202
+ ],
203
+ setup: function() {
204
+ var _ref = _async_to_generator(function(param) {
205
+ var useConfigContext, useAppContext, _modernjsConfig_server, _internalOptions_csrConfig, baseName, _userConfig_partialSSRRemotes, partialSSRRemotes, fetchSSRByRouteIds, _userConfig_metaName, metaName, _userConfig_serverPlugin, serverPlugin, transformRuntimeOptions, modernjsConfig, appContext, enableSSR, name, routesFilePath, transformRuntimeFn;
206
+ return _ts_generator(this, function(_state) {
207
+ useConfigContext = param.useConfigContext, useAppContext = param.useAppContext;
208
+ if (!enable) {
209
+ return [
210
+ 2
211
+ ];
212
+ }
213
+ baseName = userConfig.baseName, _userConfig_partialSSRRemotes = userConfig.partialSSRRemotes, partialSSRRemotes = _userConfig_partialSSRRemotes === void 0 ? [] : _userConfig_partialSSRRemotes, fetchSSRByRouteIds = userConfig.fetchSSRByRouteIds, _userConfig_metaName = userConfig.metaName, metaName = _userConfig_metaName === void 0 ? META_NAME : _userConfig_metaName, _userConfig_serverPlugin = userConfig.serverPlugin, serverPlugin = _userConfig_serverPlugin === void 0 ? "@module-federation/modern-js/data-loader-server" : _userConfig_serverPlugin, transformRuntimeOptions = userConfig.transformRuntimeOptions;
214
+ if (!baseName) {
215
+ throw new Error("".concat(PLUGIN_IDENTIFIER, " 'baseName' is required if you enable 'dataLoader'!"));
216
+ }
217
+ modernjsConfig = useConfigContext();
218
+ appContext = useAppContext();
219
+ enableSSR = Boolean(modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
220
+ name = (_internalOptions_csrConfig = internalOptions.csrConfig) === null || _internalOptions_csrConfig === void 0 ? void 0 : _internalOptions_csrConfig.name;
221
+ routesFilePath = path.resolve(appContext.internalDirectory.replace(META_NAME, metaName || META_NAME), "./main/".concat(MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME));
222
+ transformRuntimeFn = transformRuntimeOptions || _transformRuntimeOptions;
223
+ return [
224
+ 2,
225
+ {
226
+ _internalRuntimePlugins: function(param2) {
227
+ var entrypoint = param2.entrypoint, plugins = param2.plugins;
228
+ plugins.push({
229
+ name: "ssrDataLoader",
230
+ path: "@module-federation/modern-js/data-loader",
231
+ config: {}
232
+ });
233
+ return {
234
+ entrypoint,
235
+ plugins
236
+ };
237
+ },
238
+ _internalServerPlugins: function _internalServerPlugins(param2) {
239
+ var plugins = param2.plugins;
240
+ plugins.push({
241
+ name: serverPlugin,
242
+ options: transformRuntimeFn(internalOptions.csrConfig)
243
+ });
244
+ return {
245
+ plugins
246
+ };
247
+ },
248
+ config: /* @__PURE__ */ _async_to_generator(function() {
249
+ var fetchFn, ssrByRouteIds;
250
+ return _ts_generator(this, function(_state2) {
251
+ switch (_state2.label) {
252
+ case 0:
253
+ fetchFn = fetchSSRByRouteIds || _fetchSSRByRouteIds;
254
+ return [
255
+ 4,
256
+ fetchFn(partialSSRRemotes, internalOptions.csrConfig, transformRuntimeFn)
257
+ ];
258
+ case 1:
259
+ ssrByRouteIds = _state2.sent();
260
+ return [
261
+ 2,
262
+ {
263
+ server: {
264
+ ssrByRouteIds
265
+ },
266
+ tools: {
267
+ rspack: function rspack(_config, param2) {
268
+ var isServer = param2.isServer;
269
+ patchMfConfig({
270
+ mfConfig: isServer ? internalOptions.ssrConfig : internalOptions.csrConfig,
271
+ baseName,
272
+ metaName,
273
+ isServer,
274
+ routesFilePath
275
+ });
276
+ },
277
+ webpack: function webpack(_config, param2) {
278
+ var isServer = param2.isServer;
279
+ patchMfConfig({
280
+ mfConfig: isServer ? internalOptions.ssrConfig : internalOptions.csrConfig,
281
+ baseName,
282
+ metaName,
283
+ isServer,
284
+ routesFilePath
285
+ });
286
+ },
287
+ bundlerChain: function bundlerChain(chain, param2) {
288
+ var isServer = param2.isServer;
289
+ if (!isServer && internalOptions.csrConfig && Object.keys(internalOptions.csrConfig.exposes).length) {
290
+ chain.plugin("SerializableRoutesPlugin").use(SerializableRoutesPlugin, [
291
+ {
292
+ routesFilePath,
293
+ prefix: transformName2Prefix(internalOptions.csrConfig.name)
294
+ }
295
+ ]);
296
+ }
297
+ }
298
+ },
299
+ source: {
300
+ define: {
301
+ MODERN_ROUTER_ID_PREFIX: JSON.stringify(transformName2Prefix(name))
302
+ }
303
+ }
304
+ }
305
+ ];
306
+ }
307
+ });
308
+ })
309
+ }
310
+ ];
311
+ });
312
+ });
313
+ return function(_) {
314
+ return _ref.apply(this, arguments);
315
+ };
316
+ }()
317
+ };
318
+ };
319
+ var dataLoaderPlugin_default = moduleFederationDataLoaderPlugin;
320
+ export {
321
+ dataLoaderPlugin_default as default,
322
+ generateRoutes,
323
+ generateSlimRoutes,
324
+ moduleFederationDataLoaderPlugin
325
+ };
@@ -1,9 +1,11 @@
1
1
  import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
+ import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
2
3
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
4
  import { ModuleFederationPlugin as WebpackModuleFederationPlugin, AsyncBoundaryPlugin } from "@module-federation/enhanced";
4
5
  import { ModuleFederationPlugin as RspackModuleFederationPlugin } from "@module-federation/enhanced/rspack";
5
6
  import { moduleFederationConfigPlugin } from "./configPlugin";
6
7
  import { moduleFederationSSRPlugin } from "./ssrPlugin";
8
+ import { moduleFederationDataLoaderPlugin } from "./dataLoaderPlugin";
7
9
  var moduleFederationPlugin = function() {
8
10
  var userConfig = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
9
11
  var internalModernPluginOptions = {
@@ -79,7 +81,10 @@ var moduleFederationPlugin = function() {
79
81
  }(),
80
82
  usePlugins: [
81
83
  moduleFederationConfigPlugin(internalModernPluginOptions),
82
- moduleFederationSSRPlugin(internalModernPluginOptions)
84
+ moduleFederationSSRPlugin(internalModernPluginOptions),
85
+ moduleFederationDataLoaderPlugin(Boolean(userConfig.dataLoader), internalModernPluginOptions, _object_spread({
86
+ baseName: ""
87
+ }, userConfig.dataLoader))
83
88
  ]
84
89
  };
85
90
  };
@@ -0,0 +1,146 @@
1
+ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
+ import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
3
+ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
4
+ import { getInstance, init } from "@module-federation/enhanced/runtime";
5
+ import { MF_SLIM_ROUTES } from "../../runtime/constant";
6
+ function getSlimRemotes(mfInstance) {
7
+ return _getSlimRemotes.apply(this, arguments);
8
+ }
9
+ function _getSlimRemotes() {
10
+ _getSlimRemotes = _async_to_generator(function(mfInstance) {
11
+ return _ts_generator(this, function(_state) {
12
+ switch (_state.label) {
13
+ case 0:
14
+ return [
15
+ 4,
16
+ Promise.all(mfInstance.options.remotes.map(function() {
17
+ var _ref = _async_to_generator(function(remote) {
18
+ var _ref2, routes, baseName;
19
+ return _ts_generator(this, function(_state2) {
20
+ switch (_state2.label) {
21
+ case 0:
22
+ return [
23
+ 4,
24
+ mfInstance.loadRemote("".concat(remote.name, "/").concat(MF_SLIM_ROUTES))
25
+ ];
26
+ case 1:
27
+ _ref2 = _state2.sent(), routes = _ref2.routes, baseName = _ref2.baseName;
28
+ return [
29
+ 2,
30
+ {
31
+ routes,
32
+ baseName
33
+ }
34
+ ];
35
+ }
36
+ });
37
+ });
38
+ return function(remote) {
39
+ return _ref.apply(this, arguments);
40
+ };
41
+ }()))
42
+ ];
43
+ case 1:
44
+ return [
45
+ 2,
46
+ _state.sent()
47
+ ];
48
+ }
49
+ });
50
+ });
51
+ return _getSlimRemotes.apply(this, arguments);
52
+ }
53
+ function dataLoaderPlugin_default(mfRuntimeOptions) {
54
+ return {
55
+ name: "MFDataLoaderServerPlugin",
56
+ pre: [
57
+ "@modern-js/plugin-inject-resource"
58
+ ],
59
+ setup: function setup(api) {
60
+ var remotes = mfRuntimeOptions.remotes, name = mfRuntimeOptions.name;
61
+ if (!remotes.length) {
62
+ return {};
63
+ }
64
+ var isHandled = false;
65
+ return {
66
+ prepare: function prepare() {
67
+ var middlewares = api.useAppContext().middlewares;
68
+ middlewares.push({
69
+ name: "MFDataLoaderServerPlugin",
70
+ handler: function() {
71
+ var _ref = _async_to_generator(function(c, next) {
72
+ var serverManifest, loaderBundles, nestedRoutesJson, instance, slimRoutes;
73
+ return _ts_generator(this, function(_state) {
74
+ switch (_state.label) {
75
+ case 0:
76
+ console.log("isHandled : ", isHandled);
77
+ serverManifest = c.get("serverManifest");
78
+ loaderBundles = serverManifest.loaderBundles, nestedRoutesJson = serverManifest.nestedRoutesJson;
79
+ console.log("nestedRoutesJson: ", nestedRoutesJson);
80
+ console.log("loaderBundles.main.routes : ", loaderBundles.main.routes);
81
+ if (!isHandled)
82
+ return [
83
+ 3,
84
+ 2
85
+ ];
86
+ return [
87
+ 4,
88
+ next()
89
+ ];
90
+ case 1:
91
+ _state.sent();
92
+ return [
93
+ 3,
94
+ 5
95
+ ];
96
+ case 2:
97
+ instance = getInstance() || init({
98
+ name,
99
+ remotes
100
+ });
101
+ return [
102
+ 4,
103
+ getSlimRemotes(instance)
104
+ ];
105
+ case 3:
106
+ slimRoutes = _state.sent();
107
+ slimRoutes.forEach(function(slimRoute) {
108
+ var _loaderBundles_main_routes, _nestedRoutesJson_default_main;
109
+ var routes = slimRoute.routes, baseName = slimRoute.baseName;
110
+ routes[0].path = "/".concat(baseName);
111
+ (_loaderBundles_main_routes = loaderBundles.main.routes).push.apply(_loaderBundles_main_routes, _to_consumable_array(routes));
112
+ (_nestedRoutesJson_default_main = nestedRoutesJson.default.main).push.apply(_nestedRoutesJson_default_main, _to_consumable_array(routes));
113
+ });
114
+ console.log("push loaderBundles.main.routes done ");
115
+ isHandled = true;
116
+ return [
117
+ 4,
118
+ next()
119
+ ];
120
+ case 4:
121
+ _state.sent();
122
+ _state.label = 5;
123
+ case 5:
124
+ return [
125
+ 2
126
+ ];
127
+ }
128
+ });
129
+ });
130
+ return function(c, next) {
131
+ return _ref.apply(this, arguments);
132
+ };
133
+ }(),
134
+ before: [
135
+ "render"
136
+ ]
137
+ });
138
+ }
139
+ };
140
+ }
141
+ };
142
+ }
143
+ ;
144
+ export {
145
+ dataLoaderPlugin_default as default
146
+ };
@@ -2,9 +2,9 @@ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
2
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
3
  import path from "path";
4
4
  import { fs } from "@modern-js/utils";
5
- import { ModuleFederationPlugin } from "@module-federation/enhanced/webpack";
5
+ import { ModuleFederationPlugin } from "@module-federation/enhanced";
6
6
  import { ModuleFederationPlugin as RspackModuleFederationPlugin } from "@module-federation/enhanced/rspack";
7
- import UniverseEntryChunkTrackerPlugin from "@module-federation/node/universe-entry-chunk-tracker-plugin";
7
+ import { UniverseEntryChunkTrackerPlugin } from "@module-federation/node";
8
8
  import { updateStatsAndManifest } from "./manifest";
9
9
  import { isDev } from "./constant";
10
10
  function setEnv() {
@@ -79,7 +79,9 @@ var replaceRemoteUrl = function(mfConfig, remoteIpStrategy) {
79
79
  if (typeof remoteObject === "string") {
80
80
  return;
81
81
  }
82
- handleRemoteObject(remoteObject);
82
+ if ("entry" in remoteObject && typeof remoteObject.entry === "string") {
83
+ remoteObject.entry = remoteObject.entry.replace(LOCALHOST, ipv4);
84
+ }
83
85
  });
84
86
  } else if (typeof mfConfig.remotes !== "string") {
85
87
  handleRemoteObject(mfConfig.remotes);
@@ -339,5 +341,6 @@ export {
339
341
  getMFConfig,
340
342
  patchBundlerConfig,
341
343
  patchIgnoreWarning,
342
- patchMFConfig
344
+ patchMFConfig,
345
+ replaceRemoteUrl
343
346
  };
File without changes
@@ -0,0 +1,8 @@
1
+ var MF_SLIM_ROUTES = "mf-slim-routes";
2
+ var MF_FULL_ROUTES = "mf-full-routes";
3
+ var MF_ROUTES_META = "mf-routes-meta";
4
+ export {
5
+ MF_FULL_ROUTES,
6
+ MF_ROUTES_META,
7
+ MF_SLIM_ROUTES
8
+ };
@@ -0,0 +1,125 @@
1
+ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
+ import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
3
+ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
4
+ import { jsx as _jsx } from "react/jsx-runtime";
5
+ import { getInstance, loadRemote } from "@module-federation/enhanced/runtime";
6
+ import { MF_FULL_ROUTES } from "./constant";
7
+ globalThis.mfRemoteRoutes = globalThis.mfRemoteRoutes || [];
8
+ var _globalThis_mfHasLoadedRemoteRoutes;
9
+ globalThis.mfHasLoadedRemoteRoutes = (_globalThis_mfHasLoadedRemoteRoutes = globalThis.mfHasLoadedRemoteRoutes) !== null && _globalThis_mfHasLoadedRemoteRoutes !== void 0 ? _globalThis_mfHasLoadedRemoteRoutes : false;
10
+ function loadRoutes() {
11
+ return _loadRoutes.apply(this, arguments);
12
+ }
13
+ function _loadRoutes() {
14
+ _loadRoutes = _async_to_generator(function() {
15
+ var _getInstance, remotes, remoteModuleIds, traverse;
16
+ return _ts_generator(this, function(_state) {
17
+ switch (_state.label) {
18
+ case 0:
19
+ if (globalThis.mfHasLoadedRemoteRoutes) {
20
+ return [
21
+ 2
22
+ ];
23
+ }
24
+ remotes = (_getInstance = getInstance()) === null || _getInstance === void 0 ? void 0 : _getInstance.options.remotes;
25
+ if (!remotes) {
26
+ return [
27
+ 2
28
+ ];
29
+ }
30
+ remoteModuleIds = remotes.map(function(remote) {
31
+ return "".concat(remote.name, "/").concat(MF_FULL_ROUTES);
32
+ });
33
+ traverse = function(cRoutes, prefix) {
34
+ cRoutes.forEach(function(i) {
35
+ i.id = prefix + i.id;
36
+ var Comp = i.component;
37
+ i.element = /* @__PURE__ */ _jsx(Comp, {});
38
+ if (i.children) {
39
+ traverse(i.children, prefix);
40
+ }
41
+ });
42
+ };
43
+ return [
44
+ 4,
45
+ Promise.all(remoteModuleIds.map(function() {
46
+ var _ref = _async_to_generator(function(remoteModuleId) {
47
+ var _globalThis_mfRemoteRoutes, remoteName, _ref2, routes, baseName;
48
+ return _ts_generator(this, function(_state2) {
49
+ switch (_state2.label) {
50
+ case 0:
51
+ remoteName = remoteModuleId.split("/".concat(MF_FULL_ROUTES))[0];
52
+ return [
53
+ 4,
54
+ loadRemote(remoteModuleId)
55
+ ];
56
+ case 1:
57
+ _ref2 = _state2.sent(), routes = _ref2.routes, baseName = _ref2.baseName;
58
+ routes[0].path = "/".concat(baseName);
59
+ routes[0].isRoot = false;
60
+ (_globalThis_mfRemoteRoutes = globalThis.mfRemoteRoutes).push.apply(_globalThis_mfRemoteRoutes, _to_consumable_array(routes));
61
+ return [
62
+ 2
63
+ ];
64
+ }
65
+ });
66
+ });
67
+ return function(remoteModuleId) {
68
+ return _ref.apply(this, arguments);
69
+ };
70
+ }()))
71
+ ];
72
+ case 1:
73
+ _state.sent();
74
+ globalThis.mfHasLoadedRemoteRoutes = true;
75
+ return [
76
+ 2,
77
+ globalThis.mfRemoteRoutes
78
+ ];
79
+ }
80
+ });
81
+ });
82
+ return _loadRoutes.apply(this, arguments);
83
+ }
84
+ var ssrDataLoaderPlugin = function() {
85
+ return {
86
+ name: "@modern-js/plugin-mf-data-loader",
87
+ post: [
88
+ "@modern-js/plugin-router"
89
+ ],
90
+ setup: function() {
91
+ return {
92
+ beforeRender: function beforeRender(param) {
93
+ var context = param.context;
94
+ return _async_to_generator(function() {
95
+ return _ts_generator(this, function(_state) {
96
+ switch (_state.label) {
97
+ case 0:
98
+ console.log("init");
99
+ return [
100
+ 4,
101
+ loadRoutes()
102
+ ];
103
+ case 1:
104
+ _state.sent();
105
+ return [
106
+ 2
107
+ ];
108
+ }
109
+ });
110
+ })();
111
+ },
112
+ modifyRoutes: function(routes) {
113
+ var _routes;
114
+ console.log("modifyRoutes");
115
+ (_routes = routes).push.apply(_routes, _to_consumable_array(globalThis.mfRemoteRoutes));
116
+ console.log("routes: ", routes);
117
+ return routes;
118
+ }
119
+ };
120
+ }
121
+ };
122
+ };
123
+ export {
124
+ ssrDataLoaderPlugin
125
+ };
@@ -1,5 +1,7 @@
1
1
  export * from "@module-federation/enhanced/runtime";
2
2
  import { createRemoteSSRComponent } from "./createRemoteSSRComponent";
3
+ import { withMFRouteId } from "./withMFRouteId";
3
4
  export {
4
- createRemoteSSRComponent
5
+ createRemoteSSRComponent,
6
+ withMFRouteId
5
7
  };