@module-federation/modern-js 0.0.0-next-20241106033302 → 0.0.0-next-20241106063644

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/index.js +7 -2
  2. package/dist/cjs/cli/mfRuntimePlugins/{inject-node-fetch.js → node-fetch.js} +6 -6
  3. package/dist/cjs/cli/mfRuntimePlugins/node.js +41 -0
  4. package/dist/cjs/cli/mfRuntimePlugins/resolve-entry-ipv4.js +40 -38
  5. package/dist/cjs/cli/routes/ast/constant.js +49 -0
  6. package/dist/cjs/cli/routes/ast/generateRoutes.js +143 -0
  7. package/dist/cjs/cli/{constant.js → routes/ast/index.js} +6 -6
  8. package/dist/cjs/cli/routes/clearMFCache.js +57 -0
  9. package/dist/cjs/cli/routes/exportRoutePlugin.js +77 -0
  10. package/dist/cjs/cli/routes/importRoutesPlugin.js +120 -0
  11. package/dist/cjs/cli/routes/plugin.js +157 -0
  12. package/dist/cjs/cli/routes/traverseRouteFiles.js +148 -0
  13. package/dist/cjs/cli/routes/utils.js +168 -0
  14. package/dist/cjs/cli/server/fetchRemoteFullRoutesMap.js +72 -0
  15. package/dist/cjs/cli/server/fetchRoutePlugin.js +82 -0
  16. package/dist/cjs/cli/ssrPlugin.js +5 -2
  17. package/dist/cjs/cli/utils.js +11 -6
  18. package/dist/cjs/cli/utils.spec.js +5 -6
  19. package/dist/cjs/constant.js +35 -2
  20. package/dist/cjs/interfaces/route.js +16 -0
  21. package/dist/cjs/runtime/index.js +4 -1
  22. package/dist/cjs/runtime/routes/plugin-inject-assets.js +92 -0
  23. package/dist/cjs/runtime/routes/plugin.js +75 -0
  24. package/dist/cjs/runtime/routes/utils.js +115 -0
  25. package/dist/cjs/{cli/mfRuntimePlugins/shared-strategy.js → runtime/withMFRouteId.js} +11 -23
  26. package/dist/cjs/ssr-runtime/plugin.js +7 -8
  27. package/dist/cjs/types/modern.js +16 -0
  28. package/dist/cjs/types/routes.js +16 -0
  29. package/dist/esm/cli/index.js +7 -2
  30. package/dist/esm/cli/mfRuntimePlugins/{inject-node-fetch.js → node-fetch.js} +3 -3
  31. package/dist/esm/cli/mfRuntimePlugins/node.js +13 -0
  32. package/dist/esm/cli/routes/ast/constant.js +18 -0
  33. package/dist/esm/cli/routes/ast/generateRoutes.js +110 -0
  34. package/dist/esm/cli/routes/ast/index.js +4 -0
  35. package/dist/esm/cli/routes/clearMFCache.js +34 -0
  36. package/dist/esm/cli/routes/exportRoutePlugin.js +79 -0
  37. package/dist/esm/cli/routes/importRoutesPlugin.js +122 -0
  38. package/dist/esm/cli/routes/plugin.js +266 -0
  39. package/dist/esm/cli/routes/traverseRouteFiles.js +313 -0
  40. package/dist/esm/cli/routes/utils.js +130 -0
  41. package/dist/esm/cli/server/fetchRemoteFullRoutesMap.js +93 -0
  42. package/dist/esm/cli/server/fetchRoutePlugin.js +105 -0
  43. package/dist/esm/cli/ssrPlugin.js +6 -3
  44. package/dist/esm/cli/utils.js +9 -5
  45. package/dist/esm/cli/utils.spec.js +5 -6
  46. package/dist/esm/constant.js +23 -1
  47. package/dist/esm/interfaces/route.js +0 -0
  48. package/dist/esm/runtime/index.js +3 -1
  49. package/dist/esm/runtime/routes/plugin-inject-assets.js +71 -0
  50. package/dist/esm/runtime/routes/plugin.js +97 -0
  51. package/dist/esm/runtime/routes/utils.js +86 -0
  52. package/dist/esm/runtime/withMFRouteId.js +7 -0
  53. package/dist/esm/ssr-runtime/plugin.js +8 -11
  54. package/dist/esm/types/modern.js +0 -0
  55. package/dist/esm/types/routes.js +0 -0
  56. package/dist/esm-node/cli/index.js +7 -2
  57. package/dist/esm-node/cli/mfRuntimePlugins/{inject-node-fetch.js → node-fetch.js} +3 -3
  58. package/dist/esm-node/cli/mfRuntimePlugins/node.js +11 -0
  59. package/dist/esm-node/cli/mfRuntimePlugins/resolve-entry-ipv4.js +40 -38
  60. package/dist/esm-node/cli/routes/ast/constant.js +18 -0
  61. package/dist/esm-node/cli/routes/ast/generateRoutes.js +109 -0
  62. package/dist/esm-node/cli/routes/ast/index.js +4 -0
  63. package/dist/esm-node/cli/routes/clearMFCache.js +33 -0
  64. package/dist/esm-node/cli/routes/exportRoutePlugin.js +53 -0
  65. package/dist/esm-node/cli/routes/importRoutesPlugin.js +96 -0
  66. package/dist/esm-node/cli/routes/plugin.js +123 -0
  67. package/dist/esm-node/cli/routes/traverseRouteFiles.js +113 -0
  68. package/dist/esm-node/cli/routes/utils.js +133 -0
  69. package/dist/esm-node/cli/server/fetchRemoteFullRoutesMap.js +47 -0
  70. package/dist/esm-node/cli/server/fetchRoutePlugin.js +62 -0
  71. package/dist/esm-node/cli/ssrPlugin.js +5 -2
  72. package/dist/esm-node/cli/utils.js +9 -5
  73. package/dist/esm-node/cli/utils.spec.js +5 -6
  74. package/dist/esm-node/constant.js +23 -1
  75. package/dist/esm-node/interfaces/route.js +0 -0
  76. package/dist/esm-node/runtime/index.js +3 -1
  77. package/dist/esm-node/runtime/routes/plugin-inject-assets.js +68 -0
  78. package/dist/esm-node/runtime/routes/plugin.js +51 -0
  79. package/dist/esm-node/runtime/routes/utils.js +86 -0
  80. package/dist/esm-node/runtime/withMFRouteId.js +7 -0
  81. package/dist/esm-node/ssr-runtime/plugin.js +7 -8
  82. package/dist/esm-node/types/modern.js +0 -0
  83. package/dist/esm-node/types/routes.js +0 -0
  84. package/dist/types/cli/mfRuntimePlugins/node.d.ts +3 -0
  85. package/dist/types/cli/routes/ast/constant.d.ts +8 -0
  86. package/dist/types/cli/routes/ast/generateRoutes.d.ts +5 -0
  87. package/dist/types/cli/routes/ast/index.d.ts +1 -0
  88. package/dist/types/cli/routes/clearMFCache.d.ts +1 -0
  89. package/dist/types/cli/routes/exportRoutePlugin.d.ts +4 -0
  90. package/dist/types/cli/routes/importRoutesPlugin.d.ts +4 -0
  91. package/dist/types/cli/routes/plugin.d.ts +4 -0
  92. package/dist/types/cli/routes/traverseRouteFiles.d.ts +11 -0
  93. package/dist/types/cli/routes/utils.d.ts +11 -0
  94. package/dist/types/cli/server/fetchRemoteFullRoutesMap.d.ts +11 -0
  95. package/dist/types/cli/server/fetchRoutePlugin.d.ts +10 -0
  96. package/dist/types/cli/utils.d.ts +2 -0
  97. package/dist/types/constant.d.ts +11 -0
  98. package/dist/types/interfaces/route.d.ts +12 -0
  99. package/dist/types/runtime/index.d.ts +1 -0
  100. package/dist/types/runtime/routes/plugin-inject-assets.d.ts +4 -0
  101. package/dist/types/runtime/routes/plugin.d.ts +5 -0
  102. package/dist/types/runtime/routes/utils.d.ts +22 -0
  103. package/dist/types/runtime/withMFRouteId.d.ts +1 -0
  104. package/dist/types/ssr-runtime/plugin.d.ts +3 -1
  105. package/dist/types/types/index.d.ts +3 -1
  106. package/dist/types/types/modern.d.ts +12 -0
  107. package/dist/types/types/routes.d.ts +19 -0
  108. package/package.json +42 -5
  109. package/dist/esm/cli/constant.js +0 -4
  110. package/dist/esm/cli/mfRuntimePlugins/shared-strategy.js +0 -25
  111. package/dist/esm-node/cli/constant.js +0 -4
  112. package/dist/esm-node/cli/mfRuntimePlugins/shared-strategy.js +0 -23
  113. package/dist/types/cli/constant.d.ts +0 -1
  114. package/dist/types/cli/mfRuntimePlugins/shared-strategy.d.ts +0 -3
  115. /package/dist/types/cli/mfRuntimePlugins/{inject-node-fetch.d.ts → node-fetch.d.ts} +0 -0
@@ -32,7 +32,8 @@ __export(utils_exports, {
32
32
  getMFConfig: () => getMFConfig,
33
33
  patchBundlerConfig: () => patchBundlerConfig,
34
34
  patchIgnoreWarning: () => patchIgnoreWarning,
35
- patchMFConfig: () => patchMFConfig
35
+ patchMFConfig: () => patchMFConfig,
36
+ replaceRemoteUrl: () => replaceRemoteUrl
36
37
  });
37
38
  module.exports = __toCommonJS(utils_exports);
38
39
  var import_sdk = require("@module-federation/sdk");
@@ -85,7 +86,9 @@ const replaceRemoteUrl = (mfConfig, remoteIpStrategy) => {
85
86
  if (typeof remoteObject === "string") {
86
87
  return;
87
88
  }
88
- handleRemoteObject(remoteObject);
89
+ if ("entry" in remoteObject && typeof remoteObject.entry === "string") {
90
+ remoteObject.entry = remoteObject.entry.replace(import_constant.LOCALHOST, ipv4);
91
+ }
89
92
  });
90
93
  } else if (typeof mfConfig.remotes !== "string") {
91
94
  handleRemoteObject(mfConfig.remotes);
@@ -134,17 +137,18 @@ const patchMFConfig = (mfConfig, isServer, remoteIpStrategy) => {
134
137
  const runtimePlugins = [
135
138
  ...mfConfig.runtimePlugins || []
136
139
  ];
140
+ var _mfConfig_shareStrategy;
141
+ mfConfig.shareStrategy = (_mfConfig_shareStrategy = mfConfig.shareStrategy) !== null && _mfConfig_shareStrategy !== void 0 ? _mfConfig_shareStrategy : "loaded-first";
137
142
  patchDTSConfig(mfConfig, isServer);
138
- injectRuntimePlugins(import_path.default.resolve(__dirname, "./mfRuntimePlugins/shared-strategy.js"), runtimePlugins);
139
143
  if (isDev) {
140
144
  injectRuntimePlugins(import_path.default.resolve(__dirname, "./mfRuntimePlugins/resolve-entry-ipv4.js"), runtimePlugins);
141
145
  }
142
146
  if (isServer) {
143
- injectRuntimePlugins(require.resolve("@module-federation/node/runtimePlugin"), runtimePlugins);
147
+ injectRuntimePlugins(import_path.default.resolve(__dirname, "./mfRuntimePlugins/node.js"), runtimePlugins);
144
148
  if (isDev) {
145
149
  injectRuntimePlugins(require.resolve("@module-federation/node/record-dynamic-remote-entry-hash-plugin"), runtimePlugins);
146
150
  }
147
- injectRuntimePlugins(import_path.default.resolve(__dirname, "./mfRuntimePlugins/inject-node-fetch.js"), runtimePlugins);
151
+ injectRuntimePlugins(import_path.default.resolve(__dirname, "./mfRuntimePlugins/node-fetch.js"), runtimePlugins);
148
152
  if (!mfConfig.library) {
149
153
  mfConfig.library = {
150
154
  type: "commonjs-module",
@@ -330,5 +334,6 @@ function autoDeleteSplitChunkCacheGroups(mfConfig, bundlerConfig) {
330
334
  getMFConfig,
331
335
  patchBundlerConfig,
332
336
  patchIgnoreWarning,
333
- patchMFConfig
337
+ patchMFConfig,
338
+ replaceRemoteUrl
334
339
  });
@@ -59,10 +59,10 @@ const mfConfig = {
59
59
  remote: `http://${ipv4}:3000/remoteEntry.js`
60
60
  },
61
61
  remoteType: "script",
62
+ shareStrategy: "loaded-first",
62
63
  runtimePlugins: [
63
- import_path.default.resolve(__dirname, "./mfRuntimePlugins/shared-strategy.js"),
64
- require.resolve("@module-federation/node/runtimePlugin"),
65
- import_path.default.resolve(__dirname, "./mfRuntimePlugins/inject-node-fetch.js")
64
+ import_path.default.resolve(__dirname, "./mfRuntimePlugins/node.js"),
65
+ import_path.default.resolve(__dirname, "./mfRuntimePlugins/node-fetch.js")
66
66
  ],
67
67
  shared: {
68
68
  react: {
@@ -87,9 +87,8 @@ const mfConfig = {
87
87
  remote: `http://${ipv4}:3000/remoteEntry.js`
88
88
  },
89
89
  remoteType: "script",
90
- runtimePlugins: [
91
- import_path.default.resolve(__dirname, "./mfRuntimePlugins/shared-strategy.js")
92
- ],
90
+ runtimePlugins: [],
91
+ shareStrategy: "loaded-first",
93
92
  shared: {
94
93
  react: {
95
94
  eager: true,
@@ -18,17 +18,50 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var constant_exports = {};
20
20
  __export(constant_exports, {
21
+ DEFAULT_ENTRY: () => DEFAULT_ENTRY,
22
+ DEFAULT_LAYOUT: () => DEFAULT_LAYOUT,
23
+ FOLD_IDENTIFIER: () => FOLD_IDENTIFIER,
21
24
  LOCALHOST: () => LOCALHOST,
25
+ META_NAME: () => META_NAME,
26
+ MF_JSON: () => MF_JSON,
27
+ MF_ROUTES: () => MF_ROUTES,
28
+ MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME: () => MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME,
29
+ MODERN_JS_ROUTE_SERVER_LOADER: () => MODERN_JS_ROUTE_SERVER_LOADER,
22
30
  MODERN_JS_SERVER_DIR: () => MODERN_JS_SERVER_DIR,
23
- PLUGIN_IDENTIFIER: () => PLUGIN_IDENTIFIER
31
+ PLUGIN_IDENTIFIER: () => PLUGIN_IDENTIFIER,
32
+ ROUTE_ID: () => ROUTE_ID,
33
+ SEPARATOR: () => SEPARATOR,
34
+ isDev: () => isDev
24
35
  });
25
36
  module.exports = __toCommonJS(constant_exports);
26
37
  const MODERN_JS_SERVER_DIR = "bundles";
27
38
  const LOCALHOST = "localhost";
28
39
  const PLUGIN_IDENTIFIER = "[ Modern.js Module Federation ]";
40
+ const isDev = process.env.NODE_ENV === "development";
41
+ const MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME = "routes";
42
+ const MODERN_JS_ROUTE_SERVER_LOADER = "route-server-loaders";
43
+ const META_NAME = "modern-js";
44
+ const FOLD_IDENTIFIER = "@mf";
45
+ const SEPARATOR = "_";
46
+ const MF_ROUTES = "mf-routes";
47
+ const DEFAULT_ENTRY = "main";
48
+ const DEFAULT_LAYOUT = "layout";
49
+ const MF_JSON = "mf.json";
50
+ const ROUTE_ID = "ROUTE_ID";
29
51
  // Annotate the CommonJS export names for ESM import in node:
30
52
  0 && (module.exports = {
53
+ DEFAULT_ENTRY,
54
+ DEFAULT_LAYOUT,
55
+ FOLD_IDENTIFIER,
31
56
  LOCALHOST,
57
+ META_NAME,
58
+ MF_JSON,
59
+ MF_ROUTES,
60
+ MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME,
61
+ MODERN_JS_ROUTE_SERVER_LOADER,
32
62
  MODERN_JS_SERVER_DIR,
33
- PLUGIN_IDENTIFIER
63
+ PLUGIN_IDENTIFIER,
64
+ ROUTE_ID,
65
+ SEPARATOR,
66
+ isDev
34
67
  });
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var route_exports = {};
16
+ module.exports = __toCommonJS(route_exports);
@@ -19,13 +19,16 @@ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "defau
19
19
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
20
  var runtime_exports = {};
21
21
  __export(runtime_exports, {
22
- createRemoteSSRComponent: () => import_createRemoteSSRComponent.createRemoteSSRComponent
22
+ createRemoteSSRComponent: () => import_createRemoteSSRComponent.createRemoteSSRComponent,
23
+ withMFRouteId: () => import_withMFRouteId.withMFRouteId
23
24
  });
24
25
  module.exports = __toCommonJS(runtime_exports);
25
26
  __reExport(runtime_exports, require("@module-federation/enhanced/runtime"), module.exports);
26
27
  var import_createRemoteSSRComponent = require("./createRemoteSSRComponent");
28
+ var import_withMFRouteId = require("./withMFRouteId");
27
29
  // Annotate the CommonJS export names for ESM import in node:
28
30
  0 && (module.exports = {
29
31
  createRemoteSSRComponent,
32
+ withMFRouteId,
30
33
  ...require("@module-federation/enhanced/runtime")
31
34
  });
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var plugin_inject_assets_exports = {};
20
+ __export(plugin_inject_assets_exports, {
21
+ ssrDataLoaderInjectAssetsPlugin: () => ssrDataLoaderInjectAssetsPlugin
22
+ });
23
+ module.exports = __toCommonJS(plugin_inject_assets_exports);
24
+ var import_jsx_runtime = require("react/jsx-runtime");
25
+ var import_react = require("react");
26
+ var import_runtime = require("@module-federation/enhanced/runtime");
27
+ var import_createRemoteSSRComponent = require("../createRemoteSSRComponent");
28
+ var import_runtime2 = require("@meta/runtime");
29
+ var import_utils = require("./utils");
30
+ function traverseRoutes(routes, remoteNames) {
31
+ routes.forEach((route) => {
32
+ route.id && remoteNames.add((0, import_utils.decodeId)(route.id));
33
+ route.children && traverseRoutes(route.children, remoteNames);
34
+ });
35
+ }
36
+ const ssrDataLoaderInjectAssetsPlugin = ({ metaName }) => {
37
+ return {
38
+ name: "@modern-js/plugin-mf-routes-inject-assets",
39
+ pre: [
40
+ "@modern-js/plugin-mf-routes"
41
+ ],
42
+ post: [
43
+ "@module-federation/modern-js",
44
+ `@${metaName}/plugin-router`
45
+ ],
46
+ setup: () => {
47
+ return {
48
+ wrapRoot() {
49
+ const AppWrapper = (props) => {
50
+ const instance = (0, import_runtime.getInstance)();
51
+ if (!instance || !instance.options.remotes.length) {
52
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
53
+ children: props.children
54
+ });
55
+ }
56
+ const context = (0, import_react.useContext)(import_runtime2.RuntimeReactContext);
57
+ const { remotes } = instance.options;
58
+ const remoteNames = /* @__PURE__ */ new Set();
59
+ traverseRoutes(context.routes, remoteNames);
60
+ const remoteIds = [
61
+ ...remoteNames
62
+ ].reduce((sum, cur) => {
63
+ const matchRemote = remotes.find((r) => r.name === cur);
64
+ if (matchRemote) {
65
+ sum.add((0, import_utils.getRemoteId)(cur));
66
+ }
67
+ return sum;
68
+ }, /* @__PURE__ */ new Set());
69
+ const assets = [];
70
+ remoteIds.forEach((remoteId) => {
71
+ assets.push(...(0, import_createRemoteSSRComponent.collectSSRAssets)({
72
+ id: remoteId,
73
+ injectScript: false
74
+ }));
75
+ });
76
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
77
+ children: [
78
+ assets,
79
+ props.children
80
+ ]
81
+ });
82
+ };
83
+ return AppWrapper;
84
+ }
85
+ };
86
+ }
87
+ };
88
+ };
89
+ // Annotate the CommonJS export names for ESM import in node:
90
+ 0 && (module.exports = {
91
+ ssrDataLoaderInjectAssetsPlugin
92
+ });
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var plugin_exports = {};
20
+ __export(plugin_exports, {
21
+ ssrDataLoaderPlugin: () => ssrDataLoaderPlugin
22
+ });
23
+ module.exports = __toCommonJS(plugin_exports);
24
+ var import_runtime = require("@module-federation/enhanced/runtime");
25
+ var import_constant = require("../../constant");
26
+ var import_utils = require("./utils");
27
+ const ssrDataLoaderPlugin = ({ metaName, dataLoaderRemotes }) => {
28
+ return {
29
+ name: "@modern-js/plugin-mf-routes",
30
+ post: [
31
+ `@${metaName}/plugin-router`,
32
+ "@module-federation/modern-js"
33
+ ],
34
+ setup: () => {
35
+ const remoteRoutesMap = {};
36
+ return {
37
+ async beforeRender() {
38
+ if (Object.keys(remoteRoutesMap).length) {
39
+ return;
40
+ }
41
+ const instance = (0, import_runtime.getInstance)();
42
+ if (!instance) {
43
+ return;
44
+ }
45
+ if (!instance.options.remotes.length) {
46
+ return;
47
+ }
48
+ await Promise.all(instance.options.remotes.map(async (remote) => {
49
+ if (!dataLoaderRemotes.includes(remote.name)) {
50
+ return;
51
+ }
52
+ const remoteId = `${remote.name}/${import_constant.DEFAULT_ENTRY}/${import_constant.MF_ROUTES}`;
53
+ const { routes } = await instance.loadRemote(remoteId);
54
+ remoteRoutesMap[remote.name] = {
55
+ routes
56
+ };
57
+ }));
58
+ },
59
+ // runtime plugin not save route , so it needs to inject again when trigger
60
+ modifyRoutes: (routes) => {
61
+ (0, import_utils.injectRemoteRoutes)({
62
+ entry: {
63
+ routes
64
+ }
65
+ }, remoteRoutesMap);
66
+ return routes;
67
+ }
68
+ };
69
+ }
70
+ };
71
+ };
72
+ // Annotate the CommonJS export names for ESM import in node:
73
+ 0 && (module.exports = {
74
+ ssrDataLoaderPlugin
75
+ });
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var utils_exports = {};
20
+ __export(utils_exports, {
21
+ decodeId: () => decodeId,
22
+ getRemoteId: () => getRemoteId,
23
+ getRemoteLayoutId: () => getRemoteLayoutId,
24
+ getRemoteRoutesInfos: () => getRemoteRoutesInfos,
25
+ injectRemoteRoutes: () => injectRemoteRoutes,
26
+ transformName2Prefix: () => transformName2Prefix
27
+ });
28
+ module.exports = __toCommonJS(utils_exports);
29
+ var import_sdk = require("@module-federation/sdk");
30
+ var import_constant = require("../../constant");
31
+ const SPLIT_SYMBOL = "@";
32
+ function transformName2Prefix(name) {
33
+ return `${(0, import_sdk.encodeName)(name, "", false)}${SPLIT_SYMBOL}`;
34
+ }
35
+ function decodeId(prefix) {
36
+ const realPrefix = prefix.split(SPLIT_SYMBOL)[0];
37
+ return (0, import_sdk.decodeName)(realPrefix, "", false);
38
+ }
39
+ function getRemoteRoutesInfos(route, remoteRoutesMap) {
40
+ if (!route.id) {
41
+ return;
42
+ }
43
+ const remoteName = decodeId(route.id);
44
+ const remoteRouteObj = remoteRoutesMap[remoteName];
45
+ if (!remoteRouteObj) {
46
+ return;
47
+ }
48
+ const remoteRoutes = remoteRouteObj.routes[0];
49
+ return {
50
+ routes: remoteRoutes,
51
+ name: remoteName,
52
+ pathName: route.path
53
+ };
54
+ }
55
+ function getRemoteLayoutId(remoteName) {
56
+ const prefix = transformName2Prefix(remoteName);
57
+ return `${prefix}${import_constant.DEFAULT_LAYOUT}`;
58
+ }
59
+ function getRemoteId(remoteName) {
60
+ return `${remoteName}/${import_constant.DEFAULT_ENTRY}/${import_constant.MF_ROUTES}`;
61
+ }
62
+ function injectRemoteRoutes(initialRoutes, remoteRoutesMap) {
63
+ const traverse = (route) => {
64
+ var _route_children;
65
+ const remoteRoutesInfos = getRemoteRoutesInfos(route, remoteRoutesMap);
66
+ if (remoteRoutesInfos) {
67
+ const { routes, pathName } = remoteRoutesInfos;
68
+ route.id = routes.id;
69
+ route.path = pathName;
70
+ if (routes.loader) {
71
+ route.loader = routes.loader;
72
+ }
73
+ if (routes.children) {
74
+ route.children = routes.children;
75
+ }
76
+ if (routes.Component) {
77
+ route.Component = routes.Component;
78
+ if (route.element) {
79
+ delete route.element;
80
+ }
81
+ } else if (routes.element) {
82
+ route.element = routes.element;
83
+ if (route.Component) {
84
+ delete route.Component;
85
+ }
86
+ }
87
+ return;
88
+ }
89
+ (_route_children = route.children) === null || _route_children === void 0 ? void 0 : _route_children.forEach((r) => {
90
+ traverse(r);
91
+ });
92
+ };
93
+ Object.keys(initialRoutes).forEach((entryName) => {
94
+ const routes = initialRoutes[entryName];
95
+ if (Array.isArray(routes)) {
96
+ routes.forEach((route) => {
97
+ traverse(route);
98
+ });
99
+ } else {
100
+ var _routes_routes;
101
+ routes === null || routes === void 0 ? void 0 : (_routes_routes = routes.routes) === null || _routes_routes === void 0 ? void 0 : _routes_routes.forEach((r) => {
102
+ traverse(r);
103
+ });
104
+ }
105
+ });
106
+ }
107
+ // Annotate the CommonJS export names for ESM import in node:
108
+ 0 && (module.exports = {
109
+ decodeId,
110
+ getRemoteId,
111
+ getRemoteLayoutId,
112
+ getRemoteRoutesInfos,
113
+ injectRemoteRoutes,
114
+ transformName2Prefix
115
+ });
@@ -16,28 +16,16 @@ var __copyProps = (to, from, except, desc) => {
16
16
  return to;
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var shared_strategy_exports = {};
20
- __export(shared_strategy_exports, {
21
- default: () => shared_strategy_default
19
+ var withMFRouteId_exports = {};
20
+ __export(withMFRouteId_exports, {
21
+ withMFRouteId: () => withMFRouteId
22
22
  });
23
- module.exports = __toCommonJS(shared_strategy_exports);
24
- const sharedStrategy = () => ({
25
- name: "shared-strategy-plugin",
26
- beforeInit(args) {
27
- const { userOptions } = args;
28
- const shared = userOptions.shared;
29
- if (shared) {
30
- Object.keys(shared).forEach((sharedKey) => {
31
- const sharedConfigs = shared[sharedKey];
32
- const arraySharedConfigs = Array.isArray(sharedConfigs) ? sharedConfigs : [
33
- sharedConfigs
34
- ];
35
- arraySharedConfigs.forEach((s) => {
36
- s.strategy = "loaded-first";
37
- });
38
- });
39
- }
40
- return args;
41
- }
23
+ module.exports = __toCommonJS(withMFRouteId_exports);
24
+ function withMFRouteId(id) {
25
+ const prefix = typeof MODERN_ROUTER_ID_PREFIX === "string" ? MODERN_ROUTER_ID_PREFIX : "";
26
+ return prefix + id;
27
+ }
28
+ // Annotate the CommonJS export names for ESM import in node:
29
+ 0 && (module.exports = {
30
+ withMFRouteId
42
31
  });
43
- var shared_strategy_default = sharedStrategy;
@@ -34,15 +34,16 @@ module.exports = __toCommonJS(plugin_exports);
34
34
  var import_jsx_runtime = require("react/jsx-runtime");
35
35
  var import_hoist_non_react_statics = __toESM(require("hoist-non-react-statics"));
36
36
  var import_SSRLiveReload = require("./SSRLiveReload");
37
- const mfSSRPlugin = () => ({
37
+ const mfSSRPlugin = ({ metaName }) => ({
38
38
  name: "@module-federation/modern-js",
39
+ pre: [
40
+ `@${metaName}/plugin-router`
41
+ ],
39
42
  setup: () => {
40
43
  return {
41
- async init({ context }, next) {
44
+ async beforeRender() {
42
45
  if (typeof window !== "undefined") {
43
- return next({
44
- context
45
- });
46
+ return;
46
47
  }
47
48
  globalThis.shouldUpdate = false;
48
49
  const nodeUtils = await Promise.resolve().then(() => __toESM(require("@module-federation/node/utils")));
@@ -52,9 +53,7 @@ const mfSSRPlugin = () => ({
52
53
  await nodeUtils.flushChunks();
53
54
  globalThis.shouldUpdate = true;
54
55
  }
55
- return next({
56
- context
57
- });
56
+ return;
58
57
  },
59
58
  wrapRoot(App) {
60
59
  const AppWrapper = (props) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var modern_exports = {};
16
+ module.exports = __toCommonJS(modern_exports);
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var routes_exports = {};
16
+ module.exports = __toCommonJS(routes_exports);
@@ -5,6 +5,7 @@ import { ModuleFederationPlugin as WebpackModuleFederationPlugin, AsyncBoundaryP
5
5
  import { ModuleFederationPlugin as RspackModuleFederationPlugin } from "@module-federation/enhanced/rspack";
6
6
  import { moduleFederationConfigPlugin } from "./configPlugin";
7
7
  import { moduleFederationSSRPlugin } from "./ssrPlugin";
8
+ import { moduleFederationRoutesPlugin } from "./routes/plugin";
8
9
  var moduleFederationPlugin = function() {
9
10
  var userConfig = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
10
11
  var internalModernPluginOptions = {
@@ -14,7 +15,7 @@ var moduleFederationPlugin = function() {
14
15
  nodePlugin: void 0,
15
16
  distOutputDir: "",
16
17
  originPluginOptions: userConfig,
17
- remoteIpStrategy: userConfig === null || userConfig === void 0 ? void 0 : userConfig.remoteIpStrategy
18
+ remoteIpStrategy: void 0
18
19
  };
19
20
  return {
20
21
  name: "@modern-js/plugin-module-federation",
@@ -80,7 +81,11 @@ var moduleFederationPlugin = function() {
80
81
  }(),
81
82
  usePlugins: [
82
83
  moduleFederationConfigPlugin(internalModernPluginOptions),
83
- moduleFederationSSRPlugin(internalModernPluginOptions)
84
+ moduleFederationSSRPlugin(internalModernPluginOptions),
85
+ moduleFederationRoutesPlugin({
86
+ userConfig,
87
+ internalOptions: internalModernPluginOptions
88
+ })
84
89
  ]
85
90
  };
86
91
  };
@@ -1,7 +1,7 @@
1
1
  import nodeFetch from "node-fetch";
2
2
  var injectNodeFetchPlugin = function() {
3
3
  return {
4
- name: "inject-node-fetch-plugin",
4
+ name: "node-fetch-plugin",
5
5
  beforeInit: function beforeInit(args) {
6
6
  if (!globalThis.fetch) {
7
7
  globalThis.fetch = nodeFetch;
@@ -10,7 +10,7 @@ var injectNodeFetchPlugin = function() {
10
10
  }
11
11
  };
12
12
  };
13
- var inject_node_fetch_default = injectNodeFetchPlugin;
13
+ var node_fetch_default = injectNodeFetchPlugin;
14
14
  export {
15
- inject_node_fetch_default as default
15
+ node_fetch_default as default
16
16
  };
@@ -0,0 +1,13 @@
1
+ import nodeRuntimePlugin from "@module-federation/node/runtimePlugin";
2
+ var isContainer = typeof __filename === "string" ? __filename.includes("remote") ? true : false : false;
3
+ var pluginName = "node-plugin-".concat(isContainer);
4
+ var nodePlugin = function() {
5
+ return {
6
+ name: pluginName,
7
+ beforeInit: nodeRuntimePlugin().beforeInit
8
+ };
9
+ };
10
+ var node_default = nodePlugin;
11
+ export {
12
+ node_default as default
13
+ };
@@ -0,0 +1,18 @@
1
+ var IS_ROOT = "isRoot";
2
+ var ID = "id";
3
+ var COMPONENT = "component";
4
+ var LAZY_COMPONENT = "lazyImport";
5
+ var SHOULD_REVALIDATE = "shouldRevalidate";
6
+ var PRIVATE_COMPONENT = "_component";
7
+ var ELEMENT = "element";
8
+ var 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
+ };