@module-federation/modern-js 0.0.0-next-20240909092952 → 0.0.0-next-20240909101028

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 (91) hide show
  1. package/dist/cjs/cli/{dataLoader/ast/index.js → constant.js} +6 -6
  2. package/dist/cjs/cli/index.js +1 -5
  3. package/dist/cjs/cli/mfRuntimePlugins/inject-node-fetch.js +10 -7
  4. package/dist/cjs/cli/mfRuntimePlugins/resolve-entry-ipv4.js +38 -40
  5. package/dist/cjs/cli/ssrPlugin.js +1 -1
  6. package/dist/cjs/cli/utils.js +4 -8
  7. package/dist/cjs/cli/utils.spec.js +1 -1
  8. package/dist/cjs/constant.js +2 -32
  9. package/dist/cjs/runtime/index.js +1 -4
  10. package/dist/cjs/ssr-runtime/plugin.js +7 -7
  11. package/dist/esm/cli/constant.js +4 -0
  12. package/dist/esm/cli/index.js +1 -4
  13. package/dist/esm/cli/mfRuntimePlugins/inject-node-fetch.js +10 -7
  14. package/dist/esm/cli/ssrPlugin.js +1 -1
  15. package/dist/esm/cli/utils.js +3 -6
  16. package/dist/esm/cli/utils.spec.js +1 -1
  17. package/dist/esm/constant.js +1 -21
  18. package/dist/esm/runtime/index.js +1 -3
  19. package/dist/esm/ssr-runtime/plugin.js +10 -7
  20. package/dist/esm-node/cli/constant.js +4 -0
  21. package/dist/esm-node/cli/index.js +1 -5
  22. package/dist/esm-node/cli/mfRuntimePlugins/inject-node-fetch.js +10 -7
  23. package/dist/esm-node/cli/mfRuntimePlugins/resolve-entry-ipv4.js +38 -40
  24. package/dist/esm-node/cli/ssrPlugin.js +1 -1
  25. package/dist/esm-node/cli/utils.js +3 -6
  26. package/dist/esm-node/cli/utils.spec.js +1 -1
  27. package/dist/esm-node/constant.js +1 -21
  28. package/dist/esm-node/runtime/index.js +1 -3
  29. package/dist/esm-node/ssr-runtime/plugin.js +7 -7
  30. package/dist/types/cli/constant.d.ts +1 -0
  31. package/dist/types/cli/mfRuntimePlugins/inject-node-fetch.d.ts +2 -2
  32. package/dist/types/cli/utils.d.ts +0 -2
  33. package/dist/types/constant.d.ts +0 -10
  34. package/dist/types/runtime/index.d.ts +0 -1
  35. package/dist/types/types/index.d.ts +0 -9
  36. package/package.json +11 -40
  37. package/dist/cjs/cli/dataLoader/ast/constant.js +0 -49
  38. package/dist/cjs/cli/dataLoader/ast/generateRoutes.js +0 -141
  39. package/dist/cjs/cli/dataLoader/generateRouteFile.js +0 -143
  40. package/dist/cjs/cli/dataLoader/patchMFConfig.js +0 -132
  41. package/dist/cjs/cli/dataLoader/plugin.js +0 -194
  42. package/dist/cjs/cli/mfRuntimePlugins/node.js +0 -44
  43. package/dist/cjs/cli/server/dataLoaderPlugin.js +0 -82
  44. package/dist/cjs/cli/server/fetchRemoteFullRoutesMap.js +0 -69
  45. package/dist/cjs/interfaces/route.js +0 -16
  46. package/dist/cjs/runtime/dataLoader/plugin.js +0 -73
  47. package/dist/cjs/runtime/dataLoader/utils.js +0 -89
  48. package/dist/cjs/runtime/utils.js +0 -38
  49. package/dist/cjs/runtime/withMFRouteId.js +0 -31
  50. package/dist/esm/cli/dataLoader/ast/constant.js +0 -18
  51. package/dist/esm/cli/dataLoader/ast/generateRoutes.js +0 -108
  52. package/dist/esm/cli/dataLoader/ast/index.js +0 -4
  53. package/dist/esm/cli/dataLoader/generateRouteFile.js +0 -293
  54. package/dist/esm/cli/dataLoader/patchMFConfig.js +0 -98
  55. package/dist/esm/cli/dataLoader/plugin.js +0 -209
  56. package/dist/esm/cli/mfRuntimePlugins/node.js +0 -16
  57. package/dist/esm/cli/server/dataLoaderPlugin.js +0 -105
  58. package/dist/esm/cli/server/fetchRemoteFullRoutesMap.js +0 -88
  59. package/dist/esm/interfaces/route.js +0 -0
  60. package/dist/esm/runtime/dataLoader/plugin.js +0 -92
  61. package/dist/esm/runtime/dataLoader/utils.js +0 -63
  62. package/dist/esm/runtime/utils.js +0 -13
  63. package/dist/esm/runtime/withMFRouteId.js +0 -7
  64. package/dist/esm-node/cli/dataLoader/ast/constant.js +0 -18
  65. package/dist/esm-node/cli/dataLoader/ast/generateRoutes.js +0 -107
  66. package/dist/esm-node/cli/dataLoader/ast/index.js +0 -4
  67. package/dist/esm-node/cli/dataLoader/generateRouteFile.js +0 -108
  68. package/dist/esm-node/cli/dataLoader/patchMFConfig.js +0 -98
  69. package/dist/esm-node/cli/dataLoader/plugin.js +0 -159
  70. package/dist/esm-node/cli/mfRuntimePlugins/node.js +0 -14
  71. package/dist/esm-node/cli/server/dataLoaderPlugin.js +0 -62
  72. package/dist/esm-node/cli/server/fetchRemoteFullRoutesMap.js +0 -44
  73. package/dist/esm-node/interfaces/route.js +0 -0
  74. package/dist/esm-node/runtime/dataLoader/plugin.js +0 -49
  75. package/dist/esm-node/runtime/dataLoader/utils.js +0 -63
  76. package/dist/esm-node/runtime/utils.js +0 -13
  77. package/dist/esm-node/runtime/withMFRouteId.js +0 -7
  78. package/dist/types/cli/dataLoader/ast/constant.d.ts +0 -8
  79. package/dist/types/cli/dataLoader/ast/generateRoutes.d.ts +0 -5
  80. package/dist/types/cli/dataLoader/ast/index.d.ts +0 -1
  81. package/dist/types/cli/dataLoader/generateRouteFile.d.ts +0 -7
  82. package/dist/types/cli/dataLoader/patchMFConfig.d.ts +0 -10
  83. package/dist/types/cli/dataLoader/plugin.d.ts +0 -6
  84. package/dist/types/cli/mfRuntimePlugins/node.d.ts +0 -3
  85. package/dist/types/cli/server/dataLoaderPlugin.d.ts +0 -10
  86. package/dist/types/cli/server/fetchRemoteFullRoutesMap.d.ts +0 -10
  87. package/dist/types/interfaces/route.d.ts +0 -12
  88. package/dist/types/runtime/dataLoader/plugin.d.ts +0 -2
  89. package/dist/types/runtime/dataLoader/utils.d.ts +0 -19
  90. package/dist/types/runtime/utils.d.ts +0 -2
  91. package/dist/types/runtime/withMFRouteId.d.ts +0 -1
@@ -1,209 +0,0 @@
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 _ts_generator } from "@swc/helpers/_/_ts_generator";
4
- import { transformName2Prefix } from "../../runtime/utils";
5
- import { DEFAULT_ENTRY } from "../../constant";
6
- import { META_NAME } from "../../constant";
7
- import { generateRoutes } from "./ast";
8
- import { generateRouteFile } from "./generateRouteFile";
9
- import { patchMFConfig } from "./patchMFConfig";
10
- import path from "path";
11
- function _transformRuntimeOptions(buildOptions) {
12
- var remotes = buildOptions.remotes || {};
13
- var runtimeRemotes = Object.entries(remotes).map(function(remote) {
14
- var _remote = _sliced_to_array(remote, 2), alias = _remote[0], nameAndEntry = _remote[1];
15
- var _nameAndEntry_split = _sliced_to_array(nameAndEntry.split("@"), 2), name = _nameAndEntry_split[0], entry = _nameAndEntry_split[1];
16
- return {
17
- name,
18
- entry,
19
- alias
20
- };
21
- });
22
- return {
23
- name: buildOptions.name,
24
- remotes: runtimeRemotes
25
- };
26
- }
27
- var moduleFederationDataLoaderPlugin = function(enable, internalOptions, userConfig) {
28
- return {
29
- name: "@modern-js/plugin-module-federation-data-loader",
30
- pre: [
31
- "@modern-js/plugin-module-federation-config"
32
- ],
33
- post: [
34
- "@modern-js/plugin-router",
35
- "@modern-js/plugin-module-federation"
36
- ],
37
- setup: function() {
38
- var _ref = _async_to_generator(function(param) {
39
- var useAppContext, _userConfig_metaName, metaName, _userConfig_serverPlugin, serverPlugin, transformRuntimeOptions, appContext, name, internalDirectory, transformRuntimeFn, partialSSRRemotes, entries, remotePathMap, ssrByRouteIdsMap, serverPluginOptions, csrConfig, _ref2, scanEntries, scanRemotePathMap;
40
- return _ts_generator(this, function(_state) {
41
- switch (_state.label) {
42
- case 0:
43
- useAppContext = param.useAppContext;
44
- if (!enable) {
45
- return [
46
- 2
47
- ];
48
- }
49
- _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;
50
- appContext = useAppContext();
51
- name = internalOptions.csrConfig.name;
52
- internalDirectory = appContext.internalDirectory.replace(META_NAME, metaName || META_NAME);
53
- transformRuntimeFn = transformRuntimeOptions || _transformRuntimeOptions;
54
- partialSSRRemotes = [];
55
- entries = /* @__PURE__ */ new Set();
56
- remotePathMap = {};
57
- ssrByRouteIdsMap = {};
58
- serverPluginOptions = {
59
- runtimeOptions: transformRuntimeFn(internalOptions.csrConfig),
60
- partialSSRRemotes,
61
- ssrByRouteIdsMap
62
- };
63
- csrConfig = internalOptions.csrConfig;
64
- if (!(typeof csrConfig.remotes === "object" && Object.keys(csrConfig.remotes).length))
65
- return [
66
- 3,
67
- 2
68
- ];
69
- return [
70
- 4,
71
- generateRouteFile({
72
- appDirectory: appContext.appDirectory
73
- })
74
- ];
75
- case 1:
76
- _ref2 = _state.sent(), scanEntries = _ref2.entries, scanRemotePathMap = _ref2.remotePathMap;
77
- scanEntries.forEach(function(e) {
78
- return entries.add(e);
79
- });
80
- remotePathMap = scanRemotePathMap;
81
- return [
82
- 3,
83
- 3
84
- ];
85
- case 2:
86
- entries.add(DEFAULT_ENTRY);
87
- _state.label = 3;
88
- case 3:
89
- return [
90
- 2,
91
- {
92
- _internalRuntimePlugins: function(param2) {
93
- var entrypoint = param2.entrypoint, plugins = param2.plugins;
94
- plugins.push({
95
- name: "ssrDataLoader",
96
- path: "@module-federation/modern-js/data-loader",
97
- config: {}
98
- });
99
- return {
100
- entrypoint,
101
- plugins
102
- };
103
- },
104
- _internalServerPlugins: function _internalServerPlugins(param2) {
105
- var plugins = param2.plugins;
106
- plugins.push({
107
- name: serverPlugin,
108
- options: serverPluginOptions
109
- });
110
- return {
111
- plugins
112
- };
113
- },
114
- modifyFileSystemRoutes: function modifyFileSystemRoutes(options) {
115
- return _async_to_generator(function() {
116
- var routes, entrypoint, entryName, prefix, modifyRouteIds;
117
- return _ts_generator(this, function(_state2) {
118
- routes = options.routes, entrypoint = options.entrypoint;
119
- entryName = entrypoint.entryName;
120
- prefix = transformName2Prefix(internalOptions.csrConfig.name);
121
- modifyRouteIds = function(route, pathName) {
122
- var currentPathName = route.path ? path.join(pathName, route.path) : pathName;
123
- if (route.id) {
124
- var _route_children;
125
- var originalId = route.id;
126
- route.originalId = originalId;
127
- var remoteName = remotePathMap[currentPathName];
128
- if (remoteName) {
129
- var remoteIdPrefix = transformName2Prefix(remoteName);
130
- var isLayout = Boolean(route.children);
131
- var newId = "".concat(remoteIdPrefix).concat(isLayout ? "layout" : "page");
132
- ssrByRouteIdsMap[originalId] = newId;
133
- route.id = newId;
134
- if (!partialSSRRemotes.includes(remoteName)) {
135
- partialSSRRemotes.push(remoteName);
136
- }
137
- } else {
138
- route.id = "".concat(prefix).concat(route.id);
139
- }
140
- (_route_children = route.children) === null || _route_children === void 0 ? void 0 : _route_children.forEach(function(r) {
141
- modifyRouteIds(r, currentPathName);
142
- });
143
- }
144
- };
145
- routes.forEach(function(route) {
146
- modifyRouteIds(route, entryName);
147
- });
148
- return [
149
- 2,
150
- options
151
- ];
152
- });
153
- })();
154
- },
155
- config: /* @__PURE__ */ _async_to_generator(function() {
156
- return _ts_generator(this, function(_state2) {
157
- return [
158
- 2,
159
- {
160
- tools: {
161
- // bundlerChain can not keep target order
162
- rspack: function rspack(_config, param2) {
163
- var isServer = param2.isServer;
164
- patchMFConfig({
165
- mfConfig: isServer ? internalOptions.ssrConfig : internalOptions.csrConfig,
166
- metaName,
167
- isServer,
168
- internalDirectory,
169
- entries
170
- });
171
- },
172
- // bundlerChain can not keep target order
173
- webpack: function webpack(_config, param2) {
174
- var isServer = param2.isServer;
175
- patchMFConfig({
176
- mfConfig: isServer ? internalOptions.ssrConfig : internalOptions.csrConfig,
177
- metaName,
178
- isServer,
179
- internalDirectory,
180
- entries
181
- });
182
- }
183
- },
184
- source: {
185
- define: {
186
- MODERN_ROUTER_ID_PREFIX: JSON.stringify(transformName2Prefix(name))
187
- }
188
- }
189
- }
190
- ];
191
- });
192
- })
193
- }
194
- ];
195
- }
196
- });
197
- });
198
- return function(_) {
199
- return _ref.apply(this, arguments);
200
- };
201
- }()
202
- };
203
- };
204
- var plugin_default = moduleFederationDataLoaderPlugin;
205
- export {
206
- plugin_default as default,
207
- generateRoutes,
208
- moduleFederationDataLoaderPlugin
209
- };
@@ -1,16 +0,0 @@
1
- import nodeFetch from "node-fetch";
2
- var injectNodeFetchPlugin = function() {
3
- return {
4
- name: "inject-node-fetch-plugin",
5
- beforeInit: function beforeInit(args) {
6
- if (!globalThis.fetch) {
7
- globalThis.fetch = nodeFetch;
8
- }
9
- return args;
10
- }
11
- };
12
- };
13
- var node_default = injectNodeFetchPlugin;
14
- export {
15
- node_default as default
16
- };
@@ -1,105 +0,0 @@
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 { init } from "@module-federation/enhanced/runtime";
5
- import { isBrowserEnv } from "@module-federation/sdk";
6
- import { fetchRemoteFullRoutesMap, getSSRByRouteIds } from "./fetchRemoteFullRoutesMap";
7
- import { injectRemoteRoutes } from "../../runtime/dataLoader/utils";
8
- import { MF_ROUTES, DEFAULT_ENTRY, MODERN_JS_ROUTE_SERVER_LOADER } from "../../constant";
9
- function dataLoaderPlugin_default(param) {
10
- var runtimeOptions = param.runtimeOptions, partialSSRRemotes = param.partialSSRRemotes, ssrByRouteIdsMap = param.ssrByRouteIdsMap;
11
- return {
12
- name: "MFDataLoaderServerPlugin",
13
- pre: [
14
- "@modern-js/plugin-inject-resource"
15
- ],
16
- setup: function setup(api) {
17
- var remotes = runtimeOptions.remotes, name = runtimeOptions.name;
18
- if (!remotes.length) {
19
- return {};
20
- }
21
- var isHandled = false;
22
- return {
23
- prepare: function prepare() {
24
- var middlewares = api.useAppContext().middlewares;
25
- middlewares.push({
26
- name: "MFDataLoaderServerPlugin",
27
- handler: function() {
28
- var _ref = _async_to_generator(function(c, next) {
29
- var serverManifest, loaderBundles, nestedRoutesJson, _api_useConfigContext_server, instance, remoteFullRoutesMap, originalSSRByRouteIds, remoteSSRByRouteIds, ssrByRouteIds;
30
- return _ts_generator(this, function(_state) {
31
- switch (_state.label) {
32
- case 0:
33
- serverManifest = c.get("serverManifest");
34
- loaderBundles = serverManifest.loaderBundles, nestedRoutesJson = serverManifest.nestedRoutesJson;
35
- if (!isHandled)
36
- return [
37
- 3,
38
- 2
39
- ];
40
- return [
41
- 4,
42
- next()
43
- ];
44
- case 1:
45
- _state.sent();
46
- return [
47
- 3,
48
- 5
49
- ];
50
- case 2:
51
- instance = init({
52
- name,
53
- remotes
54
- });
55
- return [
56
- 4,
57
- fetchRemoteFullRoutesMap({
58
- instance,
59
- remotePath: isBrowserEnv() ? "".concat(DEFAULT_ENTRY, "/").concat(MF_ROUTES) : "".concat(DEFAULT_ENTRY, "/").concat(MODERN_JS_ROUTE_SERVER_LOADER)
60
- })
61
- ];
62
- case 3:
63
- remoteFullRoutesMap = _state.sent();
64
- originalSSRByRouteIds = (_api_useConfigContext_server = api.useConfigContext().server) === null || _api_useConfigContext_server === void 0 ? void 0 : _api_useConfigContext_server.ssrByRouteIds;
65
- if (originalSSRByRouteIds && partialSSRRemotes.length) {
66
- remoteSSRByRouteIds = getSSRByRouteIds(partialSSRRemotes, remoteFullRoutesMap) || [];
67
- ssrByRouteIds = new Set(_to_consumable_array(originalSSRByRouteIds).concat(_to_consumable_array(remoteSSRByRouteIds.map(function(id) {
68
- return ssrByRouteIdsMap[id] || id;
69
- }))));
70
- api.useConfigContext().server.ssrByRouteIds = Array.from(ssrByRouteIds);
71
- }
72
- injectRemoteRoutes(loaderBundles, remoteFullRoutesMap);
73
- injectRemoteRoutes(nestedRoutesJson, remoteFullRoutesMap);
74
- isHandled = true;
75
- return [
76
- 4,
77
- next()
78
- ];
79
- case 4:
80
- _state.sent();
81
- _state.label = 5;
82
- case 5:
83
- return [
84
- 2
85
- ];
86
- }
87
- });
88
- });
89
- return function(c, next) {
90
- return _ref.apply(this, arguments);
91
- };
92
- }(),
93
- before: [
94
- "render"
95
- ]
96
- });
97
- }
98
- };
99
- }
100
- };
101
- }
102
- ;
103
- export {
104
- dataLoaderPlugin_default as default
105
- };
@@ -1,88 +0,0 @@
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
- function fetchRemoteFullRoutesMap(options) {
6
- return _fetchRemoteFullRoutesMap.apply(this, arguments);
7
- }
8
- function _fetchRemoteFullRoutesMap() {
9
- _fetchRemoteFullRoutesMap = _async_to_generator(function(options) {
10
- var instance, remotePath, remotes, remoteRoutesMap;
11
- return _ts_generator(this, function(_state) {
12
- switch (_state.label) {
13
- case 0:
14
- instance = options.instance, remotePath = options.remotePath;
15
- remotes = instance.options.remotes;
16
- remoteRoutesMap = {};
17
- if (!remotes.length) {
18
- return [
19
- 2,
20
- remoteRoutesMap
21
- ];
22
- }
23
- return [
24
- 4,
25
- Promise.all(remotes.map(function() {
26
- var _ref = _async_to_generator(function(remote) {
27
- var remoteId, routes;
28
- return _ts_generator(this, function(_state2) {
29
- switch (_state2.label) {
30
- case 0:
31
- remoteId = "".concat(remote.name, "/").concat(remotePath);
32
- return [
33
- 4,
34
- instance.loadRemote(remoteId)
35
- ];
36
- case 1:
37
- routes = _state2.sent().routes;
38
- remoteRoutesMap[remote.name] = {
39
- routes
40
- };
41
- return [
42
- 2
43
- ];
44
- }
45
- });
46
- });
47
- return function(remote) {
48
- return _ref.apply(this, arguments);
49
- };
50
- }()))
51
- ];
52
- case 1:
53
- _state.sent();
54
- return [
55
- 2,
56
- remoteRoutesMap
57
- ];
58
- }
59
- });
60
- });
61
- return _fetchRemoteFullRoutesMap.apply(this, arguments);
62
- }
63
- function getSSRByRouteIds(partialSSRRemotes, remoteRoutesMap) {
64
- var remoteProviderRouteIds = /* @__PURE__ */ new Set();
65
- var collectIds = function(route) {
66
- remoteProviderRouteIds.add(route.id);
67
- if (route.children) {
68
- route.children.forEach(function(r) {
69
- collectIds(r);
70
- });
71
- }
72
- };
73
- Object.entries(remoteRoutesMap).forEach(function(item) {
74
- var _item = _sliced_to_array(item, 2), remoteName = _item[0], routesObj = _item[1];
75
- if (!partialSSRRemotes.includes(remoteName)) {
76
- return;
77
- }
78
- var routes = routesObj.routes;
79
- routes.forEach(function(route) {
80
- collectIds(route);
81
- });
82
- });
83
- return _to_consumable_array(remoteProviderRouteIds);
84
- }
85
- export {
86
- fetchRemoteFullRoutesMap,
87
- getSSRByRouteIds
88
- };
File without changes
@@ -1,92 +0,0 @@
1
- import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
- import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
- import { getInstance } from "@module-federation/enhanced/runtime";
4
- import { MF_ROUTES, DEFAULT_ENTRY } from "../../constant";
5
- import { injectRemoteRoutes } from "./utils";
6
- var ssrDataLoaderPlugin = function() {
7
- return {
8
- name: "@modern-js/plugin-mf-data-loader",
9
- post: [
10
- "@modern-js/plugin-router"
11
- ],
12
- setup: function() {
13
- var remoteRoutesMap = {};
14
- return {
15
- beforeRender: function beforeRender() {
16
- return _async_to_generator(function() {
17
- var instance;
18
- return _ts_generator(this, function(_state) {
19
- switch (_state.label) {
20
- case 0:
21
- console.log("init");
22
- if (Object.keys(remoteRoutesMap).length) {
23
- return [
24
- 2
25
- ];
26
- }
27
- instance = getInstance();
28
- if (!instance) {
29
- console.log("no instance!");
30
- return [
31
- 2
32
- ];
33
- }
34
- if (!instance.options.remotes.length) {
35
- return [
36
- 2
37
- ];
38
- }
39
- return [
40
- 4,
41
- Promise.all(instance.options.remotes.map(function() {
42
- var _ref = _async_to_generator(function(remote) {
43
- var remoteId, routes;
44
- return _ts_generator(this, function(_state2) {
45
- switch (_state2.label) {
46
- case 0:
47
- remoteId = "".concat(remote.name, "/").concat(DEFAULT_ENTRY, "/").concat(MF_ROUTES);
48
- return [
49
- 4,
50
- instance.loadRemote(remoteId)
51
- ];
52
- case 1:
53
- routes = _state2.sent().routes;
54
- remoteRoutesMap[remote.name] = {
55
- routes
56
- };
57
- return [
58
- 2
59
- ];
60
- }
61
- });
62
- });
63
- return function(remote) {
64
- return _ref.apply(this, arguments);
65
- };
66
- }()))
67
- ];
68
- case 1:
69
- _state.sent();
70
- return [
71
- 2
72
- ];
73
- }
74
- });
75
- })();
76
- },
77
- // runtime plugin not save route , so it needs to inject again when trigger
78
- modifyRoutes: function(routes) {
79
- injectRemoteRoutes({
80
- entry: {
81
- routes
82
- }
83
- }, remoteRoutesMap);
84
- return routes;
85
- }
86
- };
87
- }
88
- };
89
- };
90
- export {
91
- ssrDataLoaderPlugin
92
- };
@@ -1,63 +0,0 @@
1
- import { DEFAULT_LAYOUT } from "../../constant";
2
- import { transformName2Prefix, transformPrefix2Name } from "../utils";
3
- function getRemoteRoutesInfos(route, remoteRoutesMap) {
4
- if (!route.id) {
5
- return;
6
- }
7
- var remoteName = transformPrefix2Name(route.id);
8
- var remoteRouteObj = remoteRoutesMap[remoteName];
9
- if (!remoteRouteObj) {
10
- return;
11
- }
12
- var remoteRoutes = remoteRouteObj.routes[0];
13
- return {
14
- routes: remoteRoutes,
15
- name: remoteName,
16
- pathName: route.path
17
- };
18
- }
19
- function getRemoteLayoutId(remoteName) {
20
- var prefix = transformName2Prefix(remoteName);
21
- return "".concat(prefix).concat(DEFAULT_LAYOUT);
22
- }
23
- function injectRemoteRoutes(initialRoutes, remoteRoutesMap) {
24
- var traverse = function(route) {
25
- var _route_children;
26
- var remoteRoutesInfos = getRemoteRoutesInfos(route, remoteRoutesMap);
27
- if (remoteRoutesInfos) {
28
- var routes = remoteRoutesInfos.routes, pathName = remoteRoutesInfos.pathName;
29
- route.id = routes.id;
30
- route.path = pathName;
31
- if (routes.loader) {
32
- route.loader = routes.loader;
33
- }
34
- if (routes.children) {
35
- route.children = routes.children;
36
- }
37
- route.element = routes.element;
38
- route.Component = routes.Component;
39
- return;
40
- }
41
- (_route_children = route.children) === null || _route_children === void 0 ? void 0 : _route_children.forEach(function(r) {
42
- traverse(r);
43
- });
44
- };
45
- Object.keys(initialRoutes).forEach(function(entryName) {
46
- var routes = initialRoutes[entryName];
47
- if (Array.isArray(routes)) {
48
- routes.forEach(function(route) {
49
- traverse(route);
50
- });
51
- } else {
52
- var _routes_routes;
53
- routes === null || routes === void 0 ? void 0 : (_routes_routes = routes.routes) === null || _routes_routes === void 0 ? void 0 : _routes_routes.forEach(function(r) {
54
- traverse(r);
55
- });
56
- }
57
- });
58
- }
59
- export {
60
- getRemoteLayoutId,
61
- getRemoteRoutesInfos,
62
- injectRemoteRoutes
63
- };
@@ -1,13 +0,0 @@
1
- import { encodeName, decodeName } from "@module-federation/sdk";
2
- var SPLIT_SYMBOL = "@";
3
- function transformName2Prefix(name) {
4
- return "".concat(encodeName(name, "", false)).concat(SPLIT_SYMBOL);
5
- }
6
- function transformPrefix2Name(prefix) {
7
- var realPrefix = prefix.split(SPLIT_SYMBOL)[0];
8
- return decodeName(realPrefix, "", false);
9
- }
10
- export {
11
- transformName2Prefix,
12
- transformPrefix2Name
13
- };
@@ -1,7 +0,0 @@
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
- };
@@ -1,18 +0,0 @@
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
- const LOADER = "loader";
9
- export {
10
- COMPONENT,
11
- ELEMENT,
12
- ID,
13
- IS_ROOT,
14
- LAZY_COMPONENT,
15
- LOADER,
16
- PRIVATE_COMPONENT,
17
- SHOULD_REVALIDATE
18
- };