@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,115 +0,0 @@
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
- });
@@ -1,16 +0,0 @@
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);
@@ -1,16 +0,0 @@
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);
@@ -1,13 +0,0 @@
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
- };
@@ -1,18 +0,0 @@
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
- };
@@ -1,110 +0,0 @@
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
- var lazyComponentNode = findTargetKeyNode(path.node.properties, "lazyImport");
48
- if (lazyComponentNode && t.isObjectProperty(lazyComponentNode) && t.isArrowFunctionExpression(lazyComponentNode.value)) {
49
- lazyComponentName = "LazyComponent_".concat(componentId);
50
- var lazyDeclaration = t.variableDeclaration("const", [
51
- t.variableDeclarator(t.identifier(lazyComponentName), lazyComponentNode.value)
52
- ]);
53
- lazyComponentNode.value = t.identifier(lazyComponentName);
54
- var componentNode = findTargetKeyNode(path.node.properties, "component");
55
- if (componentNode && t.isObjectProperty(componentNode) && t.isCallExpression(componentNode.value) && t.isIdentifier(componentNode.value.callee)) {
56
- componentNode.value = t.callExpression(t.identifier("lazy"), [
57
- t.identifier(lazyComponentName)
58
- ]);
59
- }
60
- lazyComponentDeclarations.push(lazyDeclaration);
61
- }
62
- var componentNode1 = findTargetKeyNode(path.node.properties, "component");
63
- if (componentNode1 && t.isObjectProperty(componentNode1) && t.isCallExpression(componentNode1.value) && t.isIdentifier(componentNode1.value.callee)) {
64
- componentName = "Component_".concat(componentId);
65
- var componentDeclaration = t.variableDeclaration("const", [
66
- t.variableDeclarator(t.identifier(componentName), lazyComponentName ? t.callExpression(t.identifier("lazy"), [
67
- t.identifier(lazyComponentName)
68
- ]) : componentNode1.value)
69
- ]);
70
- componentDeclarations.push(componentDeclaration);
71
- componentNode1.value = t.identifier(componentName);
72
- }
73
- if (lazyComponentName || componentName) {
74
- componentId++;
75
- if (componentName) {
76
- var upperFirstName = componentName.slice(0, 1).toUpperCase() + componentName.slice(1);
77
- var jsxElement = t.jsxElement(t.jsxOpeningElement(t.jsxIdentifier(upperFirstName), [], true), null, [], true);
78
- path.node.properties.push(t.objectProperty(t.identifier("element"), jsxElement));
79
- } else {
80
- path.node.properties.push(t.objectProperty(t.identifier("Component"), t.callExpression(t.identifier("lazy"), [
81
- t.identifier(lazyComponentName)
82
- ])));
83
- }
84
- }
85
- }
86
- });
87
- traverse(ast, {
88
- Program: function Program(path) {
89
- var lastImportIndex = path.get("body").reduce(function(lastIndex, p, index) {
90
- if (t.isImportDeclaration(p.node)) {
91
- lastIndex = index;
92
- }
93
- return lastIndex;
94
- }, -1);
95
- if (lastImportIndex >= 0) {
96
- var lastImport = path.get("body.".concat(lastImportIndex));
97
- _to_consumable_array(componentDeclarations).concat(_to_consumable_array(lazyComponentDeclarations)).forEach(function(declaration) {
98
- if ("insertAfter" in lastImport) {
99
- lastImport.insertAfter(declaration);
100
- }
101
- });
102
- }
103
- }
104
- });
105
- var code = generate(ast).code;
106
- fs.writeFileSync(filePath, code);
107
- }
108
- export {
109
- generateRoutes
110
- };
@@ -1,4 +0,0 @@
1
- import { generateRoutes } from "./generateRoutes";
2
- export {
3
- generateRoutes
4
- };
@@ -1,34 +0,0 @@
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
- };
@@ -1,79 +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 { META_NAME } from "../../constant";
4
- import { addExpose } from "./utils";
5
- var moduleFederationExportRoutePlugin = function(param) {
6
- var userConfig = param.userConfig, internalOptions = param.internalOptions, entries = param.entries;
7
- return {
8
- name: "@modern-js/plugin-module-federation-export-routes",
9
- pre: [
10
- "@modern-js/plugin-module-federation-route"
11
- ],
12
- post: [
13
- "@modern-js/plugin-router",
14
- "@modern-js/plugin-module-federation"
15
- ],
16
- setup: function() {
17
- var _ref = _async_to_generator(function(param2) {
18
- var useAppContext, appContext, _internalOptions_metaName, metaName, internalDirectory;
19
- return _ts_generator(this, function(_state) {
20
- useAppContext = param2.useAppContext;
21
- if (!userConfig.exportRoutes) {
22
- return [
23
- 2
24
- ];
25
- }
26
- appContext = useAppContext();
27
- _internalOptions_metaName = internalOptions.metaName, metaName = _internalOptions_metaName === void 0 ? META_NAME : _internalOptions_metaName;
28
- internalDirectory = appContext.internalDirectory.replace(META_NAME, metaName || META_NAME);
29
- return [
30
- 2,
31
- {
32
- config: /* @__PURE__ */ _async_to_generator(function() {
33
- return _ts_generator(this, function(_state2) {
34
- return [
35
- 2,
36
- {
37
- tools: {
38
- // bundlerChain can not keep target order
39
- rspack: function rspack(_config, param3) {
40
- var isServer = param3.isServer;
41
- addExpose({
42
- mfConfig: isServer ? internalOptions.ssrConfig : internalOptions.csrConfig,
43
- metaName,
44
- isServer,
45
- internalDirectory,
46
- entries
47
- });
48
- },
49
- // bundlerChain can not keep target order
50
- webpack: function webpack(_config, param3) {
51
- var isServer = param3.isServer;
52
- addExpose({
53
- mfConfig: isServer ? internalOptions.ssrConfig : internalOptions.csrConfig,
54
- metaName,
55
- isServer,
56
- internalDirectory,
57
- entries
58
- });
59
- }
60
- }
61
- }
62
- ];
63
- });
64
- })
65
- }
66
- ];
67
- });
68
- });
69
- return function(_) {
70
- return _ref.apply(this, arguments);
71
- };
72
- }()
73
- };
74
- };
75
- var exportRoutePlugin_default = moduleFederationExportRoutePlugin;
76
- export {
77
- exportRoutePlugin_default as default,
78
- moduleFederationExportRoutePlugin
79
- };
@@ -1,122 +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
- import { META_NAME } from "../../constant";
6
- import { clearMFCache } from "./clearMFCache";
7
- function _transformRuntimeOptions(buildOptions) {
8
- var remotes = buildOptions.remotes || {};
9
- var runtimeRemotes = Object.entries(remotes).map(function(remote) {
10
- var _remote = _sliced_to_array(remote, 2), alias = _remote[0], nameAndEntry = _remote[1];
11
- var _nameAndEntry_split = _sliced_to_array(nameAndEntry.split("@"), 2), name = _nameAndEntry_split[0], entry = _nameAndEntry_split[1];
12
- return {
13
- name,
14
- entry,
15
- alias
16
- };
17
- });
18
- return {
19
- name: buildOptions.name,
20
- remotes: runtimeRemotes
21
- };
22
- }
23
- var moduleFederationImportRoutePlugin = function(param) {
24
- var userConfig = param.userConfig, internalOptions = param.internalOptions, remotePathMap = param.remotePathMap, _param_serverPlugin = param.serverPlugin, serverPlugin = _param_serverPlugin === void 0 ? "@module-federation/modern-js/fetch-router-server-plugin" : _param_serverPlugin, ssrByRouteIdsMap = param.ssrByRouteIdsMap, transformRuntimeOptions = param.transformRuntimeOptions;
25
- return {
26
- name: "@modern-js/plugin-module-federation-import-routes",
27
- pre: [
28
- "@modern-js/plugin-module-federation-route"
29
- ],
30
- post: [
31
- "@modern-js/plugin-router",
32
- "@modern-js/plugin-module-federation"
33
- ],
34
- setup: /* @__PURE__ */ _async_to_generator(function() {
35
- var _internalOptions_metaName, metaName, transformRuntimeFn, dataLoaderRemotes, serverPluginOptions, hasDataLoaderRemotes;
36
- return _ts_generator(this, function(_state) {
37
- if (!userConfig.importRoutes) {
38
- return [
39
- 2
40
- ];
41
- }
42
- _internalOptions_metaName = internalOptions.metaName, metaName = _internalOptions_metaName === void 0 ? META_NAME : _internalOptions_metaName;
43
- transformRuntimeFn = transformRuntimeOptions || _transformRuntimeOptions;
44
- dataLoaderRemotes = _to_consumable_array(new Set(Object.values(remotePathMap).map(function(i) {
45
- return i.name;
46
- })));
47
- serverPluginOptions = {
48
- runtimeOptions: transformRuntimeFn(internalOptions.csrConfig),
49
- dataLoaderRemotes,
50
- ssrByRouteIdsMap
51
- };
52
- hasDataLoaderRemotes = function() {
53
- return Boolean(serverPluginOptions.dataLoaderRemotes.length);
54
- };
55
- return [
56
- 2,
57
- {
58
- _internalRuntimePlugins: function(param2) {
59
- var entrypoint = param2.entrypoint, plugins = param2.plugins;
60
- if (!hasDataLoaderRemotes()) {
61
- return {
62
- entrypoint,
63
- plugins
64
- };
65
- }
66
- plugins.push({
67
- name: "ssrDataLoader",
68
- path: "@module-federation/modern-js/routes",
69
- config: {
70
- metaName,
71
- dataLoaderRemotes
72
- }
73
- });
74
- plugins.push({
75
- name: "ssrDataLoaderInjectAssets",
76
- path: "@module-federation/modern-js/routes-inject-assets",
77
- config: {
78
- metaName,
79
- dataLoaderRemotes
80
- }
81
- });
82
- return {
83
- entrypoint,
84
- plugins
85
- };
86
- },
87
- _internalServerPlugins: function _internalServerPlugins(param2) {
88
- var plugins = param2.plugins;
89
- if (!hasDataLoaderRemotes()) {
90
- return {
91
- plugins
92
- };
93
- }
94
- plugins.push({
95
- name: serverPlugin,
96
- options: serverPluginOptions
97
- });
98
- return {
99
- plugins
100
- };
101
- },
102
- afterDev: function afterDev() {
103
- return _async_to_generator(function() {
104
- return _ts_generator(this, function(_state2) {
105
- clearMFCache();
106
- return [
107
- 2
108
- ];
109
- });
110
- })();
111
- }
112
- }
113
- ];
114
- });
115
- })
116
- };
117
- };
118
- var importRoutesPlugin_default = moduleFederationImportRoutePlugin;
119
- export {
120
- importRoutesPlugin_default as default,
121
- moduleFederationImportRoutePlugin
122
- };