@module-federation/modern-js 0.0.0-next-20250526033636 → 0.0.0-next-20250526035905

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 (82) hide show
  1. package/dist/cjs/cli/configPlugin.js +6 -8
  2. package/dist/cjs/cli/configPlugin.spec.js +1 -3
  3. package/dist/cjs/{runtime/wrapNoSSR.js → cli/constant.js} +6 -13
  4. package/dist/cjs/{logger.js → cli/logger.js} +1 -1
  5. package/dist/cjs/cli/ssrPlugin.js +11 -27
  6. package/dist/cjs/cli/utils.js +0 -5
  7. package/dist/cjs/constant.js +2 -49
  8. package/dist/cjs/runtime/createRemoteSSRComponent.js +210 -0
  9. package/dist/cjs/runtime/index.js +2 -11
  10. package/dist/cjs/{interfaces/global.js → ssr-runtime/index.js} +8 -2
  11. package/dist/cjs/ssr-runtime/{devPlugin.js → plugin.js} +6 -9
  12. package/dist/esm/cli/configPlugin.js +7 -9
  13. package/dist/esm/cli/configPlugin.spec.js +1 -3
  14. package/dist/esm/cli/constant.js +4 -0
  15. package/dist/esm/{logger.js → cli/logger.js} +1 -1
  16. package/dist/esm/cli/ssrPlugin.js +7 -24
  17. package/dist/esm/cli/utils.js +0 -4
  18. package/dist/esm/constant.js +1 -37
  19. package/dist/esm/runtime/createRemoteSSRComponent.js +263 -0
  20. package/dist/esm/runtime/index.js +2 -10
  21. package/dist/esm/ssr-runtime/index.js +1 -0
  22. package/dist/esm/ssr-runtime/{devPlugin.js → plugin.js} +2 -5
  23. package/dist/esm-node/cli/configPlugin.js +7 -9
  24. package/dist/esm-node/cli/configPlugin.spec.js +1 -3
  25. package/dist/esm-node/cli/constant.js +4 -0
  26. package/dist/esm-node/{logger.js → cli/logger.js} +1 -1
  27. package/dist/esm-node/cli/ssrPlugin.js +7 -23
  28. package/dist/esm-node/cli/utils.js +0 -4
  29. package/dist/esm-node/constant.js +1 -37
  30. package/dist/esm-node/runtime/createRemoteSSRComponent.js +175 -0
  31. package/dist/esm-node/runtime/index.js +2 -10
  32. package/dist/esm-node/ssr-runtime/index.js +1 -0
  33. package/dist/esm-node/ssr-runtime/{devPlugin.js → plugin.js} +2 -5
  34. package/dist/types/cli/constant.d.ts +1 -0
  35. package/dist/types/cli/index.d.ts +0 -1
  36. package/dist/types/cli/utils.d.ts +0 -1
  37. package/dist/types/constant.d.ts +0 -23
  38. package/dist/types/runtime/createRemoteSSRComponent.d.ts +19 -0
  39. package/dist/types/runtime/index.d.ts +2 -6
  40. package/dist/types/ssr-runtime/index.d.ts +1 -0
  41. package/dist/types/ssr-runtime/plugin.d.ts +2 -0
  42. package/package.json +17 -41
  43. package/dist/cjs/cli/mfRuntimePlugins/auto-fetch-data.js +0 -98
  44. package/dist/cjs/cli/server/data-fetch-server-plugin.js +0 -192
  45. package/dist/cjs/runtime/AwaitDataFetch.js +0 -144
  46. package/dist/cjs/runtime/createRemoteComponent.js +0 -327
  47. package/dist/cjs/ssr-runtime/downgrade.js +0 -108
  48. package/dist/cjs/ssr-runtime/injectDataFetchFunctionPlugin.js +0 -128
  49. package/dist/cjs/utils/dataFetch.js +0 -211
  50. package/dist/cjs/utils/index.js +0 -54
  51. package/dist/esm/cli/mfRuntimePlugins/auto-fetch-data.js +0 -74
  52. package/dist/esm/cli/server/data-fetch-server-plugin.js +0 -240
  53. package/dist/esm/interfaces/global.js +0 -0
  54. package/dist/esm/runtime/AwaitDataFetch.js +0 -131
  55. package/dist/esm/runtime/createRemoteComponent.js +0 -417
  56. package/dist/esm/runtime/wrapNoSSR.js +0 -12
  57. package/dist/esm/ssr-runtime/downgrade.js +0 -143
  58. package/dist/esm/ssr-runtime/injectDataFetchFunctionPlugin.js +0 -168
  59. package/dist/esm/utils/dataFetch.js +0 -237
  60. package/dist/esm/utils/index.js +0 -28
  61. package/dist/esm-node/cli/mfRuntimePlugins/auto-fetch-data.js +0 -68
  62. package/dist/esm-node/cli/server/data-fetch-server-plugin.js +0 -162
  63. package/dist/esm-node/interfaces/global.js +0 -0
  64. package/dist/esm-node/runtime/AwaitDataFetch.js +0 -109
  65. package/dist/esm-node/runtime/createRemoteComponent.js +0 -291
  66. package/dist/esm-node/runtime/wrapNoSSR.js +0 -11
  67. package/dist/esm-node/ssr-runtime/downgrade.js +0 -82
  68. package/dist/esm-node/ssr-runtime/injectDataFetchFunctionPlugin.js +0 -94
  69. package/dist/esm-node/utils/dataFetch.js +0 -166
  70. package/dist/esm-node/utils/index.js +0 -27
  71. package/dist/types/cli/mfRuntimePlugins/auto-fetch-data.d.ts +0 -3
  72. package/dist/types/cli/server/data-fetch-server-plugin.d.ts +0 -3
  73. package/dist/types/interfaces/global.d.ts +0 -27
  74. package/dist/types/runtime/AwaitDataFetch.d.ts +0 -19
  75. package/dist/types/runtime/createRemoteComponent.d.ts +0 -26
  76. package/dist/types/runtime/wrapNoSSR.d.ts +0 -9
  77. package/dist/types/ssr-runtime/devPlugin.d.ts +0 -2
  78. package/dist/types/ssr-runtime/downgrade.d.ts +0 -4
  79. package/dist/types/ssr-runtime/injectDataFetchFunctionPlugin.d.ts +0 -2
  80. package/dist/types/utils/dataFetch.d.ts +0 -26
  81. package/dist/types/utils/index.d.ts +0 -15
  82. /package/dist/types/{logger.d.ts → cli/logger.d.ts} +0 -0
@@ -1,108 +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 downgrade_exports = {};
20
- __export(downgrade_exports, {
21
- callAllDowngrade: () => callAllDowngrade,
22
- callDowngrade: () => callDowngrade,
23
- getDowngradeTag: () => getDowngradeTag
24
- });
25
- module.exports = __toCommonJS(downgrade_exports);
26
- var import_constant = require("../constant");
27
- var import_constant2 = require("../constant");
28
- var import_utils = require("../utils");
29
- function getDowngradeTag() {
30
- return globalThis[import_constant.DOWNGRADE_KEY];
31
- }
32
- function callAllDowngrade() {
33
- const dataFetchMap = (0, import_utils.getDataFetchMap)();
34
- if (!dataFetchMap) {
35
- return;
36
- }
37
- Object.keys(dataFetchMap).forEach((key) => {
38
- callDowngrade(key);
39
- });
40
- }
41
- async function callDowngrade(id, params, remoteInfo) {
42
- const dataFetchMap = (0, import_utils.getDataFetchMap)();
43
- if (!dataFetchMap) {
44
- return;
45
- }
46
- const mfDataFetch = dataFetchMap[id];
47
- if ((mfDataFetch === null || mfDataFetch === void 0 ? void 0 : mfDataFetch[2]) === import_constant2.MF_DATA_FETCH_STATUS.AWAIT) {
48
- mfDataFetch[2] = import_constant2.MF_DATA_FETCH_STATUS.LOADING;
49
- let promise, res, rej;
50
- if (mfDataFetch[1]) {
51
- promise = mfDataFetch[1][0];
52
- res = mfDataFetch[1][1];
53
- rej = mfDataFetch[1][2];
54
- } else {
55
- promise = new Promise((resolve, reject) => {
56
- res = resolve;
57
- rej = reject;
58
- });
59
- mfDataFetch[1] = [
60
- promise,
61
- res,
62
- rej
63
- ];
64
- }
65
- const dataFetchType = mfDataFetch[0][1];
66
- if (dataFetchType === import_constant2.MF_DATA_FETCH_TYPE.FETCH_CLIENT) {
67
- try {
68
- mfDataFetch[0][0]().then((getDataFetchFn) => {
69
- return getDataFetchFn({
70
- ...params,
71
- isDowngrade: true
72
- }).then((data) => {
73
- mfDataFetch[2] = import_constant2.MF_DATA_FETCH_STATUS.LOADED;
74
- res(data);
75
- });
76
- });
77
- } catch (e) {
78
- mfDataFetch[2] = import_constant2.MF_DATA_FETCH_STATUS.ERROR;
79
- rej(e);
80
- }
81
- } else if (dataFetchType === import_constant2.MF_DATA_FETCH_TYPE.FETCH_SERVER) {
82
- try {
83
- const currentUrl = new URL(window.location.href);
84
- currentUrl.searchParams.set(import_constant.DATA_FETCH_QUERY, encodeURIComponent(id));
85
- if (params) {
86
- currentUrl.searchParams.set("params", encodeURIComponent(JSON.stringify(params)));
87
- }
88
- if (remoteInfo) {
89
- currentUrl.searchParams.set("remoteInfo", encodeURIComponent(JSON.stringify(remoteInfo)));
90
- }
91
- const fetchUrl = currentUrl.toString();
92
- const data = await fetch(fetchUrl).then((res2) => res2.json());
93
- mfDataFetch[2] = import_constant2.MF_DATA_FETCH_STATUS.LOADED;
94
- res(data);
95
- } catch (e) {
96
- mfDataFetch[2] = import_constant2.MF_DATA_FETCH_STATUS.ERROR;
97
- rej(e);
98
- }
99
- }
100
- return promise;
101
- }
102
- }
103
- // Annotate the CommonJS export names for ESM import in node:
104
- 0 && (module.exports = {
105
- callAllDowngrade,
106
- callDowngrade,
107
- getDowngradeTag
108
- });
@@ -1,128 +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 injectDataFetchFunctionPlugin_exports = {};
30
- __export(injectDataFetchFunctionPlugin_exports, {
31
- injectDataFetchFunctionPlugin: () => injectDataFetchFunctionPlugin
32
- });
33
- module.exports = __toCommonJS(injectDataFetchFunctionPlugin_exports);
34
- var import_constant = require("../constant");
35
- var import_logger = __toESM(require("../logger"));
36
- var import_utils = require("../utils");
37
- var import_downgrade = require("./downgrade");
38
- const injectDataFetchFunctionPlugin = () => ({
39
- name: "@module-federation/inject-data-fetch-function-plugin",
40
- setup: (api) => {
41
- api.onBeforeRender(async () => {
42
- var _globalThis, _DATA_FETCH_FUNCTION;
43
- globalThis.FEDERATION_SSR = true;
44
- if (typeof window === "undefined") {
45
- return;
46
- }
47
- const dataFetchFunction = async function(options) {
48
- const [id, data, downgrade] = options;
49
- import_logger.default.debug("==========call data fetch function!");
50
- if (data) {
51
- if (!id) {
52
- throw new Error("id is required!");
53
- }
54
- if (!(0, import_utils.getDataFetchMap)()) {
55
- (0, import_utils.initDataFetchMap)();
56
- }
57
- const dataFetchItem = (0, import_utils.getDataFetchItem)(id);
58
- if (dataFetchItem) {
59
- var _dataFetchItem__, _dataFetchItem_;
60
- (_dataFetchItem_ = dataFetchItem[1]) === null || _dataFetchItem_ === void 0 ? void 0 : (_dataFetchItem__ = _dataFetchItem_[1]) === null || _dataFetchItem__ === void 0 ? void 0 : _dataFetchItem__.call(_dataFetchItem_, data);
61
- dataFetchItem[2] = import_constant.MF_DATA_FETCH_STATUS.LOADED;
62
- return;
63
- }
64
- if (!dataFetchItem) {
65
- const dataFetchMap = (0, import_utils.getDataFetchMap)();
66
- let res;
67
- let rej;
68
- const p = new Promise((resolve, reject) => {
69
- res = resolve;
70
- rej = reject;
71
- });
72
- dataFetchMap[id] = [
73
- [
74
- async () => async () => {
75
- return "";
76
- },
77
- import_constant.MF_DATA_FETCH_TYPE.FETCH_SERVER
78
- ],
79
- [
80
- p,
81
- res,
82
- rej
83
- ],
84
- import_constant.MF_DATA_FETCH_STATUS.LOADED
85
- ];
86
- res(data);
87
- return;
88
- }
89
- }
90
- if (downgrade) {
91
- const mfDowngrade2 = (0, import_downgrade.getDowngradeTag)();
92
- if (!mfDowngrade2) {
93
- globalThis[import_constant.DOWNGRADE_KEY] = id ? [
94
- id
95
- ] : true;
96
- } else if (Array.isArray(mfDowngrade2) && id && !mfDowngrade2.includes(id)) {
97
- mfDowngrade2.push(id);
98
- }
99
- }
100
- const mfDowngrade = (0, import_downgrade.getDowngradeTag)();
101
- if (typeof mfDowngrade === "boolean") {
102
- return (0, import_downgrade.callAllDowngrade)();
103
- }
104
- if (Array.isArray(mfDowngrade)) {
105
- if (!id) {
106
- globalThis[import_constant.DOWNGRADE_KEY] = true;
107
- return (0, import_downgrade.callAllDowngrade)();
108
- }
109
- if (!mfDowngrade.includes(id)) {
110
- mfDowngrade.push(id);
111
- }
112
- return (0, import_downgrade.callDowngrade)(id);
113
- }
114
- };
115
- globalThis[import_constant.FS_HREF] = window.location.href;
116
- (_globalThis = globalThis)[_DATA_FETCH_FUNCTION = import_constant.DATA_FETCH_FUNCTION] || (_globalThis[_DATA_FETCH_FUNCTION] = []);
117
- const dataFetch = globalThis[import_constant.DATA_FETCH_FUNCTION];
118
- await Promise.all(dataFetch.map(async (options) => {
119
- await dataFetchFunction(options);
120
- }));
121
- dataFetch.push = dataFetchFunction;
122
- });
123
- }
124
- });
125
- // Annotate the CommonJS export names for ESM import in node:
126
- 0 && (module.exports = {
127
- injectDataFetchFunctionPlugin
128
- });
@@ -1,211 +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 dataFetch_exports = {};
30
- __export(dataFetch_exports, {
31
- fetchData: () => fetchData,
32
- flushDataFetch: () => flushDataFetch,
33
- getDataFetchIdWithErrorMsgs: () => getDataFetchIdWithErrorMsgs,
34
- getDataFetchInfo: () => getDataFetchInfo,
35
- getDataFetchItem: () => getDataFetchItem,
36
- getDataFetchMap: () => getDataFetchMap,
37
- getDataFetchMapKey: () => getDataFetchMapKey,
38
- initDataFetchMap: () => initDataFetchMap,
39
- isDataLoaderExpose: () => isDataLoaderExpose,
40
- loadDataFetchModule: () => loadDataFetchModule,
41
- setDataFetchItemLoadedStatus: () => setDataFetchItemLoadedStatus,
42
- wrapDataFetchId: () => wrapDataFetchId
43
- });
44
- module.exports = __toCommonJS(dataFetch_exports);
45
- var import_sdk = require("@module-federation/sdk");
46
- var import_utils = require("../utils");
47
- var import_logger = __toESM(require("../logger"));
48
- var import_downgrade = require("../ssr-runtime/downgrade");
49
- var import_constant = require("../constant");
50
- var import_constant2 = require("@module-federation/rsbuild-plugin/constant");
51
- const getDataFetchInfo = ({ name, alias, id, remoteSnapshot }) => {
52
- if (!remoteSnapshot) {
53
- return;
54
- }
55
- if (!("modules" in remoteSnapshot)) {
56
- return;
57
- }
58
- const regex = new RegExp(`^${name}(/[^/].*|)$`);
59
- const nameOrAlias = regex.test(id) ? name : alias || name;
60
- const expose = id.replace(nameOrAlias, "");
61
- let dataFetchName = "";
62
- let dataFetchId = "";
63
- if (expose.startsWith("/")) {
64
- dataFetchName = `${expose.slice(1)}.${import_constant2.DATA_FETCH_IDENTIFIER}`;
65
- dataFetchId = `${id}.${import_constant2.DATA_FETCH_IDENTIFIER}`;
66
- } else if (expose === "") {
67
- dataFetchName = import_constant2.DATA_FETCH_IDENTIFIER;
68
- dataFetchId = `${id}/${import_constant2.DATA_FETCH_IDENTIFIER}`;
69
- } else {
70
- return;
71
- }
72
- if (!dataFetchName || !dataFetchId) {
73
- return;
74
- }
75
- if (!remoteSnapshot.modules.find((module2) => module2.moduleName === dataFetchName)) {
76
- return;
77
- }
78
- return {
79
- dataFetchName,
80
- dataFetchId
81
- };
82
- };
83
- function initDataFetchMap() {
84
- var _globalThis;
85
- (_globalThis = globalThis).__MF_DATA_FETCH_MAP__ || (_globalThis.__MF_DATA_FETCH_MAP__ = {});
86
- }
87
- function getDataFetchItem(id) {
88
- var _globalThis___MF_DATA_FETCH_MAP__;
89
- return (_globalThis___MF_DATA_FETCH_MAP__ = globalThis.__MF_DATA_FETCH_MAP__) === null || _globalThis___MF_DATA_FETCH_MAP__ === void 0 ? void 0 : _globalThis___MF_DATA_FETCH_MAP__[id];
90
- }
91
- function getDataFetchMap() {
92
- return globalThis.__MF_DATA_FETCH_MAP__;
93
- }
94
- const flushDataFetch = () => {
95
- globalThis.__MF_DATA_FETCH_MAP__ = {};
96
- globalThis[import_constant.DOWNGRADE_KEY] = void 0;
97
- };
98
- function setDataFetchItemLoadedStatus(id) {
99
- const dataFetchItem = getDataFetchItem(id);
100
- if (!dataFetchItem) {
101
- return;
102
- }
103
- dataFetchItem[2] = import_constant.MF_DATA_FETCH_STATUS.LOADED;
104
- }
105
- const wrapDataFetchId = (id) => {
106
- return `${import_constant.WRAP_DATA_FETCH_ID_IDENTIFIER}${id}${import_constant.WRAP_DATA_FETCH_ID_IDENTIFIER}`;
107
- };
108
- const getDataFetchIdWithErrorMsgs = (errMsgs) => {
109
- const firstIdentifierIndex = errMsgs.indexOf(import_constant.WRAP_DATA_FETCH_ID_IDENTIFIER);
110
- if (firstIdentifierIndex === -1) {
111
- return void 0;
112
- }
113
- const secondIdentifierIndex = errMsgs.indexOf(import_constant.WRAP_DATA_FETCH_ID_IDENTIFIER, firstIdentifierIndex + import_constant.WRAP_DATA_FETCH_ID_IDENTIFIER.length);
114
- if (secondIdentifierIndex === -1) {
115
- return void 0;
116
- }
117
- return errMsgs.substring(firstIdentifierIndex + import_constant.WRAP_DATA_FETCH_ID_IDENTIFIER.length, secondIdentifierIndex);
118
- };
119
- async function fetchData(id, params, remoteInfo) {
120
- const callFetchData = async () => {
121
- const item = getDataFetchItem(id);
122
- if (!item) {
123
- return;
124
- }
125
- const [fetchDataFnArr, ..._rest] = item;
126
- const fetchDataFn = await fetchDataFnArr[2];
127
- if (!fetchDataFn) {
128
- return;
129
- }
130
- return fetchDataFn(params);
131
- };
132
- if ((0, import_sdk.isBrowserEnv)()) {
133
- var _dataFetchItem_;
134
- const dataFetchItem = getDataFetchItem(id);
135
- if (!dataFetchItem) {
136
- throw new Error(`dataFetchItem not found, id: ${id}`);
137
- }
138
- if ((_dataFetchItem_ = dataFetchItem[1]) === null || _dataFetchItem_ === void 0 ? void 0 : _dataFetchItem_[0]) {
139
- return dataFetchItem[1][0];
140
- }
141
- if ((0, import_utils.isCSROnly)()) {
142
- import_logger.default.debug("==========csr only!");
143
- return callFetchData();
144
- }
145
- if (remoteInfo) {
146
- return (0, import_downgrade.callDowngrade)(id, params, remoteInfo);
147
- }
148
- const mfDowngrade = (0, import_downgrade.getDowngradeTag)();
149
- if (mfDowngrade) {
150
- if (typeof mfDowngrade === "boolean") {
151
- return (0, import_downgrade.callDowngrade)(id, {
152
- ...params,
153
- isDowngrade: true
154
- });
155
- }
156
- if (mfDowngrade.includes(id)) {
157
- return (0, import_downgrade.callDowngrade)(id, {
158
- ...params,
159
- isDowngrade: true
160
- });
161
- }
162
- }
163
- let res;
164
- let rej;
165
- const p = new Promise((resolve, reject) => {
166
- res = resolve;
167
- rej = reject;
168
- });
169
- dataFetchItem[1] = [
170
- p,
171
- res,
172
- rej
173
- ];
174
- dataFetchItem[2] = import_constant.MF_DATA_FETCH_STATUS.AWAIT;
175
- return dataFetchItem[1][0];
176
- }
177
- return callFetchData();
178
- }
179
- function getDataFetchMapKey(dataFetchInfo, hostInfo) {
180
- if (!dataFetchInfo || !hostInfo) {
181
- return;
182
- }
183
- const { dataFetchId } = dataFetchInfo;
184
- return (0, import_sdk.composeKeyWithSeparator)(dataFetchId, hostInfo.name, hostInfo.version);
185
- }
186
- async function loadDataFetchModule(instance, id) {
187
- return instance.loadRemote(id).then((m) => {
188
- if (m && typeof m === "object" && "fetchData" in m && typeof m.fetchData === "function") {
189
- return m.fetchData;
190
- }
191
- throw new Error(`fetchData not found in remote ${id}, ${JSON.stringify(m)}`);
192
- });
193
- }
194
- function isDataLoaderExpose(exposeKey) {
195
- return exposeKey.endsWith(import_constant2.DATA_FETCH_IDENTIFIER) || exposeKey.endsWith(import_constant2.DATA_FETCH_CLIENT_SUFFIX);
196
- }
197
- // Annotate the CommonJS export names for ESM import in node:
198
- 0 && (module.exports = {
199
- fetchData,
200
- flushDataFetch,
201
- getDataFetchIdWithErrorMsgs,
202
- getDataFetchInfo,
203
- getDataFetchItem,
204
- getDataFetchMap,
205
- getDataFetchMapKey,
206
- initDataFetchMap,
207
- isDataLoaderExpose,
208
- loadDataFetchModule,
209
- setDataFetchItemLoadedStatus,
210
- wrapDataFetchId
211
- });
@@ -1,54 +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 __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
19
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
- var utils_exports = {};
21
- __export(utils_exports, {
22
- getLoadedRemoteInfos: () => getLoadedRemoteInfos,
23
- isCSROnly: () => isCSROnly
24
- });
25
- module.exports = __toCommonJS(utils_exports);
26
- __reExport(utils_exports, require("./dataFetch"), module.exports);
27
- function getLoadedRemoteInfos(id, instance) {
28
- if (!instance) {
29
- return;
30
- }
31
- const { name, expose } = instance.remoteHandler.idToRemoteMap[id] || {};
32
- if (!name) {
33
- return;
34
- }
35
- const module2 = instance.moduleCache.get(name);
36
- if (!module2) {
37
- return;
38
- }
39
- const { remoteSnapshot } = instance.snapshotHandler.getGlobalRemoteInfo(module2.remoteInfo);
40
- return {
41
- ...module2.remoteInfo,
42
- snapshot: remoteSnapshot,
43
- expose
44
- };
45
- }
46
- function isCSROnly() {
47
- return window._SSR_DATA === void 0;
48
- }
49
- // Annotate the CommonJS export names for ESM import in node:
50
- 0 && (module.exports = {
51
- getLoadedRemoteInfos,
52
- isCSROnly,
53
- ...require("./dataFetch")
54
- });
@@ -1,74 +0,0 @@
1
- import { getDataFetchInfo, initDataFetchMap, getDataFetchItem, getDataFetchMap, isCSROnly } from "../../utils";
2
- import logger from "../../logger";
3
- import { getDataFetchMapKey, isDataLoaderExpose, loadDataFetchModule } from "../../utils/dataFetch";
4
- import { MF_DATA_FETCH_TYPE, MF_DATA_FETCH_STATUS } from "../../constant";
5
- import { DATA_FETCH_CLIENT_SUFFIX } from "@module-federation/rsbuild-plugin/constant";
6
- var autoFetchData = function() {
7
- return {
8
- name: "auto-fetch-data-plugin",
9
- beforeInit: function beforeInit(args) {
10
- initDataFetchMap();
11
- return args;
12
- },
13
- afterLoadSnapshot: function afterLoadSnapshot(args) {
14
- var id = args.id, moduleInfo = args.moduleInfo, remoteSnapshot = args.remoteSnapshot, host = args.host;
15
- if (typeof id === "string" && isDataLoaderExpose(id)) {
16
- return args;
17
- }
18
- if (!remoteSnapshot || !id || !("modules" in remoteSnapshot)) {
19
- return args;
20
- }
21
- var name = moduleInfo.name, alias = moduleInfo.alias;
22
- var dataFetchInfo = getDataFetchInfo({
23
- name,
24
- alias,
25
- id,
26
- remoteSnapshot
27
- });
28
- if (!dataFetchInfo) {
29
- return args;
30
- }
31
- var dataFetchId = dataFetchInfo.dataFetchId, dataFetchName = dataFetchInfo.dataFetchName;
32
- var dataFetchMapKey = getDataFetchMapKey(dataFetchInfo, {
33
- name: host.name,
34
- version: host.options.version
35
- });
36
- logger.debug("======= auto fetch plugin dataFetchMapKey: ", dataFetchMapKey);
37
- if (!dataFetchMapKey) {
38
- return args;
39
- }
40
- var dataFetchItem = getDataFetchItem(dataFetchMapKey);
41
- if (dataFetchItem) {
42
- return args;
43
- }
44
- var dataFetchMap = getDataFetchMap();
45
- var downgradeType = remoteSnapshot.modules.find(function(module) {
46
- return module.moduleName === "".concat(dataFetchName).concat(DATA_FETCH_CLIENT_SUFFIX);
47
- }) ? MF_DATA_FETCH_TYPE.FETCH_CLIENT : MF_DATA_FETCH_TYPE.FETCH_SERVER;
48
- var finalDataFetchId = dataFetchId;
49
- if (typeof window !== "undefined") {
50
- finalDataFetchId = downgradeType === MF_DATA_FETCH_TYPE.FETCH_CLIENT ? "".concat(dataFetchId).concat(DATA_FETCH_CLIENT_SUFFIX) : dataFetchId;
51
- }
52
- var getDataFetchGetter = function() {
53
- return loadDataFetchModule(host, finalDataFetchId);
54
- };
55
- var dataFetchFnItem = [
56
- getDataFetchGetter,
57
- downgradeType
58
- ];
59
- if (typeof window === "undefined" || isCSROnly()) {
60
- dataFetchFnItem.push(getDataFetchGetter());
61
- }
62
- dataFetchMap[dataFetchMapKey] = [
63
- dataFetchFnItem,
64
- void 0,
65
- MF_DATA_FETCH_STATUS.AWAIT
66
- ];
67
- return args;
68
- }
69
- };
70
- };
71
- var auto_fetch_data_default = autoFetchData;
72
- export {
73
- auto_fetch_data_default as default
74
- };