@module-federation/modern-js 0.0.0-next-20240813065037 → 0.0.0-next-20240814073142

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 (66) hide show
  1. package/dist/cjs/cli/ast/constant.js +46 -0
  2. package/dist/cjs/cli/ast/generateRoutes.js +140 -0
  3. package/dist/cjs/cli/ast/generateSlimRoutes.js +106 -0
  4. package/dist/cjs/cli/ast/index.js +31 -0
  5. package/dist/cjs/cli/configPlugin.js +1 -0
  6. package/dist/cjs/cli/constant.js +3 -0
  7. package/dist/cjs/cli/dataLoaderPlugin.js +205 -0
  8. package/dist/cjs/cli/index.js +6 -1
  9. package/dist/cjs/cli/server/dataLoaderPlugin.js +87 -0
  10. package/dist/cjs/cli/ssrPlugin.js +4 -4
  11. package/dist/cjs/interfaces/route.js +16 -0
  12. package/dist/cjs/runtime/constant.js +34 -0
  13. package/dist/cjs/runtime/dataLoader.js +87 -0
  14. package/dist/cjs/runtime/index.js +4 -1
  15. package/dist/cjs/runtime/utils.js +43 -0
  16. package/dist/cjs/runtime/withMFRouteId.js +31 -0
  17. package/dist/cjs/ssr-runtime/plugin.js +5 -7
  18. package/dist/esm/cli/ast/constant.js +16 -0
  19. package/dist/esm/cli/ast/generateRoutes.js +107 -0
  20. package/dist/esm/cli/ast/generateSlimRoutes.js +75 -0
  21. package/dist/esm/cli/ast/index.js +6 -0
  22. package/dist/esm/cli/configPlugin.js +1 -0
  23. package/dist/esm/cli/constant.js +2 -0
  24. package/dist/esm/cli/dataLoaderPlugin.js +191 -0
  25. package/dist/esm/cli/index.js +6 -1
  26. package/dist/esm/cli/server/dataLoaderPlugin.js +132 -0
  27. package/dist/esm/cli/ssrPlugin.js +2 -2
  28. package/dist/esm/interfaces/route.js +0 -0
  29. package/dist/esm/runtime/constant.js +8 -0
  30. package/dist/esm/runtime/dataLoader.js +125 -0
  31. package/dist/esm/runtime/index.js +3 -1
  32. package/dist/esm/runtime/utils.js +16 -0
  33. package/dist/esm/runtime/withMFRouteId.js +7 -0
  34. package/dist/esm/ssr-runtime/plugin.js +5 -10
  35. package/dist/esm-node/cli/ast/constant.js +16 -0
  36. package/dist/esm-node/cli/ast/generateRoutes.js +106 -0
  37. package/dist/esm-node/cli/ast/generateSlimRoutes.js +72 -0
  38. package/dist/esm-node/cli/ast/index.js +6 -0
  39. package/dist/esm-node/cli/configPlugin.js +1 -0
  40. package/dist/esm-node/cli/constant.js +2 -0
  41. package/dist/esm-node/cli/dataLoaderPlugin.js +169 -0
  42. package/dist/esm-node/cli/index.js +6 -1
  43. package/dist/esm-node/cli/server/dataLoaderPlugin.js +67 -0
  44. package/dist/esm-node/cli/ssrPlugin.js +2 -2
  45. package/dist/esm-node/interfaces/route.js +0 -0
  46. package/dist/esm-node/runtime/constant.js +8 -0
  47. package/dist/esm-node/runtime/dataLoader.js +63 -0
  48. package/dist/esm-node/runtime/index.js +3 -1
  49. package/dist/esm-node/runtime/utils.js +19 -0
  50. package/dist/esm-node/runtime/withMFRouteId.js +7 -0
  51. package/dist/esm-node/ssr-runtime/plugin.js +5 -7
  52. package/dist/types/cli/ast/constant.d.ts +7 -0
  53. package/dist/types/cli/ast/generateRoutes.d.ts +7 -0
  54. package/dist/types/cli/ast/generateSlimRoutes.d.ts +7 -0
  55. package/dist/types/cli/ast/index.d.ts +2 -0
  56. package/dist/types/cli/constant.d.ts +1 -0
  57. package/dist/types/cli/dataLoaderPlugin.d.ts +6 -0
  58. package/dist/types/cli/server/dataLoaderPlugin.d.ts +4 -0
  59. package/dist/types/interfaces/route.d.ts +13 -0
  60. package/dist/types/runtime/constant.d.ts +3 -0
  61. package/dist/types/runtime/dataLoader.d.ts +7 -0
  62. package/dist/types/runtime/index.d.ts +1 -0
  63. package/dist/types/runtime/utils.d.ts +1 -0
  64. package/dist/types/runtime/withMFRouteId.d.ts +1 -0
  65. package/dist/types/types/index.d.ts +15 -0
  66. package/package.json +37 -11
@@ -0,0 +1,191 @@
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 _ts_generator } from "@swc/helpers/_/_ts_generator";
4
+ import path from "path";
5
+ import { fs } from "@modern-js/utils";
6
+ import { transformName2Prefix } from "../runtime/utils";
7
+ import { PLUGIN_IDENTIFIER } from "../constant";
8
+ import { MF_FULL_ROUTES, MF_SLIM_ROUTES, MF_ROUTES_META } from "../runtime/constant";
9
+ import { generateRoutes, generateSlimRoutes } from "./ast";
10
+ import { MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME } from "./constant";
11
+ function generateExtraExposeFiles(options) {
12
+ var routesFilePath = options.routesFilePath, mfConfig = options.mfConfig, isServer = options.isServer, baseName = options.baseName;
13
+ var outputDir = path.resolve(process.cwd(), "node_modules/.federation");
14
+ fs.ensureDirSync(outputDir);
15
+ var addSuffix = function(fileName) {
16
+ if (!isServer) {
17
+ return "".concat(fileName, ".jsx");
18
+ }
19
+ return "".concat(fileName, ".server.jsx");
20
+ };
21
+ var routesFileContent = fs.readFileSync(routesFilePath, "utf-8");
22
+ var outputSlimRoutesPath = path.resolve(outputDir, addSuffix(MF_SLIM_ROUTES));
23
+ var outputFullRoutesPath = path.resolve(outputDir, addSuffix(MF_FULL_ROUTES));
24
+ var outputRoutesMetaPath = path.resolve(outputDir, "".concat(MF_ROUTES_META, ".js"));
25
+ generateSlimRoutes({
26
+ sourceCode: routesFileContent,
27
+ filePath: outputSlimRoutesPath,
28
+ prefix: transformName2Prefix(mfConfig.name),
29
+ baseName
30
+ });
31
+ generateRoutes({
32
+ sourceCode: routesFileContent,
33
+ filePath: outputFullRoutesPath,
34
+ prefix: transformName2Prefix(mfConfig.name),
35
+ baseName
36
+ });
37
+ fs.writeFileSync(outputRoutesMetaPath, "export const baseName = '".concat(baseName, "';"));
38
+ return {
39
+ outputSlimRoutesPath,
40
+ outputFullRoutesPath,
41
+ outputRoutesMetaPath
42
+ };
43
+ }
44
+ function addExpose(options) {
45
+ var mfConfig = options.mfConfig;
46
+ var _generateExtraExposeFiles = generateExtraExposeFiles(options), outputSlimRoutesPath = _generateExtraExposeFiles.outputSlimRoutesPath, outputFullRoutesPath = _generateExtraExposeFiles.outputFullRoutesPath, outputRoutesMetaPath = _generateExtraExposeFiles.outputRoutesMetaPath;
47
+ var fullRoutesKey = "./".concat(MF_FULL_ROUTES);
48
+ var slimRoutesKey = "./".concat(MF_SLIM_ROUTES);
49
+ var routeMetaKey = "./".concat(MF_ROUTES_META);
50
+ if (!mfConfig.exposes) {
51
+ var _obj;
52
+ mfConfig.exposes = (_obj = {}, _define_property(_obj, fullRoutesKey, outputFullRoutesPath), _define_property(_obj, slimRoutesKey, outputSlimRoutesPath), _define_property(_obj, routeMetaKey, outputRoutesMetaPath), _obj);
53
+ } else {
54
+ if (!Array.isArray(mfConfig.exposes)) {
55
+ if (!mfConfig.exposes[fullRoutesKey]) {
56
+ mfConfig.exposes[fullRoutesKey] = outputFullRoutesPath;
57
+ }
58
+ if (!mfConfig.exposes[slimRoutesKey]) {
59
+ mfConfig.exposes[slimRoutesKey] = outputSlimRoutesPath;
60
+ }
61
+ if (!mfConfig.exposes[routeMetaKey]) {
62
+ mfConfig.exposes[routeMetaKey] = outputRoutesMetaPath;
63
+ }
64
+ }
65
+ }
66
+ }
67
+ function addShared(options) {
68
+ var pkgName = options.pkgName, mfConfig = options.mfConfig;
69
+ var alias = "@".concat(pkgName, "/runtime/router");
70
+ if (!mfConfig.shared) {
71
+ mfConfig.shared = _define_property({}, alias, {
72
+ singleton: true
73
+ });
74
+ } else {
75
+ if (!Array.isArray(mfConfig.shared)) {
76
+ mfConfig.shared[alias] = {
77
+ singleton: true
78
+ };
79
+ } else {
80
+ mfConfig.shared.push(alias);
81
+ }
82
+ }
83
+ }
84
+ function _pathMfConfig(options) {
85
+ addShared(options);
86
+ addExpose(options);
87
+ }
88
+ var moduleFederationDataLoaderPlugin = function(enable, internalOptions, userConfig) {
89
+ return {
90
+ name: "@modern-js/plugin-module-federation-data-loader",
91
+ pre: [
92
+ "@modern-js/plugin-module-federation-config"
93
+ ],
94
+ post: [
95
+ "@modern-js/plugin-router",
96
+ "@modern-js/plugin-module-federation"
97
+ ],
98
+ setup: function() {
99
+ var _ref = _async_to_generator(function(param) {
100
+ var useConfigContext, useAppContext, _modernjsConfig_server, _internalOptions_csrConfig, baseName, _userConfig_partialSSRRemotes, partialSSRRemotes, fetchSSRByRouteIds, patchMFConfig, _userConfig_pkgName, pkgName, _userConfig_serverPlugin, serverPlugin, modernjsConfig, appContext, enableSSR, name, routesFilePath;
101
+ return _ts_generator(this, function(_state) {
102
+ useConfigContext = param.useConfigContext, useAppContext = param.useAppContext;
103
+ if (!enable) {
104
+ return [
105
+ 2
106
+ ];
107
+ }
108
+ baseName = userConfig.baseName, _userConfig_partialSSRRemotes = userConfig.partialSSRRemotes, partialSSRRemotes = _userConfig_partialSSRRemotes === void 0 ? [] : _userConfig_partialSSRRemotes, fetchSSRByRouteIds = userConfig.fetchSSRByRouteIds, patchMFConfig = userConfig.patchMFConfig, _userConfig_pkgName = userConfig.pkgName, pkgName = _userConfig_pkgName === void 0 ? "modern-js" : _userConfig_pkgName, _userConfig_serverPlugin = userConfig.serverPlugin, serverPlugin = _userConfig_serverPlugin === void 0 ? "@module-federation/modern-js/data-loader-server" : _userConfig_serverPlugin;
109
+ if (!baseName) {
110
+ throw new Error("".concat(PLUGIN_IDENTIFIER, " 'baseName' is required if you enable 'dataLoader'!"));
111
+ }
112
+ modernjsConfig = useConfigContext();
113
+ appContext = useAppContext();
114
+ enableSSR = Boolean(modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
115
+ name = (_internalOptions_csrConfig = internalOptions.csrConfig) === null || _internalOptions_csrConfig === void 0 ? void 0 : _internalOptions_csrConfig.name;
116
+ routesFilePath = path.resolve(appContext.internalDirectory, "./main/".concat(MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME));
117
+ return [
118
+ 2,
119
+ {
120
+ _internalRuntimePlugins: function(param2) {
121
+ var entrypoint = param2.entrypoint, plugins = param2.plugins;
122
+ plugins.push({
123
+ name: "ssrDataLoader",
124
+ path: "@module-federation/modern-js/data-loader",
125
+ config: {}
126
+ });
127
+ return {
128
+ entrypoint,
129
+ plugins
130
+ };
131
+ },
132
+ _internalServerPlugins: function _internalServerPlugins(param2) {
133
+ var plugins = param2.plugins;
134
+ plugins.push({
135
+ name: serverPlugin,
136
+ options: internalOptions
137
+ });
138
+ return {
139
+ plugins
140
+ };
141
+ },
142
+ config: /* @__PURE__ */ _async_to_generator(function() {
143
+ var patchMFConfigFn;
144
+ return _ts_generator(this, function(_state2) {
145
+ console.log("dataloader plugin config");
146
+ patchMFConfigFn = patchMFConfig || _pathMfConfig;
147
+ return [
148
+ 2,
149
+ {
150
+ // server: {
151
+ // ssrByRouteIds: ssrByRouteIds,
152
+ // },
153
+ tools: {
154
+ rspack: function rspack(_config, param2) {
155
+ var isServer = param2.isServer;
156
+ patchMFConfigFn({
157
+ mfConfig: isServer ? internalOptions.ssrConfig : internalOptions.csrConfig,
158
+ baseName,
159
+ pkgName,
160
+ isServer,
161
+ routesFilePath
162
+ });
163
+ console.log("dataloader plugin rspack");
164
+ }
165
+ },
166
+ source: {
167
+ define: {
168
+ MODERN_ROUTER_ID_PREFIX: JSON.stringify(transformName2Prefix(name))
169
+ }
170
+ }
171
+ }
172
+ ];
173
+ });
174
+ })
175
+ }
176
+ ];
177
+ });
178
+ });
179
+ return function(_) {
180
+ return _ref.apply(this, arguments);
181
+ };
182
+ }()
183
+ };
184
+ };
185
+ var dataLoaderPlugin_default = moduleFederationDataLoaderPlugin;
186
+ export {
187
+ dataLoaderPlugin_default as default,
188
+ generateRoutes,
189
+ generateSlimRoutes,
190
+ moduleFederationDataLoaderPlugin
191
+ };
@@ -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,132 @@
1
+ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
+ import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
3
+ import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
4
+ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
5
+ import { getInstance, init } from "@module-federation/enhanced/runtime";
6
+ import { MF_SLIM_ROUTES } from "../../runtime/constant";
7
+ function dataLoaderPlugin_default(options) {
8
+ return {
9
+ name: "MFDataLoaderServerPlugin",
10
+ pre: [
11
+ "@modern-js/plugin-inject-resource"
12
+ ],
13
+ setup: function setup(api) {
14
+ var mfConfig = options.csrConfig;
15
+ var remotes = mfConfig.remotes;
16
+ if (!remotes || !Object.keys(remotes).length) {
17
+ return {};
18
+ }
19
+ var runtimeRemotes = Object.entries(remotes).map(function(item) {
20
+ var _item = _sliced_to_array(item, 2), _alias = _item[0], nameAndEntry = _item[1];
21
+ var _nameAndEntry_split = _sliced_to_array(nameAndEntry.split("@"), 2), name = _nameAndEntry_split[0], entry = _nameAndEntry_split[1];
22
+ return {
23
+ name,
24
+ entry
25
+ };
26
+ });
27
+ var isHandled = false;
28
+ return {
29
+ prepare: function prepare() {
30
+ var middlewares = api.useAppContext().middlewares;
31
+ middlewares.push({
32
+ name: "MFDataLoaderServerPlugin",
33
+ handler: function() {
34
+ var _ref = _async_to_generator(function(c, next) {
35
+ var serverManifest, loaderBundles, instance, slimRoutes;
36
+ return _ts_generator(this, function(_state) {
37
+ switch (_state.label) {
38
+ case 0:
39
+ console.log("isHandled : ", isHandled);
40
+ serverManifest = c.get("serverManifest");
41
+ loaderBundles = serverManifest.loaderBundles;
42
+ console.log("loaderBundles.main.routes : ", loaderBundles.main.routes);
43
+ if (!isHandled)
44
+ return [
45
+ 3,
46
+ 2
47
+ ];
48
+ return [
49
+ 4,
50
+ next()
51
+ ];
52
+ case 1:
53
+ _state.sent();
54
+ return [
55
+ 3,
56
+ 5
57
+ ];
58
+ case 2:
59
+ instance = getInstance() || init({
60
+ name: mfConfig.name,
61
+ remotes: runtimeRemotes
62
+ });
63
+ return [
64
+ 4,
65
+ Promise.all(runtimeRemotes.map(function() {
66
+ var _ref2 = _async_to_generator(function(remote) {
67
+ var _ref3, routes, baseName;
68
+ return _ts_generator(this, function(_state2) {
69
+ switch (_state2.label) {
70
+ case 0:
71
+ return [
72
+ 4,
73
+ instance.loadRemote("".concat(remote.name, "/").concat(MF_SLIM_ROUTES))
74
+ ];
75
+ case 1:
76
+ _ref3 = _state2.sent(), routes = _ref3.routes, baseName = _ref3.baseName;
77
+ return [
78
+ 2,
79
+ {
80
+ routes,
81
+ baseName
82
+ }
83
+ ];
84
+ }
85
+ });
86
+ });
87
+ return function(remote) {
88
+ return _ref2.apply(this, arguments);
89
+ };
90
+ }()))
91
+ ];
92
+ case 3:
93
+ slimRoutes = _state.sent();
94
+ slimRoutes.forEach(function(slimRoute) {
95
+ var _loaderBundles_main_routes;
96
+ var routes = slimRoute.routes, baseName = slimRoute.baseName;
97
+ routes[0].path = "/".concat(baseName);
98
+ (_loaderBundles_main_routes = loaderBundles.main.routes).push.apply(_loaderBundles_main_routes, _to_consumable_array(routes));
99
+ });
100
+ console.log("loaderBundles.main.routes : ", loaderBundles.main.routes);
101
+ isHandled = true;
102
+ return [
103
+ 4,
104
+ next()
105
+ ];
106
+ case 4:
107
+ _state.sent();
108
+ _state.label = 5;
109
+ case 5:
110
+ return [
111
+ 2
112
+ ];
113
+ }
114
+ });
115
+ });
116
+ return function(c, next) {
117
+ return _ref.apply(this, arguments);
118
+ };
119
+ }(),
120
+ before: [
121
+ "render"
122
+ ]
123
+ });
124
+ }
125
+ };
126
+ }
127
+ };
128
+ }
129
+ ;
130
+ export {
131
+ dataLoaderPlugin_default as default
132
+ };
@@ -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() {
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
  };
@@ -0,0 +1,16 @@
1
+ import { _ as _define_property } from "@swc/helpers/_/_define_property";
2
+ function transformName2Prefix(name) {
3
+ var NameTransformSymbol = {
4
+ AT: "@",
5
+ HYPHEN: "-",
6
+ SLASH: "/",
7
+ UNDERLINE: "_"
8
+ };
9
+ var _obj;
10
+ var NameTransformMap = (_obj = {}, _define_property(_obj, NameTransformSymbol.AT, "SCOPE"), _define_property(_obj, NameTransformSymbol.HYPHEN, "HYPHEN"), _define_property(_obj, NameTransformSymbol.SLASH, "SLASH"), _define_property(_obj, NameTransformSymbol.UNDERLINE, "UNDERLINE"), _obj);
11
+ var SPLIT_SYMBOL = "@";
12
+ return "".concat(name.replace(new RegExp("".concat(NameTransformSymbol.AT), "g"), NameTransformMap[NameTransformSymbol.AT]).replace(new RegExp("".concat(NameTransformSymbol.HYPHEN), "g"), NameTransformMap[NameTransformSymbol.HYPHEN]).replace(new RegExp("".concat(NameTransformSymbol.SLASH), "g"), NameTransformMap[NameTransformSymbol.SLASH]).replace(new RegExp("".concat(NameTransformSymbol.UNDERLINE), "g"), NameTransformMap[NameTransformSymbol.UNDERLINE])).concat(SPLIT_SYMBOL);
13
+ }
14
+ export {
15
+ transformName2Prefix
16
+ };
@@ -0,0 +1,7 @@
1
+ function withMFRouteId(id) {
2
+ var prefix = typeof MODERN_ROUTER_ID_PREFIX === "string" ? MODERN_ROUTER_ID_PREFIX : "";
3
+ return prefix + id;
4
+ }
5
+ export {
6
+ withMFRouteId
7
+ };
@@ -4,24 +4,22 @@ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
4
4
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
5
5
  import hoistNonReactStatics from "hoist-non-react-statics";
6
6
  import { SSRLiveReload } from "./SSRLiveReload";
7
+ console.log("mfSSRPlugin trigger");
7
8
  var mfSSRPlugin = function() {
8
9
  return {
9
10
  name: "@module-federation/modern-js",
10
11
  setup: function() {
11
12
  return {
12
- init: function init(param, next) {
13
- var context = param.context;
13
+ beforeRender: function beforeRender() {
14
14
  return _async_to_generator(function() {
15
15
  var nodeUtils, shouldUpdate;
16
16
  return _ts_generator(this, function(_state) {
17
17
  switch (_state.label) {
18
18
  case 0:
19
+ console.log(111, "beforeRender");
19
20
  if (typeof window !== "undefined") {
20
21
  return [
21
- 2,
22
- next({
23
- context
24
- })
22
+ 2
25
23
  ];
26
24
  }
27
25
  globalThis.shouldUpdate = false;
@@ -53,10 +51,7 @@ var mfSSRPlugin = function() {
53
51
  _state.label = 4;
54
52
  case 4:
55
53
  return [
56
- 2,
57
- next({
58
- context
59
- })
54
+ 2
60
55
  ];
61
56
  }
62
57
  });
@@ -0,0 +1,16 @@
1
+ const IS_ROOT = "isRoot";
2
+ const ID = "id";
3
+ const COMPONENT = "component";
4
+ const LAZY_COMPONENT = "lazyImport";
5
+ const SHOULD_REVALIDATE = "shouldRevalidate";
6
+ const PRIVATE_COMPONENT = "_component";
7
+ const ELEMENT = "element";
8
+ export {
9
+ COMPONENT,
10
+ ELEMENT,
11
+ ID,
12
+ IS_ROOT,
13
+ LAZY_COMPONENT,
14
+ PRIVATE_COMPONENT,
15
+ SHOULD_REVALIDATE
16
+ };