@module-federation/modern-js 0.0.0-next-20250616092616 → 0.0.0-next-20250616190501

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 (90) hide show
  1. package/package.json +16 -9
  2. package/dist/LICENSE +0 -21
  3. package/dist/cjs/cli/configPlugin.js +0 -381
  4. package/dist/cjs/cli/configPlugin.spec.js +0 -114
  5. package/dist/cjs/cli/index.js +0 -95
  6. package/dist/cjs/cli/mfRuntimePlugins/inject-node-fetch.js +0 -44
  7. package/dist/cjs/cli/mfRuntimePlugins/resolve-entry-ipv4.js +0 -82
  8. package/dist/cjs/cli/mfRuntimePlugins/shared-strategy.js +0 -43
  9. package/dist/cjs/cli/server/data-fetch-server-plugin.js +0 -188
  10. package/dist/cjs/cli/ssrPlugin.js +0 -236
  11. package/dist/cjs/cli/utils.js +0 -90
  12. package/dist/cjs/constant.js +0 -31
  13. package/dist/cjs/interfaces/bundler.js +0 -16
  14. package/dist/cjs/logger.js +0 -27
  15. package/dist/cjs/runtime/index.js +0 -33
  16. package/dist/cjs/server/fileCache.js +0 -84
  17. package/dist/cjs/server/fileCache.spec.js +0 -28
  18. package/dist/cjs/server/index.js +0 -58
  19. package/dist/cjs/server/staticMiddleware.js +0 -77
  20. package/dist/cjs/server/staticMiddleware.spec.js +0 -185
  21. package/dist/cjs/ssr-runtime/SSRLiveReload.js +0 -43
  22. package/dist/cjs/ssr-runtime/devPlugin.js +0 -71
  23. package/dist/cjs/ssr-runtime/injectDataFetchFunctionPlugin.js +0 -41
  24. package/dist/cjs/types/index.js +0 -16
  25. package/dist/esm/cli/configPlugin.js +0 -388
  26. package/dist/esm/cli/configPlugin.spec.js +0 -110
  27. package/dist/esm/cli/index.js +0 -90
  28. package/dist/esm/cli/mfRuntimePlugins/inject-node-fetch.js +0 -16
  29. package/dist/esm/cli/mfRuntimePlugins/resolve-entry-ipv4.js +0 -74
  30. package/dist/esm/cli/mfRuntimePlugins/shared-strategy.js +0 -25
  31. package/dist/esm/cli/server/data-fetch-server-plugin.js +0 -236
  32. package/dist/esm/cli/ssrPlugin.js +0 -219
  33. package/dist/esm/cli/utils.js +0 -53
  34. package/dist/esm/constant.js +0 -6
  35. package/dist/esm/interfaces/bundler.js +0 -0
  36. package/dist/esm/logger.js +0 -7
  37. package/dist/esm/runtime/index.js +0 -6
  38. package/dist/esm/server/fileCache.js +0 -98
  39. package/dist/esm/server/fileCache.spec.js +0 -50
  40. package/dist/esm/server/index.js +0 -36
  41. package/dist/esm/server/staticMiddleware.js +0 -81
  42. package/dist/esm/server/staticMiddleware.spec.js +0 -328
  43. package/dist/esm/ssr-runtime/SSRLiveReload.js +0 -26
  44. package/dist/esm/ssr-runtime/devPlugin.js +0 -73
  45. package/dist/esm/ssr-runtime/injectDataFetchFunctionPlugin.js +0 -35
  46. package/dist/esm/types/index.js +0 -0
  47. package/dist/esm-node/cli/configPlugin.js +0 -340
  48. package/dist/esm-node/cli/configPlugin.spec.js +0 -91
  49. package/dist/esm-node/cli/index.js +0 -70
  50. package/dist/esm-node/cli/mfRuntimePlugins/inject-node-fetch.js +0 -14
  51. package/dist/esm-node/cli/mfRuntimePlugins/resolve-entry-ipv4.js +0 -62
  52. package/dist/esm-node/cli/mfRuntimePlugins/shared-strategy.js +0 -23
  53. package/dist/esm-node/cli/server/data-fetch-server-plugin.js +0 -158
  54. package/dist/esm-node/cli/ssrPlugin.js +0 -200
  55. package/dist/esm-node/cli/utils.js +0 -53
  56. package/dist/esm-node/constant.js +0 -6
  57. package/dist/esm-node/interfaces/bundler.js +0 -0
  58. package/dist/esm-node/logger.js +0 -7
  59. package/dist/esm-node/runtime/index.js +0 -6
  60. package/dist/esm-node/server/fileCache.js +0 -49
  61. package/dist/esm-node/server/fileCache.spec.js +0 -27
  62. package/dist/esm-node/server/index.js +0 -34
  63. package/dist/esm-node/server/staticMiddleware.js +0 -43
  64. package/dist/esm-node/server/staticMiddleware.spec.js +0 -162
  65. package/dist/esm-node/ssr-runtime/SSRLiveReload.js +0 -19
  66. package/dist/esm-node/ssr-runtime/devPlugin.js +0 -37
  67. package/dist/esm-node/ssr-runtime/injectDataFetchFunctionPlugin.js +0 -17
  68. package/dist/esm-node/types/index.js +0 -0
  69. package/dist/types/cli/configPlugin.d.ts +0 -21
  70. package/dist/types/cli/configPlugin.spec.d.ts +0 -1
  71. package/dist/types/cli/index.d.ts +0 -6
  72. package/dist/types/cli/mfRuntimePlugins/inject-node-fetch.d.ts +0 -3
  73. package/dist/types/cli/mfRuntimePlugins/resolve-entry-ipv4.d.ts +0 -3
  74. package/dist/types/cli/mfRuntimePlugins/shared-strategy.d.ts +0 -3
  75. package/dist/types/cli/server/data-fetch-server-plugin.d.ts +0 -3
  76. package/dist/types/cli/ssrPlugin.d.ts +0 -6
  77. package/dist/types/cli/utils.d.ts +0 -6
  78. package/dist/types/constant.d.ts +0 -2
  79. package/dist/types/interfaces/bundler.d.ts +0 -18
  80. package/dist/types/logger.d.ts +0 -2
  81. package/dist/types/runtime/index.d.ts +0 -3
  82. package/dist/types/server/fileCache.d.ts +0 -14
  83. package/dist/types/server/fileCache.spec.d.ts +0 -1
  84. package/dist/types/server/index.d.ts +0 -4
  85. package/dist/types/server/staticMiddleware.d.ts +0 -6
  86. package/dist/types/server/staticMiddleware.spec.d.ts +0 -1
  87. package/dist/types/ssr-runtime/SSRLiveReload.d.ts +0 -1
  88. package/dist/types/ssr-runtime/devPlugin.d.ts +0 -2
  89. package/dist/types/ssr-runtime/injectDataFetchFunctionPlugin.d.ts +0 -4
  90. package/dist/types/types/index.d.ts +0 -24
@@ -1,44 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var inject_node_fetch_exports = {};
30
- __export(inject_node_fetch_exports, {
31
- default: () => inject_node_fetch_default
32
- });
33
- module.exports = __toCommonJS(inject_node_fetch_exports);
34
- var import_node_fetch = __toESM(require("node-fetch"));
35
- const injectNodeFetchPlugin = () => ({
36
- name: "inject-node-fetch-plugin",
37
- beforeInit(args) {
38
- if (!globalThis.fetch) {
39
- globalThis.fetch = import_node_fetch.default;
40
- }
41
- return args;
42
- }
43
- });
44
- var inject_node_fetch_default = injectNodeFetchPlugin;
@@ -1,82 +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 resolve_entry_ipv4_exports = {};
20
- __export(resolve_entry_ipv4_exports, {
21
- default: () => resolve_entry_ipv4_default
22
- });
23
- module.exports = __toCommonJS(resolve_entry_ipv4_exports);
24
- var import_constant = require("../../constant");
25
- const ipv4 = typeof FEDERATION_IPV4 !== "undefined" ? FEDERATION_IPV4 : "127.0.0.1";
26
- const remoteIpStrategy = typeof REMOTE_IP_STRATEGY !== "undefined" ? REMOTE_IP_STRATEGY : "inherit";
27
- function replaceObjectLocalhost(key, obj) {
28
- if (remoteIpStrategy !== "ipv4") {
29
- return;
30
- }
31
- if (!(key in obj)) {
32
- return;
33
- }
34
- const remote = obj[key];
35
- if (remote && typeof remote === "string" && remote.includes(import_constant.LOCALHOST)) {
36
- obj[key] = replaceLocalhost(remote);
37
- }
38
- }
39
- function replaceLocalhost(url) {
40
- return url.replace(import_constant.LOCALHOST, ipv4);
41
- }
42
- const resolveEntryIpv4Plugin = () => ({
43
- name: "resolve-entry-ipv4",
44
- beforeRegisterRemote(args) {
45
- const { remote } = args;
46
- replaceObjectLocalhost("entry", remote);
47
- return args;
48
- },
49
- async afterResolve(args) {
50
- const { remoteInfo } = args;
51
- replaceObjectLocalhost("entry", remoteInfo);
52
- return args;
53
- },
54
- beforeLoadRemoteSnapshot(args) {
55
- const { moduleInfo } = args;
56
- if ("entry" in moduleInfo) {
57
- replaceObjectLocalhost("entry", moduleInfo);
58
- return args;
59
- }
60
- if ("version" in moduleInfo) {
61
- replaceObjectLocalhost("version", moduleInfo);
62
- }
63
- return args;
64
- },
65
- loadRemoteSnapshot(args) {
66
- const { remoteSnapshot } = args;
67
- if ("publicPath" in remoteSnapshot) {
68
- replaceObjectLocalhost("publicPath", remoteSnapshot);
69
- }
70
- if ("getPublicPath" in remoteSnapshot) {
71
- replaceObjectLocalhost("getPublicPath", remoteSnapshot);
72
- }
73
- if (remoteSnapshot.remotesInfo) {
74
- Object.keys(remoteSnapshot.remotesInfo).forEach((key) => {
75
- const remoteInfo = remoteSnapshot.remotesInfo[key];
76
- replaceObjectLocalhost("matchedVersion", remoteInfo);
77
- });
78
- }
79
- return args;
80
- }
81
- });
82
- var resolve_entry_ipv4_default = resolveEntryIpv4Plugin;
@@ -1,43 +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 shared_strategy_exports = {};
20
- __export(shared_strategy_exports, {
21
- default: () => shared_strategy_default
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
- }
42
- });
43
- var shared_strategy_default = sharedStrategy;
@@ -1,188 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var data_fetch_server_plugin_exports = {};
30
- __export(data_fetch_server_plugin_exports, {
31
- default: () => data_fetch_server_plugin_default
32
- });
33
- module.exports = __toCommonJS(data_fetch_server_plugin_exports);
34
- var import_data_fetch_constant = require("@module-federation/bridge-react/data-fetch-constant");
35
- var import_data_fetch_utils = require("@module-federation/bridge-react/data-fetch-utils");
36
- var import_sdk = require("@module-federation/sdk");
37
- var import_logger = __toESM(require("../../logger"));
38
- function wrapSetTimeout(targetPromise, delay = 2e4, id) {
39
- if (targetPromise && typeof targetPromise.then === "function") {
40
- return new Promise((resolve, reject) => {
41
- const timeoutId = setTimeout(() => {
42
- import_logger.default.warn(`Data fetch for ID ${id} timed out after 20 seconds.`);
43
- reject(new Error(`Data fetch for ID ${id} timed out after 20 seconds`));
44
- }, delay);
45
- targetPromise.then((value) => {
46
- clearTimeout(timeoutId);
47
- resolve(value);
48
- }).catch((err) => {
49
- clearTimeout(timeoutId);
50
- reject(err);
51
- });
52
- });
53
- }
54
- }
55
- function addProtocol(url) {
56
- if (url.startsWith("//")) {
57
- return "https:" + url;
58
- }
59
- return url;
60
- }
61
- const getDecodeQuery = (url, name) => {
62
- const res = url.searchParams.get(name);
63
- if (!res) {
64
- return null;
65
- }
66
- return decodeURIComponent(res);
67
- };
68
- const middleware = async (ctx, next) => {
69
- var _globalThis___FEDERATION__;
70
- let url;
71
- let dataFetchId;
72
- let params;
73
- let remoteInfo;
74
- try {
75
- url = new URL(ctx.req.url);
76
- dataFetchId = getDecodeQuery(url, import_data_fetch_constant.DATA_FETCH_QUERY);
77
- params = JSON.parse(getDecodeQuery(url, "params") || "{}");
78
- const remoteInfoQuery = getDecodeQuery(url, "remoteInfo");
79
- remoteInfo = remoteInfoQuery ? JSON.parse(remoteInfoQuery) : null;
80
- } catch (e) {
81
- import_logger.default.error("fetch data from server, error: ", e);
82
- return next();
83
- }
84
- if (!dataFetchId) {
85
- return next();
86
- }
87
- import_logger.default.log("fetch data from server, dataFetchId: ", dataFetchId);
88
- import_logger.default.debug("fetch data from server, moduleInfo: ", (_globalThis___FEDERATION__ = globalThis.__FEDERATION__) === null || _globalThis___FEDERATION__ === void 0 ? void 0 : _globalThis___FEDERATION__.moduleInfo);
89
- try {
90
- var _dataFetchMap_dataFetchId, _dataFetchMap_dataFetchId1;
91
- const dataFetchMap = (0, import_data_fetch_utils.getDataFetchMap)();
92
- if (!dataFetchMap) {
93
- (0, import_data_fetch_utils.initDataFetchMap)();
94
- }
95
- const fetchDataPromise = (_dataFetchMap_dataFetchId = dataFetchMap[dataFetchId]) === null || _dataFetchMap_dataFetchId === void 0 ? void 0 : _dataFetchMap_dataFetchId[1];
96
- import_logger.default.debug("fetch data from server, fetchDataPromise: ", fetchDataPromise);
97
- if (fetchDataPromise && ((_dataFetchMap_dataFetchId1 = dataFetchMap[dataFetchId]) === null || _dataFetchMap_dataFetchId1 === void 0 ? void 0 : _dataFetchMap_dataFetchId1[2]) !== import_data_fetch_constant.MF_DATA_FETCH_STATUS.ERROR) {
98
- const targetPromise = fetchDataPromise[0];
99
- const wrappedPromise = wrapSetTimeout(targetPromise, 2e4, dataFetchId);
100
- if (wrappedPromise) {
101
- const res = await wrappedPromise;
102
- import_logger.default.log("fetch data from server, fetchDataPromise res: ", res);
103
- return ctx.json(res);
104
- }
105
- import_logger.default.error(`Expected a Promise from fetchDataPromise[0] for dataFetchId ${dataFetchId}, but received:`, targetPromise, "Will try call new dataFetch again...");
106
- }
107
- if (remoteInfo) {
108
- try {
109
- const hostInstance2 = globalThis.__FEDERATION__.__INSTANCES__[0];
110
- const remoteEntry = `${addProtocol(remoteInfo.ssrPublicPath) + remoteInfo.ssrRemoteEntry}`;
111
- if (!hostInstance2) {
112
- throw new Error("host instance not found!");
113
- }
114
- const remote = hostInstance2.options.remotes.find((remote2) => remote2.name === remoteInfo.name);
115
- import_logger.default.debug("find remote: ", JSON.stringify(remote));
116
- if (!remote) {
117
- hostInstance2.registerRemotes([
118
- {
119
- name: remoteInfo.name,
120
- entry: remoteEntry,
121
- entryGlobalName: remoteInfo.globalName
122
- }
123
- ]);
124
- } else if (!("entry" in remote) || !remote.entry.includes(import_sdk.MANIFEST_EXT)) {
125
- const { hostGlobalSnapshot, remoteSnapshot } = hostInstance2.snapshotHandler.getGlobalRemoteInfo(remoteInfo);
126
- import_logger.default.debug("find hostGlobalSnapshot: ", JSON.stringify(hostGlobalSnapshot));
127
- import_logger.default.debug("find remoteSnapshot: ", JSON.stringify(remoteSnapshot));
128
- if (!hostGlobalSnapshot || !remoteSnapshot) {
129
- if ("version" in remote) {
130
- delete remote.version;
131
- }
132
- remote.entry = remoteEntry;
133
- remote.entryGlobalName = remoteInfo.globalName;
134
- }
135
- }
136
- } catch (e) {
137
- ctx.status(500);
138
- return ctx.text(`failed to fetch ${remoteInfo.name} data, error:
139
- ${e}`);
140
- }
141
- }
142
- const dataFetchItem = dataFetchMap[dataFetchId];
143
- import_logger.default.debug("fetch data from server, dataFetchItem: ", dataFetchItem);
144
- if (dataFetchItem) {
145
- const callFetchDataPromise = (0, import_data_fetch_utils.fetchData)(dataFetchId, {
146
- ...params,
147
- isDowngrade: !remoteInfo
148
- });
149
- const wrappedPromise = wrapSetTimeout(callFetchDataPromise, 2e4, dataFetchId);
150
- if (wrappedPromise) {
151
- const res = await wrappedPromise;
152
- import_logger.default.log("fetch data from server, dataFetchItem res: ", res);
153
- return ctx.json(res);
154
- }
155
- }
156
- const remoteId = dataFetchId.split(import_sdk.SEPARATOR)[0];
157
- const hostInstance = globalThis.__FEDERATION__.__INSTANCES__[0];
158
- if (!hostInstance) {
159
- throw new Error("host instance not found!");
160
- }
161
- const dataFetchFn = await (0, import_data_fetch_utils.loadDataFetchModule)(hostInstance, remoteId);
162
- const data = await dataFetchFn({
163
- ...params,
164
- isDowngrade: !remoteInfo
165
- });
166
- import_logger.default.log("fetch data from server, loadDataFetchModule res: ", data);
167
- return ctx.json(data);
168
- } catch (e) {
169
- import_logger.default.error("server plugin data fetch error: ", e);
170
- ctx.status(500);
171
- return ctx.text(`failed to fetch ${remoteInfo.name} data, error:
172
- ${e}`);
173
- }
174
- };
175
- const dataFetchServePlugin = () => ({
176
- name: "mf-data-fetch-server-plugin",
177
- setup: (api) => {
178
- api.onPrepare(() => {
179
- const { middlewares } = api.getServerContext();
180
- middlewares.push({
181
- name: "module-federation-serve-manifest",
182
- // @ts-ignore type error
183
- handler: middleware
184
- });
185
- });
186
- }
187
- });
188
- var data_fetch_server_plugin_default = dataFetchServePlugin;
@@ -1,236 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var ssrPlugin_exports = {};
30
- __export(ssrPlugin_exports, {
31
- CHAIN_MF_PLUGIN_ID: () => CHAIN_MF_PLUGIN_ID,
32
- default: () => ssrPlugin_default,
33
- moduleFederationSSRPlugin: () => moduleFederationSSRPlugin,
34
- setEnv: () => setEnv
35
- });
36
- module.exports = __toCommonJS(ssrPlugin_exports);
37
- var import_path = __toESM(require("path"));
38
- var import_fs_extra = __toESM(require("fs-extra"));
39
- var import_webpack = require("@module-federation/enhanced/webpack");
40
- var import_rspack = require("@module-federation/enhanced/rspack");
41
- var import_universe_entry_chunk_tracker_plugin = __toESM(require("@module-federation/node/universe-entry-chunk-tracker-plugin"));
42
- var import_logger = __toESM(require("../logger"));
43
- var import_utils = require("./utils");
44
- var import_manifest = require("@module-federation/rsbuild-plugin/manifest");
45
- var import_utils2 = require("./utils");
46
- function setEnv() {
47
- process.env["MF_DISABLE_EMIT_STATS"] = "true";
48
- process.env["MF_SSR_PRJ"] = "true";
49
- }
50
- const CHAIN_MF_PLUGIN_ID = "plugin-module-federation-server";
51
- const mfSSRRsbuildPlugin = (pluginOptions) => {
52
- return {
53
- name: "@modern-js/plugin-mf-post-config",
54
- pre: [
55
- "@modern-js/builder-plugin-ssr"
56
- ],
57
- setup(api) {
58
- if (pluginOptions.csrConfig.getPublicPath) {
59
- return;
60
- }
61
- let csrOutputPath = "";
62
- let ssrOutputPath = "";
63
- let ssrEnv = "";
64
- api.modifyEnvironmentConfig((config, { name }) => {
65
- const target = config.output.target;
66
- if ((0, import_utils2.skipByTarget)(target)) {
67
- return config;
68
- }
69
- if ((0, import_utils2.isWebTarget)(target)) {
70
- csrOutputPath = config.output.distPath.root;
71
- } else {
72
- ssrOutputPath = config.output.distPath.root;
73
- ssrEnv = name;
74
- }
75
- return config;
76
- });
77
- const modifySSRPublicPath = (config, utils) => {
78
- if (ssrEnv !== utils.environment.name) {
79
- return config;
80
- }
81
- const userSSRConfig = pluginOptions.userConfig.ssr ? typeof pluginOptions.userConfig.ssr === "object" ? pluginOptions.userConfig.ssr : {} : {};
82
- if (userSSRConfig.distOutputDir) {
83
- return;
84
- }
85
- config.output.publicPath = `${config.output.publicPath}${import_path.default.relative(csrOutputPath, ssrOutputPath)}/`;
86
- return config;
87
- };
88
- api.modifyWebpackConfig((config, utils) => {
89
- modifySSRPublicPath(config, utils);
90
- return config;
91
- });
92
- api.modifyRspackConfig((config, utils) => {
93
- modifySSRPublicPath(config, utils);
94
- return config;
95
- });
96
- }
97
- };
98
- };
99
- const moduleFederationSSRPlugin = (pluginOptions) => ({
100
- name: "@modern-js/plugin-module-federation-ssr",
101
- pre: [
102
- "@modern-js/plugin-module-federation-config",
103
- "@modern-js/plugin-module-federation"
104
- ],
105
- setup: async (api) => {
106
- var _pluginOptions_userConfig, _modernjsConfig_server;
107
- const modernjsConfig = api.getConfig();
108
- var _pluginOptions_userConfig_ssr;
109
- const enableSSR = (_pluginOptions_userConfig_ssr = (_pluginOptions_userConfig = pluginOptions.userConfig) === null || _pluginOptions_userConfig === void 0 ? void 0 : _pluginOptions_userConfig.ssr) !== null && _pluginOptions_userConfig_ssr !== void 0 ? _pluginOptions_userConfig_ssr : Boolean(modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
110
- if (!enableSSR) {
111
- return;
112
- }
113
- setEnv();
114
- api._internalRuntimePlugins(({ entrypoint, plugins }) => {
115
- const { fetchServerQuery } = pluginOptions;
116
- plugins.push({
117
- name: "injectDataFetchFunction",
118
- path: "@module-federation/modern-js/ssr-inject-data-fetch-function-plugin",
119
- config: {
120
- fetchServerQuery
121
- }
122
- });
123
- if (!(0, import_utils.isDev)()) {
124
- return {
125
- entrypoint,
126
- plugins
127
- };
128
- }
129
- plugins.push({
130
- name: "mfSSRDev",
131
- path: "@module-federation/modern-js/ssr-dev-plugin",
132
- config: {}
133
- });
134
- return {
135
- entrypoint,
136
- plugins
137
- };
138
- });
139
- if (pluginOptions.ssrConfig.remotes) {
140
- api._internalServerPlugins(({ plugins }) => {
141
- plugins.push({
142
- name: "@module-federation/modern-js/data-fetch-server-plugin",
143
- options: {}
144
- });
145
- return {
146
- plugins
147
- };
148
- });
149
- }
150
- api.modifyBundlerChain((chain) => {
151
- const target = chain.get("target");
152
- if ((0, import_utils2.skipByTarget)(target)) {
153
- return;
154
- }
155
- const bundlerType = api.getAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
156
- const MFPlugin = bundlerType === "webpack" ? import_webpack.ModuleFederationPlugin : import_rspack.ModuleFederationPlugin;
157
- const isWeb = (0, import_utils2.isWebTarget)(target);
158
- if (!isWeb) {
159
- if (!chain.plugins.has(CHAIN_MF_PLUGIN_ID)) {
160
- chain.plugin(CHAIN_MF_PLUGIN_ID).use(MFPlugin, [
161
- pluginOptions.ssrConfig
162
- ]).init((Plugin, args) => {
163
- pluginOptions.nodePlugin = new Plugin(args[0]);
164
- return pluginOptions.nodePlugin;
165
- });
166
- }
167
- }
168
- if (!isWeb) {
169
- chain.target("async-node");
170
- if ((0, import_utils.isDev)()) {
171
- chain.plugin("UniverseEntryChunkTrackerPlugin").use(import_universe_entry_chunk_tracker_plugin.default);
172
- }
173
- const userSSRConfig = pluginOptions.userConfig.ssr ? typeof pluginOptions.userConfig.ssr === "object" ? pluginOptions.userConfig.ssr : {} : {};
174
- const publicPath = chain.output.get("publicPath");
175
- if (userSSRConfig.distOutputDir && publicPath) {
176
- chain.output.publicPath(`${publicPath}${userSSRConfig.distOutputDir}/`);
177
- }
178
- }
179
- if ((0, import_utils.isDev)() && isWeb) {
180
- chain.externals({
181
- "@module-federation/node/utils": "NOT_USED_IN_BROWSER"
182
- });
183
- }
184
- });
185
- api.config(() => {
186
- return {
187
- builderPlugins: [
188
- mfSSRRsbuildPlugin(pluginOptions)
189
- ],
190
- tools: {
191
- devServer: {
192
- before: [
193
- (req, res, next) => {
194
- if (!enableSSR) {
195
- next();
196
- return;
197
- }
198
- try {
199
- var _req_url, _req_url1;
200
- if (((_req_url = req.url) === null || _req_url === void 0 ? void 0 : _req_url.includes(".json")) && !((_req_url1 = req.url) === null || _req_url1 === void 0 ? void 0 : _req_url1.includes("hot-update"))) {
201
- const filepath = import_path.default.join(process.cwd(), `dist${req.url}`);
202
- import_fs_extra.default.statSync(filepath);
203
- res.setHeader("Access-Control-Allow-Origin", "*");
204
- res.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, PATCH, OPTIONS");
205
- res.setHeader("Access-Control-Allow-Headers", "*");
206
- import_fs_extra.default.createReadStream(filepath).pipe(res);
207
- } else {
208
- next();
209
- }
210
- } catch (err) {
211
- import_logger.default.debug(err);
212
- next();
213
- }
214
- }
215
- ]
216
- }
217
- }
218
- };
219
- });
220
- api.onAfterBuild(() => {
221
- const { nodePlugin, browserPlugin, distOutputDir } = pluginOptions;
222
- (0, import_manifest.updateStatsAndManifest)(nodePlugin, browserPlugin, distOutputDir);
223
- });
224
- api.onDevCompileDone(() => {
225
- const { nodePlugin, browserPlugin, distOutputDir } = pluginOptions;
226
- (0, import_manifest.updateStatsAndManifest)(nodePlugin, browserPlugin, distOutputDir);
227
- });
228
- }
229
- });
230
- var ssrPlugin_default = moduleFederationSSRPlugin;
231
- // Annotate the CommonJS export names for ESM import in node:
232
- 0 && (module.exports = {
233
- CHAIN_MF_PLUGIN_ID,
234
- moduleFederationSSRPlugin,
235
- setEnv
236
- });
@@ -1,90 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var utils_exports = {};
30
- __export(utils_exports, {
31
- getIPV4: () => getIPV4,
32
- isDev: () => isDev,
33
- isWebTarget: () => isWebTarget,
34
- skipByTarget: () => skipByTarget
35
- });
36
- module.exports = __toCommonJS(utils_exports);
37
- var import_os = __toESM(require("os"));
38
- const localIpv4 = "127.0.0.1";
39
- const getIpv4Interfaces = () => {
40
- try {
41
- const interfaces = import_os.default.networkInterfaces();
42
- const ipv4Interfaces = [];
43
- Object.values(interfaces).forEach((detail) => {
44
- detail === null || detail === void 0 ? void 0 : detail.forEach((detail2) => {
45
- const familyV4Value = typeof detail2.family === "string" ? "IPv4" : 4;
46
- if (detail2.family === familyV4Value && detail2.address !== localIpv4) {
47
- ipv4Interfaces.push(detail2);
48
- }
49
- });
50
- });
51
- return ipv4Interfaces;
52
- } catch (_err) {
53
- return [];
54
- }
55
- };
56
- const getIPV4 = () => {
57
- const ipv4Interfaces = getIpv4Interfaces();
58
- const ipv4Interface = ipv4Interfaces[0] || {
59
- address: localIpv4
60
- };
61
- return ipv4Interface.address;
62
- };
63
- const isWebTarget = (target) => {
64
- const WEB_TARGET = "web";
65
- if (Array.isArray(target)) {
66
- return target.includes(WEB_TARGET);
67
- } else if (typeof target === "string") {
68
- return target === WEB_TARGET;
69
- }
70
- return false;
71
- };
72
- const skipByTarget = (target) => {
73
- const IGNORE_TARGET = "webworker";
74
- if (Array.isArray(target)) {
75
- return target.includes(IGNORE_TARGET);
76
- } else if (typeof target === "string") {
77
- return target === IGNORE_TARGET;
78
- }
79
- return false;
80
- };
81
- function isDev() {
82
- return process.env.NODE_ENV === "development";
83
- }
84
- // Annotate the CommonJS export names for ESM import in node:
85
- 0 && (module.exports = {
86
- getIPV4,
87
- isDev,
88
- isWebTarget,
89
- skipByTarget
90
- });