@module-federation/modern-js 0.0.0-next-20240913081127 → 0.0.0-next-20240913095223

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 (99) hide show
  1. package/dist/cjs/cli/dataLoader/ast/constant.js +49 -0
  2. package/dist/cjs/cli/dataLoader/ast/generateRoutes.js +141 -0
  3. package/dist/cjs/cli/{constant.js → dataLoader/ast/index.js} +6 -6
  4. package/dist/cjs/cli/dataLoader/clearMFCache.js +57 -0
  5. package/dist/cjs/cli/dataLoader/generateRouteFile.js +143 -0
  6. package/dist/cjs/cli/dataLoader/patchMFConfig.js +140 -0
  7. package/dist/cjs/cli/dataLoader/plugin.js +204 -0
  8. package/dist/cjs/cli/index.js +5 -1
  9. package/dist/cjs/cli/mfRuntimePlugins/{inject-node-fetch.js → node-fetch.js} +6 -6
  10. package/dist/cjs/cli/mfRuntimePlugins/node.js +41 -0
  11. package/dist/cjs/cli/mfRuntimePlugins/resolve-entry-ipv4.js +40 -38
  12. package/dist/cjs/cli/server/dataLoaderPlugin.js +84 -0
  13. package/dist/cjs/cli/server/fetchRemoteFullRoutesMap.js +69 -0
  14. package/dist/cjs/cli/ssrPlugin.js +5 -2
  15. package/dist/cjs/cli/utils.js +11 -6
  16. package/dist/cjs/cli/utils.spec.js +5 -6
  17. package/dist/cjs/constant.js +32 -2
  18. package/dist/cjs/interfaces/route.js +16 -0
  19. package/dist/cjs/runtime/dataLoader/plugin-inject-assets.js +94 -0
  20. package/dist/cjs/runtime/dataLoader/plugin.js +74 -0
  21. package/dist/cjs/runtime/dataLoader/utils.js +106 -0
  22. package/dist/cjs/runtime/index.js +4 -1
  23. package/dist/cjs/{cli/mfRuntimePlugins/shared-strategy.js → runtime/withMFRouteId.js} +11 -23
  24. package/dist/cjs/ssr-runtime/plugin.js +9 -22
  25. package/dist/esm/cli/dataLoader/ast/constant.js +18 -0
  26. package/dist/esm/cli/dataLoader/ast/generateRoutes.js +108 -0
  27. package/dist/esm/cli/dataLoader/ast/index.js +4 -0
  28. package/dist/esm/cli/dataLoader/clearMFCache.js +34 -0
  29. package/dist/esm/cli/dataLoader/generateRouteFile.js +293 -0
  30. package/dist/esm/cli/dataLoader/patchMFConfig.js +106 -0
  31. package/dist/esm/cli/dataLoader/plugin.js +232 -0
  32. package/dist/esm/cli/index.js +6 -2
  33. package/dist/esm/cli/mfRuntimePlugins/{inject-node-fetch.js → node-fetch.js} +3 -3
  34. package/dist/esm/cli/mfRuntimePlugins/node.js +13 -0
  35. package/dist/esm/cli/server/dataLoaderPlugin.js +107 -0
  36. package/dist/esm/cli/server/fetchRemoteFullRoutesMap.js +88 -0
  37. package/dist/esm/cli/ssrPlugin.js +6 -3
  38. package/dist/esm/cli/utils.js +13 -8
  39. package/dist/esm/cli/utils.spec.js +5 -6
  40. package/dist/esm/constant.js +21 -1
  41. package/dist/esm/interfaces/route.js +0 -0
  42. package/dist/esm/runtime/dataLoader/plugin-inject-assets.js +73 -0
  43. package/dist/esm/runtime/dataLoader/plugin.js +94 -0
  44. package/dist/esm/runtime/dataLoader/utils.js +77 -0
  45. package/dist/esm/runtime/index.js +3 -1
  46. package/dist/esm/runtime/withMFRouteId.js +7 -0
  47. package/dist/esm/ssr-runtime/plugin.js +10 -26
  48. package/dist/esm-node/cli/dataLoader/ast/constant.js +18 -0
  49. package/dist/esm-node/cli/dataLoader/ast/generateRoutes.js +107 -0
  50. package/dist/esm-node/cli/dataLoader/ast/index.js +4 -0
  51. package/dist/esm-node/cli/dataLoader/clearMFCache.js +33 -0
  52. package/dist/esm-node/cli/dataLoader/generateRouteFile.js +108 -0
  53. package/dist/esm-node/cli/dataLoader/patchMFConfig.js +106 -0
  54. package/dist/esm-node/cli/dataLoader/plugin.js +169 -0
  55. package/dist/esm-node/cli/index.js +5 -1
  56. package/dist/esm-node/cli/mfRuntimePlugins/{inject-node-fetch.js → node-fetch.js} +3 -3
  57. package/dist/esm-node/cli/mfRuntimePlugins/node.js +11 -0
  58. package/dist/esm-node/cli/mfRuntimePlugins/resolve-entry-ipv4.js +40 -38
  59. package/dist/esm-node/cli/server/dataLoaderPlugin.js +64 -0
  60. package/dist/esm-node/cli/server/fetchRemoteFullRoutesMap.js +44 -0
  61. package/dist/esm-node/cli/ssrPlugin.js +5 -2
  62. package/dist/esm-node/cli/utils.js +9 -5
  63. package/dist/esm-node/cli/utils.spec.js +5 -6
  64. package/dist/esm-node/constant.js +21 -1
  65. package/dist/esm-node/interfaces/route.js +0 -0
  66. package/dist/esm-node/runtime/dataLoader/plugin-inject-assets.js +70 -0
  67. package/dist/esm-node/runtime/dataLoader/plugin.js +50 -0
  68. package/dist/esm-node/runtime/dataLoader/utils.js +77 -0
  69. package/dist/esm-node/runtime/index.js +3 -1
  70. package/dist/esm-node/runtime/withMFRouteId.js +7 -0
  71. package/dist/esm-node/ssr-runtime/plugin.js +9 -22
  72. package/dist/types/cli/dataLoader/ast/constant.d.ts +8 -0
  73. package/dist/types/cli/dataLoader/ast/generateRoutes.d.ts +5 -0
  74. package/dist/types/cli/dataLoader/ast/index.d.ts +1 -0
  75. package/dist/types/cli/dataLoader/clearMFCache.d.ts +1 -0
  76. package/dist/types/cli/dataLoader/generateRouteFile.d.ts +7 -0
  77. package/dist/types/cli/dataLoader/patchMFConfig.d.ts +10 -0
  78. package/dist/types/cli/dataLoader/plugin.d.ts +6 -0
  79. package/dist/types/cli/mfRuntimePlugins/node.d.ts +3 -0
  80. package/dist/types/cli/server/dataLoaderPlugin.d.ts +10 -0
  81. package/dist/types/cli/server/fetchRemoteFullRoutesMap.d.ts +10 -0
  82. package/dist/types/cli/utils.d.ts +2 -0
  83. package/dist/types/constant.d.ts +10 -0
  84. package/dist/types/interfaces/route.d.ts +12 -0
  85. package/dist/types/runtime/dataLoader/plugin-inject-assets.d.ts +4 -0
  86. package/dist/types/runtime/dataLoader/plugin.d.ts +4 -0
  87. package/dist/types/runtime/dataLoader/utils.d.ts +22 -0
  88. package/dist/types/runtime/index.d.ts +1 -0
  89. package/dist/types/runtime/withMFRouteId.d.ts +1 -0
  90. package/dist/types/ssr-runtime/plugin.d.ts +3 -1
  91. package/dist/types/types/index.d.ts +9 -0
  92. package/package.json +48 -11
  93. package/dist/esm/cli/constant.js +0 -4
  94. package/dist/esm/cli/mfRuntimePlugins/shared-strategy.js +0 -25
  95. package/dist/esm-node/cli/constant.js +0 -4
  96. package/dist/esm-node/cli/mfRuntimePlugins/shared-strategy.js +0 -23
  97. package/dist/types/cli/constant.d.ts +0 -1
  98. package/dist/types/cli/mfRuntimePlugins/shared-strategy.d.ts +0 -3
  99. /package/dist/types/cli/mfRuntimePlugins/{inject-node-fetch.d.ts → node-fetch.d.ts} +0 -0
@@ -18,17 +18,47 @@ 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
+ SEPARATOR: () => SEPARATOR,
33
+ isDev: () => isDev
24
34
  });
25
35
  module.exports = __toCommonJS(constant_exports);
26
36
  const MODERN_JS_SERVER_DIR = "bundles";
27
37
  const LOCALHOST = "localhost";
28
38
  const PLUGIN_IDENTIFIER = "[ Modern.js Module Federation ]";
39
+ const isDev = process.env.NODE_ENV === "development";
40
+ const MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME = "routes";
41
+ const MODERN_JS_ROUTE_SERVER_LOADER = "route-server-loaders";
42
+ const META_NAME = "modern-js";
43
+ const FOLD_IDENTIFIER = "@mf";
44
+ const SEPARATOR = "_";
45
+ const MF_ROUTES = "mf-routes";
46
+ const DEFAULT_ENTRY = "main";
47
+ const DEFAULT_LAYOUT = "layout";
48
+ const MF_JSON = "mf.json";
29
49
  // Annotate the CommonJS export names for ESM import in node:
30
50
  0 && (module.exports = {
51
+ DEFAULT_ENTRY,
52
+ DEFAULT_LAYOUT,
53
+ FOLD_IDENTIFIER,
31
54
  LOCALHOST,
55
+ META_NAME,
56
+ MF_JSON,
57
+ MF_ROUTES,
58
+ MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME,
59
+ MODERN_JS_ROUTE_SERVER_LOADER,
32
60
  MODERN_JS_SERVER_DIR,
33
- PLUGIN_IDENTIFIER
61
+ PLUGIN_IDENTIFIER,
62
+ SEPARATOR,
63
+ isDev
34
64
  });
@@ -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);
@@ -0,0 +1,94 @@
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-data-loader-inject-assets",
39
+ pre: [
40
+ "@modern-js/plugin-mf-data-loader"
41
+ ],
42
+ post: [
43
+ "@module-federation/modern-js",
44
+ `@${metaName}/plugin-router`
45
+ ],
46
+ setup: () => {
47
+ return {
48
+ wrapRoot(App) {
49
+ const AppWrapper = (props) => {
50
+ const instance = (0, import_runtime.getInstance)();
51
+ if (!instance || !instance.options.remotes.length) {
52
+ console.log("plugin-mf-data-loader-inject-assets no instance!");
53
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
54
+ children: props.children
55
+ });
56
+ }
57
+ const context = (0, import_react.useContext)(import_runtime2.RuntimeReactContext);
58
+ const { remotes } = instance.options;
59
+ const remoteNames = /* @__PURE__ */ new Set();
60
+ traverseRoutes(context.routes, remoteNames);
61
+ const remoteIds = [
62
+ ...remoteNames
63
+ ].reduce((sum, cur) => {
64
+ const matchRemote = remotes.find((r) => r.name === cur);
65
+ if (matchRemote) {
66
+ sum.add((0, import_utils.getRemoteId)(cur));
67
+ }
68
+ return sum;
69
+ }, /* @__PURE__ */ new Set());
70
+ const assets = [];
71
+ remoteIds.forEach((remoteId) => {
72
+ assets.push(...(0, import_createRemoteSSRComponent.collectSSRAssets)({
73
+ id: remoteId,
74
+ injectScript: false
75
+ }));
76
+ });
77
+ console.log("plugin-mf-data-loader-inject-assets has assets: ", assets);
78
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
79
+ children: [
80
+ assets,
81
+ props.children
82
+ ]
83
+ });
84
+ };
85
+ return AppWrapper;
86
+ }
87
+ };
88
+ }
89
+ };
90
+ };
91
+ // Annotate the CommonJS export names for ESM import in node:
92
+ 0 && (module.exports = {
93
+ ssrDataLoaderInjectAssetsPlugin
94
+ });
@@ -0,0 +1,74 @@
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 }) => {
28
+ return {
29
+ name: "@modern-js/plugin-mf-data-loader",
30
+ post: [
31
+ `@${metaName}/plugin-router`,
32
+ "@module-federation/modern-js"
33
+ ],
34
+ setup: () => {
35
+ const remoteRoutesMap = {};
36
+ return {
37
+ async beforeRender() {
38
+ console.log("init");
39
+ if (Object.keys(remoteRoutesMap).length) {
40
+ return;
41
+ }
42
+ const instance = (0, import_runtime.getInstance)();
43
+ if (!instance) {
44
+ console.log("no instance!");
45
+ return;
46
+ }
47
+ if (!instance.options.remotes.length) {
48
+ return;
49
+ }
50
+ await Promise.all(instance.options.remotes.map(async (remote) => {
51
+ const remoteId = `${remote.name}/${import_constant.DEFAULT_ENTRY}/${import_constant.MF_ROUTES}`;
52
+ const { routes } = await instance.loadRemote(remoteId);
53
+ remoteRoutesMap[remote.name] = {
54
+ routes
55
+ };
56
+ }));
57
+ },
58
+ // runtime plugin not save route , so it needs to inject again when trigger
59
+ modifyRoutes: (routes) => {
60
+ (0, import_utils.injectRemoteRoutes)({
61
+ entry: {
62
+ routes
63
+ }
64
+ }, remoteRoutesMap);
65
+ return routes;
66
+ }
67
+ };
68
+ }
69
+ };
70
+ };
71
+ // Annotate the CommonJS export names for ESM import in node:
72
+ 0 && (module.exports = {
73
+ ssrDataLoaderPlugin
74
+ });
@@ -0,0 +1,106 @@
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
+ route.element = routes.element;
77
+ route.Component = routes.Component;
78
+ return;
79
+ }
80
+ (_route_children = route.children) === null || _route_children === void 0 ? void 0 : _route_children.forEach((r) => {
81
+ traverse(r);
82
+ });
83
+ };
84
+ Object.keys(initialRoutes).forEach((entryName) => {
85
+ const routes = initialRoutes[entryName];
86
+ if (Array.isArray(routes)) {
87
+ routes.forEach((route) => {
88
+ traverse(route);
89
+ });
90
+ } else {
91
+ var _routes_routes;
92
+ routes === null || routes === void 0 ? void 0 : (_routes_routes = routes.routes) === null || _routes_routes === void 0 ? void 0 : _routes_routes.forEach((r) => {
93
+ traverse(r);
94
+ });
95
+ }
96
+ });
97
+ }
98
+ // Annotate the CommonJS export names for ESM import in node:
99
+ 0 && (module.exports = {
100
+ decodeId,
101
+ getRemoteId,
102
+ getRemoteLayoutId,
103
+ getRemoteRoutesInfos,
104
+ injectRemoteRoutes,
105
+ transformName2Prefix
106
+ });
@@ -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
  });
@@ -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;
@@ -31,18 +31,18 @@ __export(plugin_exports, {
31
31
  mfSSRPlugin: () => mfSSRPlugin
32
32
  });
33
33
  module.exports = __toCommonJS(plugin_exports);
34
- var import_jsx_runtime = require("react/jsx-runtime");
35
- var import_hoist_non_react_statics = __toESM(require("hoist-non-react-statics"));
36
- var import_SSRLiveReload = require("./SSRLiveReload");
37
- const mfSSRPlugin = () => ({
34
+ console.log("mfSSRPlugin trigger");
35
+ const mfSSRPlugin = ({ metaName }) => ({
38
36
  name: "@module-federation/modern-js",
37
+ pre: [
38
+ `@${metaName}/plugin-router`
39
+ ],
39
40
  setup: () => {
40
41
  return {
41
- async init({ context }, next) {
42
+ async beforeRender() {
43
+ console.log("live reload beforeRender");
42
44
  if (typeof window !== "undefined") {
43
- return next({
44
- context
45
- });
45
+ return;
46
46
  }
47
47
  globalThis.shouldUpdate = false;
48
48
  const nodeUtils = await Promise.resolve().then(() => __toESM(require("@module-federation/node/utils")));
@@ -52,20 +52,7 @@ const mfSSRPlugin = () => ({
52
52
  await nodeUtils.flushChunks();
53
53
  globalThis.shouldUpdate = true;
54
54
  }
55
- return next({
56
- context
57
- });
58
- },
59
- wrapRoot(App) {
60
- const AppWrapper = (props) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
61
- children: [
62
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_SSRLiveReload.SSRLiveReload, {}),
63
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, {
64
- ...props
65
- })
66
- ]
67
- });
68
- return (0, import_hoist_non_react_statics.default)(AppWrapper, App);
55
+ return;
69
56
  }
70
57
  };
71
58
  }
@@ -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
+ };
@@ -0,0 +1,108 @@
1
+ import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
2
+ import fs from "fs";
3
+ import traverse from "@babel/traverse";
4
+ import * as babelParser from "@babel/parser";
5
+ import generate from "@babel/generator";
6
+ import * as t from "@babel/types";
7
+ function findTargetKeyNode(nodeProperties, key) {
8
+ return nodeProperties.find(function(p) {
9
+ return t.isObjectProperty(p) && t.isStringLiteral(p.key) && p.key.value === key;
10
+ });
11
+ }
12
+ function generateRoutes(param) {
13
+ var sourceCode = param.sourceCode, filePath = param.filePath;
14
+ var ast = babelParser.parse(sourceCode, {
15
+ sourceType: "module"
16
+ });
17
+ var lazyComponentDeclarations = [];
18
+ var componentDeclarations = [];
19
+ var componentId = 0;
20
+ traverse(ast, {
21
+ // ImportDeclaration(path) {
22
+ // const source = path.node.source.value;
23
+ // const routeIdMatch = source.match(/routeId=([^&]+)/);
24
+ // if (routeIdMatch) {
25
+ // const originalRouteId = routeIdMatch[1];
26
+ // const newRouteId = `${prefix}${originalRouteId}`;
27
+ // const newSource = source.replace(
28
+ // /routeId=[^&]+/,
29
+ // `routeId=${newRouteId}`,
30
+ // );
31
+ // path.node.source = t.stringLiteral(newSource);
32
+ // }
33
+ // },
34
+ ObjectExpression: function ObjectExpression(path) {
35
+ var componentName = "";
36
+ var lazyComponentName = "";
37
+ if (!Array.isArray(path.node.properties)) {
38
+ return;
39
+ }
40
+ var idNode = findTargetKeyNode(path.node.properties, "id");
41
+ if (idNode && t.isObjectProperty(idNode) && t.isStringLiteral(idNode.value)) {
42
+ }
43
+ var isRootNode = findTargetKeyNode(path.node.properties, "isRoot");
44
+ if (isRootNode && t.isObjectProperty(isRootNode) && t.isBooleanLiteral(isRootNode.value)) {
45
+ isRootNode.value.value = false;
46
+ }
47
+ if (!isRootNode) {
48
+ var lazyComponentNode = findTargetKeyNode(path.node.properties, "lazyImport");
49
+ if (lazyComponentNode && t.isObjectProperty(lazyComponentNode) && t.isArrowFunctionExpression(lazyComponentNode.value)) {
50
+ lazyComponentName = "LazyComponent_".concat(componentId);
51
+ var lazyDeclaration = t.variableDeclaration("const", [
52
+ t.variableDeclarator(t.identifier(lazyComponentName), lazyComponentNode.value)
53
+ ]);
54
+ lazyComponentNode.value = t.identifier(lazyComponentName);
55
+ var componentNode = findTargetKeyNode(path.node.properties, "component");
56
+ if (componentNode && t.isObjectProperty(componentNode) && t.isCallExpression(componentNode.value) && t.isIdentifier(componentNode.value.callee)) {
57
+ componentNode.value = t.callExpression(t.identifier("lazy"), [
58
+ t.identifier(lazyComponentName)
59
+ ]);
60
+ }
61
+ lazyComponentDeclarations.push(lazyDeclaration);
62
+ }
63
+ }
64
+ var componentNode1 = findTargetKeyNode(path.node.properties, "component");
65
+ if (componentNode1 && t.isObjectProperty(componentNode1) && t.isCallExpression(componentNode1.value) && t.isIdentifier(componentNode1.value.callee)) {
66
+ componentName = "Component_".concat(componentId);
67
+ var componentDeclaration = t.variableDeclaration("const", [
68
+ t.variableDeclarator(t.identifier(componentName), lazyComponentName ? t.callExpression(t.identifier("lazy"), [
69
+ t.identifier(lazyComponentName)
70
+ ]) : componentNode1.value)
71
+ ]);
72
+ componentDeclarations.push(componentDeclaration);
73
+ componentNode1.value = t.identifier(componentName);
74
+ }
75
+ if (lazyComponentName || componentName) {
76
+ componentId++;
77
+ if (componentName) {
78
+ var upperFirstName = componentName.slice(0, 1).toUpperCase() + componentName.slice(1);
79
+ var jsxElement = t.jsxElement(t.jsxOpeningElement(t.jsxIdentifier(upperFirstName), [], true), null, [], true);
80
+ path.node.properties.push(t.objectProperty(t.identifier("element"), jsxElement));
81
+ }
82
+ }
83
+ }
84
+ });
85
+ traverse(ast, {
86
+ Program: function Program(path) {
87
+ var lastImportIndex = path.get("body").reduce(function(lastIndex, p, index) {
88
+ if (t.isImportDeclaration(p.node)) {
89
+ lastIndex = index;
90
+ }
91
+ return lastIndex;
92
+ }, -1);
93
+ if (lastImportIndex >= 0) {
94
+ var lastImport = path.get("body.".concat(lastImportIndex));
95
+ _to_consumable_array(componentDeclarations).concat(_to_consumable_array(lazyComponentDeclarations)).forEach(function(declaration) {
96
+ if ("insertAfter" in lastImport) {
97
+ lastImport.insertAfter(declaration);
98
+ }
99
+ });
100
+ }
101
+ }
102
+ });
103
+ var code = generate(ast).code;
104
+ fs.writeFileSync(filePath, code);
105
+ }
106
+ export {
107
+ generateRoutes
108
+ };
@@ -0,0 +1,4 @@
1
+ import { generateRoutes } from "./generateRoutes";
2
+ export {
3
+ generateRoutes
4
+ };
@@ -0,0 +1,34 @@
1
+ import { _ as _type_of } from "@swc/helpers/_/_type_of";
2
+ function clearMFCache() {
3
+ if (!globalThis.__FEDERATION__) {
4
+ console.log("clearMFCache no globalThis.__FEDERATION__");
5
+ return;
6
+ }
7
+ globalThis.__FEDERATION__.__INSTANCES__.map(function(i) {
8
+ i.moduleCache.forEach(function(mc) {
9
+ if (mc.remoteInfo && mc.remoteInfo.entryGlobalName) {
10
+ delete globalThis[mc.remoteInfo.entryGlobalName];
11
+ }
12
+ });
13
+ i.moduleCache.clear();
14
+ if (globalThis[i.name]) {
15
+ delete globalThis[i.name];
16
+ }
17
+ });
18
+ Object.keys(globalThis.__FEDERATION__).forEach(function(key) {
19
+ if (Array.isArray(globalThis.__FEDERATION__[key])) {
20
+ globalThis.__FEDERATION__[key] = [];
21
+ } else if (key === "__PRELOADED_MAP__") {
22
+ globalThis.__FEDERATION__[key] = /* @__PURE__ */ new Map();
23
+ } else if (_type_of(globalThis.__FEDERATION__[key]) === "object") {
24
+ globalThis.__FEDERATION__[key] = {};
25
+ }
26
+ });
27
+ if (globalThis.__GLOBAL_LOADING_REMOTE_ENTRY__) {
28
+ globalThis.__GLOBAL_LOADING_REMOTE_ENTRY__ = {};
29
+ }
30
+ globalThis.FORCE_MF_REFRESH = true;
31
+ }
32
+ export {
33
+ clearMFCache
34
+ };