@module-federation/modern-js 0.0.0-next-20241017102355 → 0.0.0-next-20241018034800

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 (115) hide show
  1. package/dist/cjs/cli/{routes/ast/index.js → constant.js} +6 -6
  2. package/dist/cjs/cli/index.js +2 -7
  3. package/dist/cjs/cli/mfRuntimePlugins/{node-fetch.js → inject-node-fetch.js} +6 -6
  4. package/dist/cjs/cli/mfRuntimePlugins/resolve-entry-ipv4.js +38 -40
  5. package/dist/cjs/{runtime/withMFRouteId.js → cli/mfRuntimePlugins/shared-strategy.js} +23 -11
  6. package/dist/cjs/cli/ssrPlugin.js +2 -5
  7. package/dist/cjs/cli/utils.js +6 -11
  8. package/dist/cjs/cli/utils.spec.js +6 -5
  9. package/dist/cjs/constant.js +2 -35
  10. package/dist/cjs/runtime/index.js +1 -4
  11. package/dist/cjs/ssr-runtime/plugin.js +8 -7
  12. package/dist/esm/cli/constant.js +4 -0
  13. package/dist/esm/cli/index.js +2 -7
  14. package/dist/esm/cli/mfRuntimePlugins/{node-fetch.js → inject-node-fetch.js} +3 -3
  15. package/dist/esm/cli/mfRuntimePlugins/shared-strategy.js +25 -0
  16. package/dist/esm/cli/ssrPlugin.js +3 -6
  17. package/dist/esm/cli/utils.js +5 -9
  18. package/dist/esm/cli/utils.spec.js +6 -5
  19. package/dist/esm/constant.js +1 -23
  20. package/dist/esm/runtime/index.js +1 -3
  21. package/dist/esm/ssr-runtime/plugin.js +11 -8
  22. package/dist/esm-node/cli/constant.js +4 -0
  23. package/dist/esm-node/cli/index.js +2 -7
  24. package/dist/esm-node/cli/mfRuntimePlugins/{node-fetch.js → inject-node-fetch.js} +3 -3
  25. package/dist/esm-node/cli/mfRuntimePlugins/resolve-entry-ipv4.js +38 -40
  26. package/dist/esm-node/cli/mfRuntimePlugins/shared-strategy.js +23 -0
  27. package/dist/esm-node/cli/ssrPlugin.js +2 -5
  28. package/dist/esm-node/cli/utils.js +5 -9
  29. package/dist/esm-node/cli/utils.spec.js +6 -5
  30. package/dist/esm-node/constant.js +1 -23
  31. package/dist/esm-node/runtime/index.js +1 -3
  32. package/dist/esm-node/ssr-runtime/plugin.js +8 -7
  33. package/dist/types/cli/constant.d.ts +1 -0
  34. package/dist/types/cli/mfRuntimePlugins/shared-strategy.d.ts +3 -0
  35. package/dist/types/cli/utils.d.ts +0 -2
  36. package/dist/types/constant.d.ts +0 -11
  37. package/dist/types/runtime/index.d.ts +0 -1
  38. package/dist/types/ssr-runtime/plugin.d.ts +1 -3
  39. package/dist/types/types/index.d.ts +1 -3
  40. package/package.json +12 -49
  41. package/dist/cjs/cli/mfRuntimePlugins/node.js +0 -41
  42. package/dist/cjs/cli/routes/ast/constant.js +0 -49
  43. package/dist/cjs/cli/routes/ast/generateRoutes.js +0 -143
  44. package/dist/cjs/cli/routes/clearMFCache.js +0 -57
  45. package/dist/cjs/cli/routes/exportRoutePlugin.js +0 -77
  46. package/dist/cjs/cli/routes/importRoutesPlugin.js +0 -120
  47. package/dist/cjs/cli/routes/plugin.js +0 -157
  48. package/dist/cjs/cli/routes/traverseRouteFiles.js +0 -148
  49. package/dist/cjs/cli/routes/utils.js +0 -168
  50. package/dist/cjs/cli/server/fetchRemoteFullRoutesMap.js +0 -72
  51. package/dist/cjs/cli/server/fetchRoutePlugin.js +0 -81
  52. package/dist/cjs/interfaces/route.js +0 -16
  53. package/dist/cjs/runtime/routes/plugin-inject-assets.js +0 -92
  54. package/dist/cjs/runtime/routes/plugin.js +0 -75
  55. package/dist/cjs/runtime/routes/utils.js +0 -115
  56. package/dist/cjs/types/modern.js +0 -16
  57. package/dist/cjs/types/routes.js +0 -16
  58. package/dist/esm/cli/mfRuntimePlugins/node.js +0 -13
  59. package/dist/esm/cli/routes/ast/constant.js +0 -18
  60. package/dist/esm/cli/routes/ast/generateRoutes.js +0 -110
  61. package/dist/esm/cli/routes/ast/index.js +0 -4
  62. package/dist/esm/cli/routes/clearMFCache.js +0 -34
  63. package/dist/esm/cli/routes/exportRoutePlugin.js +0 -79
  64. package/dist/esm/cli/routes/importRoutesPlugin.js +0 -122
  65. package/dist/esm/cli/routes/plugin.js +0 -266
  66. package/dist/esm/cli/routes/traverseRouteFiles.js +0 -313
  67. package/dist/esm/cli/routes/utils.js +0 -130
  68. package/dist/esm/cli/server/fetchRemoteFullRoutesMap.js +0 -93
  69. package/dist/esm/cli/server/fetchRoutePlugin.js +0 -104
  70. package/dist/esm/interfaces/route.js +0 -0
  71. package/dist/esm/runtime/routes/plugin-inject-assets.js +0 -71
  72. package/dist/esm/runtime/routes/plugin.js +0 -97
  73. package/dist/esm/runtime/routes/utils.js +0 -86
  74. package/dist/esm/runtime/withMFRouteId.js +0 -7
  75. package/dist/esm/types/modern.js +0 -0
  76. package/dist/esm/types/routes.js +0 -0
  77. package/dist/esm-node/cli/mfRuntimePlugins/node.js +0 -11
  78. package/dist/esm-node/cli/routes/ast/constant.js +0 -18
  79. package/dist/esm-node/cli/routes/ast/generateRoutes.js +0 -109
  80. package/dist/esm-node/cli/routes/ast/index.js +0 -4
  81. package/dist/esm-node/cli/routes/clearMFCache.js +0 -33
  82. package/dist/esm-node/cli/routes/exportRoutePlugin.js +0 -53
  83. package/dist/esm-node/cli/routes/importRoutesPlugin.js +0 -96
  84. package/dist/esm-node/cli/routes/plugin.js +0 -123
  85. package/dist/esm-node/cli/routes/traverseRouteFiles.js +0 -113
  86. package/dist/esm-node/cli/routes/utils.js +0 -133
  87. package/dist/esm-node/cli/server/fetchRemoteFullRoutesMap.js +0 -47
  88. package/dist/esm-node/cli/server/fetchRoutePlugin.js +0 -61
  89. package/dist/esm-node/interfaces/route.js +0 -0
  90. package/dist/esm-node/runtime/routes/plugin-inject-assets.js +0 -68
  91. package/dist/esm-node/runtime/routes/plugin.js +0 -51
  92. package/dist/esm-node/runtime/routes/utils.js +0 -86
  93. package/dist/esm-node/runtime/withMFRouteId.js +0 -7
  94. package/dist/esm-node/types/modern.js +0 -0
  95. package/dist/esm-node/types/routes.js +0 -0
  96. package/dist/types/cli/mfRuntimePlugins/node.d.ts +0 -3
  97. package/dist/types/cli/routes/ast/constant.d.ts +0 -8
  98. package/dist/types/cli/routes/ast/generateRoutes.d.ts +0 -5
  99. package/dist/types/cli/routes/ast/index.d.ts +0 -1
  100. package/dist/types/cli/routes/clearMFCache.d.ts +0 -1
  101. package/dist/types/cli/routes/exportRoutePlugin.d.ts +0 -4
  102. package/dist/types/cli/routes/importRoutesPlugin.d.ts +0 -4
  103. package/dist/types/cli/routes/plugin.d.ts +0 -4
  104. package/dist/types/cli/routes/traverseRouteFiles.d.ts +0 -11
  105. package/dist/types/cli/routes/utils.d.ts +0 -11
  106. package/dist/types/cli/server/fetchRemoteFullRoutesMap.d.ts +0 -11
  107. package/dist/types/cli/server/fetchRoutePlugin.d.ts +0 -10
  108. package/dist/types/interfaces/route.d.ts +0 -12
  109. package/dist/types/runtime/routes/plugin-inject-assets.d.ts +0 -4
  110. package/dist/types/runtime/routes/plugin.d.ts +0 -5
  111. package/dist/types/runtime/routes/utils.d.ts +0 -22
  112. package/dist/types/runtime/withMFRouteId.d.ts +0 -1
  113. package/dist/types/types/modern.d.ts +0 -12
  114. package/dist/types/types/routes.d.ts +0 -19
  115. /package/dist/types/cli/mfRuntimePlugins/{node-fetch.d.ts → inject-node-fetch.d.ts} +0 -0
@@ -1,130 +0,0 @@
1
- import { _ as _define_property } from "@swc/helpers/_/_define_property";
2
- import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
3
- import path from "path";
4
- import { fs } from "@modern-js/utils";
5
- import { MODERN_JS_ROUTE_SERVER_LOADER } from "../../constant";
6
- import { MF_ROUTES, MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME } from "../../constant";
7
- import { generateRoutes } from "./ast";
8
- function generateExtraExposeFiles(options) {
9
- var internalDirectory = options.internalDirectory, mfConfig = options.mfConfig, isServer = options.isServer, entries = options.entries;
10
- var entryMap = {};
11
- var outputDir = path.resolve(process.cwd(), "node_modules/.federation/data-loader");
12
- fs.ensureDirSync(outputDir);
13
- var addSuffix = function(fileName) {
14
- var ext = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : ".jsx";
15
- if (!isServer) {
16
- return "".concat(fileName).concat(ext);
17
- }
18
- return "".concat(fileName, ".server").concat(ext);
19
- };
20
- var generateEntryRoutes = function(entry) {
21
- var outputEntryDir = path.resolve(outputDir, entry);
22
- fs.ensureDirSync(outputEntryDir);
23
- var sourceDir = path.resolve(internalDirectory, entry);
24
- var routesFilePath = path.resolve(sourceDir, addSuffix(MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME, ".js"));
25
- var routesFileContent = fs.readFileSync(routesFilePath, "utf-8");
26
- var outputFullRoutesPath = path.resolve(outputEntryDir, addSuffix(MF_ROUTES));
27
- generateRoutes({
28
- sourceCode: routesFileContent,
29
- filePath: outputFullRoutesPath
30
- });
31
- var routeServerLoaderPath = path.resolve(sourceDir, "".concat(MODERN_JS_ROUTE_SERVER_LOADER, ".js"));
32
- var outputRouteServerLoaderPath = path.resolve(outputEntryDir, "".concat(MODERN_JS_ROUTE_SERVER_LOADER, ".js"));
33
- var clientRouteServerLoaderPath = outputRouteServerLoaderPath.replace(MODERN_JS_ROUTE_SERVER_LOADER, "".concat(MODERN_JS_ROUTE_SERVER_LOADER, "-client"));
34
- if (isServer) {
35
- var routeServerLoaderContent = fs.readFileSync(routeServerLoaderPath, "utf-8");
36
- generateRoutes({
37
- sourceCode: routeServerLoaderContent,
38
- filePath: outputRouteServerLoaderPath
39
- });
40
- } else {
41
- fs.writeFileSync(clientRouteServerLoaderPath, "export const routes = []");
42
- }
43
- entryMap[entry] = {
44
- routesPath: outputFullRoutesPath,
45
- routeServerLoaderPath: outputRouteServerLoaderPath,
46
- clientRouteServerLoaderPath
47
- };
48
- };
49
- entries.forEach(function(entry) {
50
- generateEntryRoutes(entry);
51
- });
52
- return {
53
- entryMap
54
- };
55
- }
56
- function addExpose(options) {
57
- var mfConfig = options.mfConfig, isServer = options.isServer;
58
- var entryMap = generateExtraExposeFiles(options).entryMap;
59
- var addExposeByEntry = function(entry, routesPath, routeServerLoaderPath, clientRouteServerLoaderPath) {
60
- if (!mfConfig.exposes) {
61
- mfConfig.exposes = {};
62
- }
63
- var routesKey = "./".concat(entry, "/").concat(MF_ROUTES);
64
- if (!mfConfig.exposes[routesKey]) {
65
- mfConfig.exposes[routesKey] = routesPath;
66
- }
67
- var routeServerLoaderKey = "./".concat(entry, "/").concat(MODERN_JS_ROUTE_SERVER_LOADER);
68
- if (!mfConfig.exposes[routeServerLoaderKey]) {
69
- if (isServer) {
70
- mfConfig.exposes[routeServerLoaderKey] = routeServerLoaderPath;
71
- } else {
72
- mfConfig.exposes[routeServerLoaderKey] = clientRouteServerLoaderPath;
73
- }
74
- }
75
- };
76
- Object.keys(entryMap).forEach(function(entry) {
77
- var _entryMap_entry = entryMap[entry], routesPath = _entryMap_entry.routesPath, routeServerLoaderPath = _entryMap_entry.routeServerLoaderPath, clientRouteServerLoaderPath = _entryMap_entry.clientRouteServerLoaderPath;
78
- addExposeByEntry(entry, routesPath, routeServerLoaderPath, clientRouteServerLoaderPath);
79
- });
80
- }
81
- function addShared(options) {
82
- var mfConfig = options.mfConfig;
83
- var styledComponents = "styled-components";
84
- var reactRouterDom = "react-router-dom";
85
- var reactRouterDomServer = "react-router-dom/server";
86
- if (!mfConfig.shared) {
87
- var _obj;
88
- mfConfig.shared = (_obj = {}, _define_property(_obj, reactRouterDom, {
89
- singleton: true
90
- }), _define_property(_obj, reactRouterDomServer, {
91
- singleton: true
92
- }), _define_property(_obj, styledComponents, {
93
- singleton: true
94
- }), _obj);
95
- } else {
96
- if (!Array.isArray(mfConfig.shared)) {
97
- mfConfig.shared[reactRouterDom] = {
98
- singleton: true
99
- };
100
- mfConfig.shared[reactRouterDomServer] = {
101
- singleton: true
102
- };
103
- mfConfig.shared[styledComponents] = {
104
- singleton: true
105
- };
106
- } else {
107
- mfConfig.shared = mfConfig.shared.reduce(function(sum, cur) {
108
- if (typeof cur === "string") {
109
- sum[cur] = {};
110
- } else {
111
- sum = _object_spread({}, sum, cur);
112
- }
113
- return sum;
114
- }, {});
115
- mfConfig.shared[reactRouterDom] = {
116
- singleton: true
117
- };
118
- mfConfig.shared[reactRouterDomServer] = {
119
- singleton: true
120
- };
121
- mfConfig.shared[styledComponents] = {
122
- singleton: true
123
- };
124
- }
125
- }
126
- }
127
- export {
128
- addExpose,
129
- addShared
130
- };
@@ -1,93 +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, dataLoaderRemotes, remotes, remoteRoutesMap;
11
- return _ts_generator(this, function(_state) {
12
- switch (_state.label) {
13
- case 0:
14
- instance = options.instance, remotePath = options.remotePath, dataLoaderRemotes = options.dataLoaderRemotes;
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
- if (!dataLoaderRemotes.includes(remote.name)) {
32
- return [
33
- 2
34
- ];
35
- }
36
- remoteId = "".concat(remote.name, "/").concat(remotePath);
37
- return [
38
- 4,
39
- instance.loadRemote(remoteId)
40
- ];
41
- case 1:
42
- routes = _state2.sent().routes;
43
- remoteRoutesMap[remote.name] = {
44
- routes
45
- };
46
- return [
47
- 2
48
- ];
49
- }
50
- });
51
- });
52
- return function(remote) {
53
- return _ref.apply(this, arguments);
54
- };
55
- }()))
56
- ];
57
- case 1:
58
- _state.sent();
59
- return [
60
- 2,
61
- remoteRoutesMap
62
- ];
63
- }
64
- });
65
- });
66
- return _fetchRemoteFullRoutesMap.apply(this, arguments);
67
- }
68
- function getSSRByRouteIds(dataLoaderRemotes, remoteRoutesMap) {
69
- var remoteProviderRouteIds = /* @__PURE__ */ new Set();
70
- var collectIds = function(route) {
71
- remoteProviderRouteIds.add(route.id);
72
- if (route.children) {
73
- route.children.forEach(function(r) {
74
- collectIds(r);
75
- });
76
- }
77
- };
78
- Object.entries(remoteRoutesMap).forEach(function(item) {
79
- var _item = _sliced_to_array(item, 2), remoteName = _item[0], routesObj = _item[1];
80
- if (!dataLoaderRemotes.includes(remoteName)) {
81
- return;
82
- }
83
- var routes = routesObj.routes;
84
- routes.forEach(function(route) {
85
- collectIds(route);
86
- });
87
- });
88
- return _to_consumable_array(remoteProviderRouteIds);
89
- }
90
- export {
91
- fetchRemoteFullRoutesMap,
92
- getSSRByRouteIds
93
- };
@@ -1,104 +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/routes/utils";
8
- import { MF_ROUTES, DEFAULT_ENTRY, MODERN_JS_ROUTE_SERVER_LOADER } from "../../constant";
9
- function fetchRoutePlugin_default(param) {
10
- var runtimeOptions = param.runtimeOptions, dataLoaderRemotes = param.dataLoaderRemotes, ssrByRouteIdsMap = param.ssrByRouteIdsMap;
11
- return {
12
- name: "@module-federation/modern-js-fetch-route",
13
- pre: [
14
- "@modern-js/plugin-inject-resource"
15
- ],
16
- setup: function setup(api) {
17
- var remotes = runtimeOptions.remotes, name = runtimeOptions.name;
18
- var isHandled = false;
19
- return {
20
- prepare: function prepare() {
21
- var middlewares = api.useAppContext().middlewares;
22
- middlewares.push({
23
- name: "MFPatchRouteMiddleWare",
24
- handler: function() {
25
- var _ref = _async_to_generator(function(c, next) {
26
- var serverManifest, loaderBundles, nestedRoutesJson, _api_useConfigContext_server, instance, remoteFullRoutesMap, originalSSRByRouteIds, remoteSSRByRouteIds, ssrByRouteIds;
27
- return _ts_generator(this, function(_state) {
28
- switch (_state.label) {
29
- case 0:
30
- serverManifest = c.get("serverManifest");
31
- loaderBundles = serverManifest.loaderBundles, nestedRoutesJson = serverManifest.nestedRoutesJson;
32
- if (!(isHandled && !globalThis.FORCE_MF_REFRESH))
33
- return [
34
- 3,
35
- 2
36
- ];
37
- return [
38
- 4,
39
- next()
40
- ];
41
- case 1:
42
- _state.sent();
43
- return [
44
- 3,
45
- 5
46
- ];
47
- case 2:
48
- instance = init({
49
- name,
50
- remotes
51
- });
52
- return [
53
- 4,
54
- fetchRemoteFullRoutesMap({
55
- instance,
56
- remotePath: isBrowserEnv() ? "".concat(DEFAULT_ENTRY, "/").concat(MF_ROUTES) : "".concat(DEFAULT_ENTRY, "/").concat(MODERN_JS_ROUTE_SERVER_LOADER),
57
- dataLoaderRemotes
58
- })
59
- ];
60
- case 3:
61
- remoteFullRoutesMap = _state.sent();
62
- originalSSRByRouteIds = (_api_useConfigContext_server = api.useConfigContext().server) === null || _api_useConfigContext_server === void 0 ? void 0 : _api_useConfigContext_server.ssrByRouteIds;
63
- if (originalSSRByRouteIds && dataLoaderRemotes.length) {
64
- remoteSSRByRouteIds = getSSRByRouteIds(dataLoaderRemotes, remoteFullRoutesMap) || [];
65
- ssrByRouteIds = new Set(_to_consumable_array(originalSSRByRouteIds).concat(_to_consumable_array(remoteSSRByRouteIds.map(function(id) {
66
- return ssrByRouteIdsMap[id] || id;
67
- }))));
68
- api.useConfigContext().server.ssrByRouteIds = Array.from(ssrByRouteIds);
69
- }
70
- injectRemoteRoutes(loaderBundles, remoteFullRoutesMap);
71
- injectRemoteRoutes(nestedRoutesJson, remoteFullRoutesMap);
72
- isHandled = true;
73
- globalThis.FORCE_MF_REFRESH = false;
74
- return [
75
- 4,
76
- next()
77
- ];
78
- case 4:
79
- _state.sent();
80
- _state.label = 5;
81
- case 5:
82
- return [
83
- 2
84
- ];
85
- }
86
- });
87
- });
88
- return function(c, next) {
89
- return _ref.apply(this, arguments);
90
- };
91
- }(),
92
- before: [
93
- "render"
94
- ]
95
- });
96
- }
97
- };
98
- }
99
- };
100
- }
101
- ;
102
- export {
103
- fetchRoutePlugin_default as default
104
- };
File without changes
@@ -1,71 +0,0 @@
1
- import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
2
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
- import { useContext } from "react";
4
- import { getInstance } from "@module-federation/enhanced/runtime";
5
- import { collectSSRAssets } from "../createRemoteSSRComponent";
6
- import { RuntimeReactContext } from "@meta/runtime";
7
- import { decodeId, getRemoteId } from "./utils";
8
- function traverseRoutes(routes, remoteNames) {
9
- routes.forEach(function(route) {
10
- route.id && remoteNames.add(decodeId(route.id));
11
- route.children && traverseRoutes(route.children, remoteNames);
12
- });
13
- }
14
- var ssrDataLoaderInjectAssetsPlugin = function(param) {
15
- var metaName = param.metaName;
16
- return {
17
- name: "@modern-js/plugin-mf-routes-inject-assets",
18
- pre: [
19
- "@modern-js/plugin-mf-routes"
20
- ],
21
- post: [
22
- "@module-federation/modern-js",
23
- "@".concat(metaName, "/plugin-router")
24
- ],
25
- setup: function() {
26
- return {
27
- wrapRoot: function wrapRoot() {
28
- var AppWrapper = function(props) {
29
- var instance = getInstance();
30
- if (!instance || !instance.options.remotes.length) {
31
- return /* @__PURE__ */ _jsx(_Fragment, {
32
- children: props.children
33
- });
34
- }
35
- var context = useContext(RuntimeReactContext);
36
- var remotes = instance.options.remotes;
37
- var remoteNames = /* @__PURE__ */ new Set();
38
- traverseRoutes(context.routes, remoteNames);
39
- var remoteIds = _to_consumable_array(remoteNames).reduce(function(sum, cur) {
40
- var matchRemote = remotes.find(function(r) {
41
- return r.name === cur;
42
- });
43
- if (matchRemote) {
44
- sum.add(getRemoteId(cur));
45
- }
46
- return sum;
47
- }, /* @__PURE__ */ new Set());
48
- var assets = [];
49
- remoteIds.forEach(function(remoteId) {
50
- var _assets;
51
- (_assets = assets).push.apply(_assets, _to_consumable_array(collectSSRAssets({
52
- id: remoteId,
53
- injectScript: false
54
- })));
55
- });
56
- return /* @__PURE__ */ _jsxs(_Fragment, {
57
- children: [
58
- assets,
59
- props.children
60
- ]
61
- });
62
- };
63
- return AppWrapper;
64
- }
65
- };
66
- }
67
- };
68
- };
69
- export {
70
- ssrDataLoaderInjectAssetsPlugin
71
- };
@@ -1,97 +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(param) {
7
- var metaName = param.metaName, dataLoaderRemotes = param.dataLoaderRemotes;
8
- return {
9
- name: "@modern-js/plugin-mf-routes",
10
- post: [
11
- "@".concat(metaName, "/plugin-router"),
12
- "@module-federation/modern-js"
13
- ],
14
- setup: function() {
15
- var remoteRoutesMap = {};
16
- return {
17
- beforeRender: function beforeRender() {
18
- return _async_to_generator(function() {
19
- var instance;
20
- return _ts_generator(this, function(_state) {
21
- switch (_state.label) {
22
- case 0:
23
- if (Object.keys(remoteRoutesMap).length) {
24
- return [
25
- 2
26
- ];
27
- }
28
- instance = getInstance();
29
- if (!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
- if (!dataLoaderRemotes.includes(remote.name)) {
48
- return [
49
- 2
50
- ];
51
- }
52
- remoteId = "".concat(remote.name, "/").concat(DEFAULT_ENTRY, "/").concat(MF_ROUTES);
53
- return [
54
- 4,
55
- instance.loadRemote(remoteId)
56
- ];
57
- case 1:
58
- routes = _state2.sent().routes;
59
- remoteRoutesMap[remote.name] = {
60
- routes
61
- };
62
- return [
63
- 2
64
- ];
65
- }
66
- });
67
- });
68
- return function(remote) {
69
- return _ref.apply(this, arguments);
70
- };
71
- }()))
72
- ];
73
- case 1:
74
- _state.sent();
75
- return [
76
- 2
77
- ];
78
- }
79
- });
80
- })();
81
- },
82
- // runtime plugin not save route , so it needs to inject again when trigger
83
- modifyRoutes: function(routes) {
84
- injectRemoteRoutes({
85
- entry: {
86
- routes
87
- }
88
- }, remoteRoutesMap);
89
- return routes;
90
- }
91
- };
92
- }
93
- };
94
- };
95
- export {
96
- ssrDataLoaderPlugin
97
- };
@@ -1,86 +0,0 @@
1
- import { encodeName, decodeName } from "@module-federation/sdk";
2
- import { DEFAULT_ENTRY, DEFAULT_LAYOUT, MF_ROUTES } from "../../constant";
3
- var SPLIT_SYMBOL = "@";
4
- function transformName2Prefix(name) {
5
- return "".concat(encodeName(name, "", false)).concat(SPLIT_SYMBOL);
6
- }
7
- function decodeId(prefix) {
8
- var realPrefix = prefix.split(SPLIT_SYMBOL)[0];
9
- return decodeName(realPrefix, "", false);
10
- }
11
- function getRemoteRoutesInfos(route, remoteRoutesMap) {
12
- if (!route.id) {
13
- return;
14
- }
15
- var remoteName = decodeId(route.id);
16
- var remoteRouteObj = remoteRoutesMap[remoteName];
17
- if (!remoteRouteObj) {
18
- return;
19
- }
20
- var remoteRoutes = remoteRouteObj.routes[0];
21
- return {
22
- routes: remoteRoutes,
23
- name: remoteName,
24
- pathName: route.path
25
- };
26
- }
27
- function getRemoteLayoutId(remoteName) {
28
- var prefix = transformName2Prefix(remoteName);
29
- return "".concat(prefix).concat(DEFAULT_LAYOUT);
30
- }
31
- function getRemoteId(remoteName) {
32
- return "".concat(remoteName, "/").concat(DEFAULT_ENTRY, "/").concat(MF_ROUTES);
33
- }
34
- function injectRemoteRoutes(initialRoutes, remoteRoutesMap) {
35
- var traverse = function(route) {
36
- var _route_children;
37
- var remoteRoutesInfos = getRemoteRoutesInfos(route, remoteRoutesMap);
38
- if (remoteRoutesInfos) {
39
- var routes = remoteRoutesInfos.routes, pathName = remoteRoutesInfos.pathName;
40
- route.id = routes.id;
41
- route.path = pathName;
42
- if (routes.loader) {
43
- route.loader = routes.loader;
44
- }
45
- if (routes.children) {
46
- route.children = routes.children;
47
- }
48
- if (routes.Component) {
49
- route.Component = routes.Component;
50
- if (route.element) {
51
- delete route.element;
52
- }
53
- } else if (routes.element) {
54
- route.element = routes.element;
55
- if (route.Component) {
56
- delete route.Component;
57
- }
58
- }
59
- return;
60
- }
61
- (_route_children = route.children) === null || _route_children === void 0 ? void 0 : _route_children.forEach(function(r) {
62
- traverse(r);
63
- });
64
- };
65
- Object.keys(initialRoutes).forEach(function(entryName) {
66
- var routes = initialRoutes[entryName];
67
- if (Array.isArray(routes)) {
68
- routes.forEach(function(route) {
69
- traverse(route);
70
- });
71
- } else {
72
- var _routes_routes;
73
- routes === null || routes === void 0 ? void 0 : (_routes_routes = routes.routes) === null || _routes_routes === void 0 ? void 0 : _routes_routes.forEach(function(r) {
74
- traverse(r);
75
- });
76
- }
77
- });
78
- }
79
- export {
80
- decodeId,
81
- getRemoteId,
82
- getRemoteLayoutId,
83
- getRemoteRoutesInfos,
84
- injectRemoteRoutes,
85
- transformName2Prefix
86
- };
@@ -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
- };
File without changes
File without changes
@@ -1,11 +0,0 @@
1
- import nodeRuntimePlugin from "@module-federation/node/runtimePlugin";
2
- const isContainer = typeof __filename === "string" ? __filename.includes("remote") ? true : false : false;
3
- const pluginName = `node-plugin-${isContainer}`;
4
- const nodePlugin = () => ({
5
- name: pluginName,
6
- beforeInit: nodeRuntimePlugin().beforeInit
7
- });
8
- var node_default = nodePlugin;
9
- export {
10
- node_default as default
11
- };
@@ -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
- };