@module-federation/modern-js 0.14.2 → 0.15.0

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 (122) hide show
  1. package/dist/LICENSE +21 -0
  2. package/dist/cjs/cli/configPlugin.js +381 -0
  3. package/dist/cjs/cli/configPlugin.spec.js +114 -0
  4. package/dist/cjs/cli/index.js +95 -0
  5. package/dist/cjs/cli/mfRuntimePlugins/auto-fetch-data.js +98 -0
  6. package/dist/cjs/cli/mfRuntimePlugins/inject-node-fetch.js +44 -0
  7. package/dist/cjs/cli/mfRuntimePlugins/resolve-entry-ipv4.js +82 -0
  8. package/dist/cjs/cli/mfRuntimePlugins/shared-strategy.js +43 -0
  9. package/dist/cjs/cli/server/data-fetch-server-plugin.js +189 -0
  10. package/dist/cjs/cli/ssrPlugin.js +236 -0
  11. package/dist/cjs/cli/utils.js +90 -0
  12. package/dist/cjs/constant.js +78 -0
  13. package/dist/cjs/interfaces/bundler.js +16 -0
  14. package/dist/cjs/interfaces/global.js +16 -0
  15. package/dist/cjs/logger.js +27 -0
  16. package/dist/cjs/runtime/AwaitDataFetch.js +144 -0
  17. package/dist/cjs/runtime/createRemoteComponent.js +327 -0
  18. package/dist/cjs/runtime/index.js +50 -0
  19. package/dist/cjs/runtime/wrapNoSSR.js +35 -0
  20. package/dist/cjs/server/fileCache.js +84 -0
  21. package/dist/cjs/server/fileCache.spec.js +28 -0
  22. package/dist/cjs/server/index.js +58 -0
  23. package/dist/cjs/server/staticMiddleware.js +77 -0
  24. package/dist/cjs/server/staticMiddleware.spec.js +185 -0
  25. package/dist/cjs/ssr-runtime/SSRLiveReload.js +43 -0
  26. package/dist/cjs/ssr-runtime/devPlugin.js +71 -0
  27. package/dist/cjs/ssr-runtime/downgrade.js +114 -0
  28. package/dist/cjs/ssr-runtime/injectDataFetchFunctionPlugin.js +136 -0
  29. package/dist/cjs/types/index.js +16 -0
  30. package/dist/cjs/utils/dataFetch.js +211 -0
  31. package/dist/cjs/utils/index.js +54 -0
  32. package/dist/esm/cli/configPlugin.js +388 -0
  33. package/dist/esm/cli/configPlugin.spec.js +110 -0
  34. package/dist/esm/cli/index.js +90 -0
  35. package/dist/esm/cli/mfRuntimePlugins/auto-fetch-data.js +74 -0
  36. package/dist/esm/cli/mfRuntimePlugins/inject-node-fetch.js +16 -0
  37. package/dist/esm/cli/mfRuntimePlugins/resolve-entry-ipv4.js +74 -0
  38. package/dist/esm/cli/mfRuntimePlugins/shared-strategy.js +25 -0
  39. package/dist/esm/cli/server/data-fetch-server-plugin.js +237 -0
  40. package/dist/esm/cli/ssrPlugin.js +219 -0
  41. package/dist/esm/cli/utils.js +53 -0
  42. package/dist/esm/constant.js +42 -0
  43. package/dist/esm/interfaces/bundler.js +0 -0
  44. package/dist/esm/interfaces/global.js +0 -0
  45. package/dist/esm/logger.js +7 -0
  46. package/dist/esm/runtime/AwaitDataFetch.js +131 -0
  47. package/dist/esm/runtime/createRemoteComponent.js +417 -0
  48. package/dist/esm/runtime/index.js +22 -0
  49. package/dist/esm/runtime/wrapNoSSR.js +12 -0
  50. package/dist/esm/server/fileCache.js +98 -0
  51. package/dist/esm/server/fileCache.spec.js +50 -0
  52. package/dist/esm/server/index.js +36 -0
  53. package/dist/esm/server/staticMiddleware.js +81 -0
  54. package/dist/esm/server/staticMiddleware.spec.js +328 -0
  55. package/dist/esm/ssr-runtime/SSRLiveReload.js +26 -0
  56. package/dist/esm/ssr-runtime/devPlugin.js +73 -0
  57. package/dist/esm/ssr-runtime/downgrade.js +150 -0
  58. package/dist/esm/ssr-runtime/injectDataFetchFunctionPlugin.js +177 -0
  59. package/dist/esm/types/index.js +0 -0
  60. package/dist/esm/utils/dataFetch.js +237 -0
  61. package/dist/esm/utils/index.js +28 -0
  62. package/dist/esm-node/cli/configPlugin.js +340 -0
  63. package/dist/esm-node/cli/configPlugin.spec.js +91 -0
  64. package/dist/esm-node/cli/index.js +70 -0
  65. package/dist/esm-node/cli/mfRuntimePlugins/auto-fetch-data.js +68 -0
  66. package/dist/esm-node/cli/mfRuntimePlugins/inject-node-fetch.js +14 -0
  67. package/dist/esm-node/cli/mfRuntimePlugins/resolve-entry-ipv4.js +62 -0
  68. package/dist/esm-node/cli/mfRuntimePlugins/shared-strategy.js +23 -0
  69. package/dist/esm-node/cli/server/data-fetch-server-plugin.js +159 -0
  70. package/dist/esm-node/cli/ssrPlugin.js +200 -0
  71. package/dist/esm-node/cli/utils.js +53 -0
  72. package/dist/esm-node/constant.js +42 -0
  73. package/dist/esm-node/interfaces/bundler.js +0 -0
  74. package/dist/esm-node/interfaces/global.js +0 -0
  75. package/dist/esm-node/logger.js +7 -0
  76. package/dist/esm-node/runtime/AwaitDataFetch.js +109 -0
  77. package/dist/esm-node/runtime/createRemoteComponent.js +291 -0
  78. package/dist/esm-node/runtime/index.js +22 -0
  79. package/dist/esm-node/runtime/wrapNoSSR.js +11 -0
  80. package/dist/esm-node/server/fileCache.js +49 -0
  81. package/dist/esm-node/server/fileCache.spec.js +27 -0
  82. package/dist/esm-node/server/index.js +34 -0
  83. package/dist/esm-node/server/staticMiddleware.js +43 -0
  84. package/dist/esm-node/server/staticMiddleware.spec.js +162 -0
  85. package/dist/esm-node/ssr-runtime/SSRLiveReload.js +19 -0
  86. package/dist/esm-node/ssr-runtime/devPlugin.js +37 -0
  87. package/dist/esm-node/ssr-runtime/downgrade.js +88 -0
  88. package/dist/esm-node/ssr-runtime/injectDataFetchFunctionPlugin.js +101 -0
  89. package/dist/esm-node/types/index.js +0 -0
  90. package/dist/esm-node/utils/dataFetch.js +166 -0
  91. package/dist/esm-node/utils/index.js +27 -0
  92. package/dist/types/cli/configPlugin.d.ts +21 -0
  93. package/dist/types/cli/configPlugin.spec.d.ts +1 -0
  94. package/dist/types/cli/index.d.ts +6 -0
  95. package/dist/types/cli/mfRuntimePlugins/auto-fetch-data.d.ts +3 -0
  96. package/dist/types/cli/mfRuntimePlugins/inject-node-fetch.d.ts +3 -0
  97. package/dist/types/cli/mfRuntimePlugins/resolve-entry-ipv4.d.ts +3 -0
  98. package/dist/types/cli/mfRuntimePlugins/shared-strategy.d.ts +3 -0
  99. package/dist/types/cli/server/data-fetch-server-plugin.d.ts +3 -0
  100. package/dist/types/cli/ssrPlugin.d.ts +6 -0
  101. package/dist/types/cli/utils.d.ts +6 -0
  102. package/dist/types/constant.d.ts +25 -0
  103. package/dist/types/interfaces/bundler.d.ts +18 -0
  104. package/dist/types/interfaces/global.d.ts +27 -0
  105. package/dist/types/logger.d.ts +2 -0
  106. package/dist/types/runtime/AwaitDataFetch.d.ts +19 -0
  107. package/dist/types/runtime/createRemoteComponent.d.ts +26 -0
  108. package/dist/types/runtime/index.d.ts +10 -0
  109. package/dist/types/runtime/wrapNoSSR.d.ts +9 -0
  110. package/dist/types/server/fileCache.d.ts +14 -0
  111. package/dist/types/server/fileCache.spec.d.ts +1 -0
  112. package/dist/types/server/index.d.ts +4 -0
  113. package/dist/types/server/staticMiddleware.d.ts +6 -0
  114. package/dist/types/server/staticMiddleware.spec.d.ts +1 -0
  115. package/dist/types/ssr-runtime/SSRLiveReload.d.ts +1 -0
  116. package/dist/types/ssr-runtime/devPlugin.d.ts +2 -0
  117. package/dist/types/ssr-runtime/downgrade.d.ts +4 -0
  118. package/dist/types/ssr-runtime/injectDataFetchFunctionPlugin.d.ts +7 -0
  119. package/dist/types/types/index.d.ts +24 -0
  120. package/dist/types/utils/dataFetch.d.ts +26 -0
  121. package/dist/types/utils/index.d.ts +15 -0
  122. package/package.json +37 -12
@@ -0,0 +1,37 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { SSRLiveReload } from "./SSRLiveReload";
3
+ import { flushDataFetch } from "../utils";
4
+ const mfSSRDevPlugin = () => ({
5
+ name: "@module-federation/modern-js",
6
+ setup: (api) => {
7
+ api.onBeforeRender(async () => {
8
+ if (typeof window !== "undefined") {
9
+ return;
10
+ }
11
+ globalThis.shouldUpdate = false;
12
+ const nodeUtils = await import("@module-federation/node/utils");
13
+ const shouldUpdate = await nodeUtils.revalidate();
14
+ console.log("shouldUpdate: ", shouldUpdate);
15
+ if (shouldUpdate) {
16
+ console.log("should RELOAD", shouldUpdate);
17
+ await nodeUtils.flushChunks();
18
+ flushDataFetch();
19
+ globalThis.shouldUpdate = true;
20
+ }
21
+ });
22
+ api.wrapRoot((App) => {
23
+ const AppWrapper = (props) => /* @__PURE__ */ _jsxs(_Fragment, {
24
+ children: [
25
+ /* @__PURE__ */ _jsx(SSRLiveReload, {}),
26
+ /* @__PURE__ */ _jsx(App, {
27
+ ...props
28
+ })
29
+ ]
30
+ });
31
+ return AppWrapper;
32
+ });
33
+ }
34
+ });
35
+ export {
36
+ mfSSRDevPlugin
37
+ };
@@ -0,0 +1,88 @@
1
+ import { DATA_FETCH_QUERY, DOWNGRADE_KEY } from "../constant";
2
+ import { MF_DATA_FETCH_STATUS, MF_DATA_FETCH_TYPE } from "../constant";
3
+ import { getDataFetchMap } from "../utils";
4
+ function getDowngradeTag() {
5
+ return globalThis[DOWNGRADE_KEY];
6
+ }
7
+ function callAllDowngrade() {
8
+ const dataFetchMap = getDataFetchMap();
9
+ if (!dataFetchMap) {
10
+ return;
11
+ }
12
+ Object.keys(dataFetchMap).forEach((key) => {
13
+ callDowngrade(key);
14
+ });
15
+ }
16
+ async function callDowngrade(id, params, remoteInfo) {
17
+ const dataFetchMap = getDataFetchMap();
18
+ if (!dataFetchMap) {
19
+ return;
20
+ }
21
+ const mfDataFetch = dataFetchMap[id];
22
+ if ((mfDataFetch === null || mfDataFetch === void 0 ? void 0 : mfDataFetch[2]) === MF_DATA_FETCH_STATUS.AWAIT) {
23
+ mfDataFetch[2] = MF_DATA_FETCH_STATUS.LOADING;
24
+ let promise, res, rej;
25
+ if (mfDataFetch[1]) {
26
+ promise = mfDataFetch[1][0];
27
+ res = mfDataFetch[1][1];
28
+ rej = mfDataFetch[1][2];
29
+ } else {
30
+ promise = new Promise((resolve, reject) => {
31
+ res = resolve;
32
+ rej = reject;
33
+ });
34
+ mfDataFetch[1] = [
35
+ promise,
36
+ res,
37
+ rej
38
+ ];
39
+ }
40
+ const dataFetchType = mfDataFetch[0][1];
41
+ if (dataFetchType === MF_DATA_FETCH_TYPE.FETCH_CLIENT) {
42
+ try {
43
+ mfDataFetch[0][0]().then((getDataFetchFn) => {
44
+ return getDataFetchFn({
45
+ ...params,
46
+ isDowngrade: true
47
+ }).then((data) => {
48
+ mfDataFetch[2] = MF_DATA_FETCH_STATUS.LOADED;
49
+ res(data);
50
+ });
51
+ });
52
+ } catch (e) {
53
+ mfDataFetch[2] = MF_DATA_FETCH_STATUS.ERROR;
54
+ rej(e);
55
+ }
56
+ } else if (dataFetchType === MF_DATA_FETCH_TYPE.FETCH_SERVER) {
57
+ try {
58
+ const currentUrl = new URL(window.location.href);
59
+ currentUrl.searchParams.set(DATA_FETCH_QUERY, encodeURIComponent(id));
60
+ if (params) {
61
+ currentUrl.searchParams.set("params", encodeURIComponent(JSON.stringify(params)));
62
+ }
63
+ if (remoteInfo) {
64
+ currentUrl.searchParams.set("remoteInfo", encodeURIComponent(JSON.stringify(remoteInfo)));
65
+ }
66
+ const fetchServerQuery = globalThis.FEDERATION_SERVER_QUERY;
67
+ if (fetchServerQuery && typeof fetchServerQuery === "object") {
68
+ Object.keys(fetchServerQuery).forEach((key) => {
69
+ currentUrl.searchParams.set(key, JSON.stringify(fetchServerQuery[key]));
70
+ });
71
+ }
72
+ const fetchUrl = currentUrl.toString();
73
+ const data = await fetch(fetchUrl).then((res2) => res2.json());
74
+ mfDataFetch[2] = MF_DATA_FETCH_STATUS.LOADED;
75
+ res(data);
76
+ } catch (e) {
77
+ mfDataFetch[2] = MF_DATA_FETCH_STATUS.ERROR;
78
+ rej(e);
79
+ }
80
+ }
81
+ return promise;
82
+ }
83
+ }
84
+ export {
85
+ callAllDowngrade,
86
+ callDowngrade,
87
+ getDowngradeTag
88
+ };
@@ -0,0 +1,101 @@
1
+ import { DATA_FETCH_FUNCTION, DOWNGRADE_KEY, FS_HREF, MF_DATA_FETCH_STATUS, MF_DATA_FETCH_TYPE } from "../constant";
2
+ import logger from "../logger";
3
+ import { getDataFetchMap, getDataFetchItem, initDataFetchMap } from "../utils";
4
+ import { callAllDowngrade, callDowngrade, getDowngradeTag } from "./downgrade";
5
+ function setSSREnv({ fetchServerQuery }) {
6
+ globalThis.FEDERATION_SSR = true;
7
+ globalThis.FEDERATION_SERVER_QUERY = fetchServerQuery;
8
+ }
9
+ const injectDataFetchFunctionPlugin = ({ fetchServerQuery }) => ({
10
+ name: "@module-federation/inject-data-fetch-function-plugin",
11
+ setup: (api) => {
12
+ api.onBeforeRender(async () => {
13
+ var _globalThis, _DATA_FETCH_FUNCTION;
14
+ setSSREnv({
15
+ fetchServerQuery
16
+ });
17
+ if (typeof window === "undefined") {
18
+ return;
19
+ }
20
+ const dataFetchFunction = async function(options) {
21
+ const [id, data, downgrade] = options;
22
+ logger.debug("==========call data fetch function!");
23
+ if (data) {
24
+ if (!id) {
25
+ throw new Error("id is required!");
26
+ }
27
+ if (!getDataFetchMap()) {
28
+ initDataFetchMap();
29
+ }
30
+ const dataFetchItem = getDataFetchItem(id);
31
+ if (dataFetchItem) {
32
+ var _dataFetchItem__, _dataFetchItem_;
33
+ (_dataFetchItem_ = dataFetchItem[1]) === null || _dataFetchItem_ === void 0 ? void 0 : (_dataFetchItem__ = _dataFetchItem_[1]) === null || _dataFetchItem__ === void 0 ? void 0 : _dataFetchItem__.call(_dataFetchItem_, data);
34
+ dataFetchItem[2] = MF_DATA_FETCH_STATUS.LOADED;
35
+ return;
36
+ }
37
+ if (!dataFetchItem) {
38
+ const dataFetchMap = getDataFetchMap();
39
+ let res;
40
+ let rej;
41
+ const p = new Promise((resolve, reject) => {
42
+ res = resolve;
43
+ rej = reject;
44
+ });
45
+ dataFetchMap[id] = [
46
+ [
47
+ async () => async () => {
48
+ return "";
49
+ },
50
+ MF_DATA_FETCH_TYPE.FETCH_SERVER
51
+ ],
52
+ [
53
+ p,
54
+ res,
55
+ rej
56
+ ],
57
+ MF_DATA_FETCH_STATUS.LOADED
58
+ ];
59
+ res(data);
60
+ return;
61
+ }
62
+ }
63
+ if (downgrade) {
64
+ const mfDowngrade2 = getDowngradeTag();
65
+ if (!mfDowngrade2) {
66
+ globalThis[DOWNGRADE_KEY] = id ? [
67
+ id
68
+ ] : true;
69
+ } else if (Array.isArray(mfDowngrade2) && id && !mfDowngrade2.includes(id)) {
70
+ mfDowngrade2.push(id);
71
+ }
72
+ }
73
+ const mfDowngrade = getDowngradeTag();
74
+ if (typeof mfDowngrade === "boolean") {
75
+ return callAllDowngrade();
76
+ }
77
+ if (Array.isArray(mfDowngrade)) {
78
+ if (!id) {
79
+ globalThis[DOWNGRADE_KEY] = true;
80
+ return callAllDowngrade();
81
+ }
82
+ if (!mfDowngrade.includes(id)) {
83
+ mfDowngrade.push(id);
84
+ }
85
+ return callDowngrade(id);
86
+ }
87
+ };
88
+ globalThis[FS_HREF] = window.location.href;
89
+ (_globalThis = globalThis)[_DATA_FETCH_FUNCTION = DATA_FETCH_FUNCTION] || (_globalThis[_DATA_FETCH_FUNCTION] = []);
90
+ const dataFetch = globalThis[DATA_FETCH_FUNCTION];
91
+ await Promise.all(dataFetch.map(async (options) => {
92
+ await dataFetchFunction(options);
93
+ }));
94
+ dataFetch.push = dataFetchFunction;
95
+ });
96
+ }
97
+ });
98
+ export {
99
+ injectDataFetchFunctionPlugin,
100
+ setSSREnv
101
+ };
File without changes
@@ -0,0 +1,166 @@
1
+ import { isBrowserEnv, composeKeyWithSeparator } from "@module-federation/sdk";
2
+ import { isCSROnly } from "../utils";
3
+ import logger from "../logger";
4
+ import { callDowngrade, getDowngradeTag } from "../ssr-runtime/downgrade";
5
+ import { DOWNGRADE_KEY, MF_DATA_FETCH_STATUS, WRAP_DATA_FETCH_ID_IDENTIFIER } from "../constant";
6
+ import { DATA_FETCH_CLIENT_SUFFIX, DATA_FETCH_IDENTIFIER } from "@module-federation/rsbuild-plugin/constant";
7
+ const getDataFetchInfo = ({ name, alias, id, remoteSnapshot }) => {
8
+ if (!remoteSnapshot) {
9
+ return;
10
+ }
11
+ if (!("modules" in remoteSnapshot)) {
12
+ return;
13
+ }
14
+ const regex = new RegExp(`^${name}(/[^/].*|)$`);
15
+ const nameOrAlias = regex.test(id) ? name : alias || name;
16
+ const expose = id.replace(nameOrAlias, "");
17
+ let dataFetchName = "";
18
+ let dataFetchId = "";
19
+ if (expose.startsWith("/")) {
20
+ dataFetchName = `${expose.slice(1)}.${DATA_FETCH_IDENTIFIER}`;
21
+ dataFetchId = `${id}.${DATA_FETCH_IDENTIFIER}`;
22
+ } else if (expose === "") {
23
+ dataFetchName = DATA_FETCH_IDENTIFIER;
24
+ dataFetchId = `${id}/${DATA_FETCH_IDENTIFIER}`;
25
+ } else {
26
+ return;
27
+ }
28
+ if (!dataFetchName || !dataFetchId) {
29
+ return;
30
+ }
31
+ if (!remoteSnapshot.modules.find((module) => module.moduleName === dataFetchName)) {
32
+ return;
33
+ }
34
+ return {
35
+ dataFetchName,
36
+ dataFetchId
37
+ };
38
+ };
39
+ function initDataFetchMap() {
40
+ var _globalThis;
41
+ (_globalThis = globalThis).__MF_DATA_FETCH_MAP__ || (_globalThis.__MF_DATA_FETCH_MAP__ = {});
42
+ }
43
+ function getDataFetchItem(id) {
44
+ var _globalThis___MF_DATA_FETCH_MAP__;
45
+ 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];
46
+ }
47
+ function getDataFetchMap() {
48
+ return globalThis.__MF_DATA_FETCH_MAP__;
49
+ }
50
+ const flushDataFetch = () => {
51
+ globalThis.__MF_DATA_FETCH_MAP__ = {};
52
+ globalThis[DOWNGRADE_KEY] = void 0;
53
+ };
54
+ function setDataFetchItemLoadedStatus(id) {
55
+ const dataFetchItem = getDataFetchItem(id);
56
+ if (!dataFetchItem) {
57
+ return;
58
+ }
59
+ dataFetchItem[2] = MF_DATA_FETCH_STATUS.LOADED;
60
+ }
61
+ const wrapDataFetchId = (id) => {
62
+ return `${WRAP_DATA_FETCH_ID_IDENTIFIER}${id}${WRAP_DATA_FETCH_ID_IDENTIFIER}`;
63
+ };
64
+ const getDataFetchIdWithErrorMsgs = (errMsgs) => {
65
+ const firstIdentifierIndex = errMsgs.indexOf(WRAP_DATA_FETCH_ID_IDENTIFIER);
66
+ if (firstIdentifierIndex === -1) {
67
+ return void 0;
68
+ }
69
+ const secondIdentifierIndex = errMsgs.indexOf(WRAP_DATA_FETCH_ID_IDENTIFIER, firstIdentifierIndex + WRAP_DATA_FETCH_ID_IDENTIFIER.length);
70
+ if (secondIdentifierIndex === -1) {
71
+ return void 0;
72
+ }
73
+ return errMsgs.substring(firstIdentifierIndex + WRAP_DATA_FETCH_ID_IDENTIFIER.length, secondIdentifierIndex);
74
+ };
75
+ async function fetchData(id, params, remoteInfo) {
76
+ const callFetchData = async () => {
77
+ const item = getDataFetchItem(id);
78
+ if (!item) {
79
+ return;
80
+ }
81
+ const [fetchDataFnArr, ..._rest] = item;
82
+ const fetchDataFn = await fetchDataFnArr[2];
83
+ if (!fetchDataFn) {
84
+ return;
85
+ }
86
+ return fetchDataFn(params);
87
+ };
88
+ if (isBrowserEnv()) {
89
+ var _dataFetchItem_;
90
+ const dataFetchItem = getDataFetchItem(id);
91
+ if (!dataFetchItem) {
92
+ throw new Error(`dataFetchItem not found, id: ${id}`);
93
+ }
94
+ if ((_dataFetchItem_ = dataFetchItem[1]) === null || _dataFetchItem_ === void 0 ? void 0 : _dataFetchItem_[0]) {
95
+ return dataFetchItem[1][0];
96
+ }
97
+ if (isCSROnly()) {
98
+ logger.debug("==========csr only!");
99
+ return callFetchData();
100
+ }
101
+ if (remoteInfo) {
102
+ return callDowngrade(id, params, remoteInfo);
103
+ }
104
+ const mfDowngrade = getDowngradeTag();
105
+ if (mfDowngrade) {
106
+ if (typeof mfDowngrade === "boolean") {
107
+ return callDowngrade(id, {
108
+ ...params,
109
+ isDowngrade: true
110
+ });
111
+ }
112
+ if (mfDowngrade.includes(id)) {
113
+ return callDowngrade(id, {
114
+ ...params,
115
+ isDowngrade: true
116
+ });
117
+ }
118
+ }
119
+ let res;
120
+ let rej;
121
+ const p = new Promise((resolve, reject) => {
122
+ res = resolve;
123
+ rej = reject;
124
+ });
125
+ dataFetchItem[1] = [
126
+ p,
127
+ res,
128
+ rej
129
+ ];
130
+ dataFetchItem[2] = MF_DATA_FETCH_STATUS.AWAIT;
131
+ return dataFetchItem[1][0];
132
+ }
133
+ return callFetchData();
134
+ }
135
+ function getDataFetchMapKey(dataFetchInfo, hostInfo) {
136
+ if (!dataFetchInfo || !hostInfo) {
137
+ return;
138
+ }
139
+ const { dataFetchId } = dataFetchInfo;
140
+ return composeKeyWithSeparator(dataFetchId, hostInfo.name, hostInfo.version);
141
+ }
142
+ async function loadDataFetchModule(instance, id) {
143
+ return instance.loadRemote(id).then((m) => {
144
+ if (m && typeof m === "object" && "fetchData" in m && typeof m.fetchData === "function") {
145
+ return m.fetchData;
146
+ }
147
+ throw new Error(`fetchData not found in remote ${id}, ${JSON.stringify(m)}`);
148
+ });
149
+ }
150
+ function isDataLoaderExpose(exposeKey) {
151
+ return exposeKey.endsWith(DATA_FETCH_IDENTIFIER) || exposeKey.endsWith(DATA_FETCH_CLIENT_SUFFIX);
152
+ }
153
+ export {
154
+ fetchData,
155
+ flushDataFetch,
156
+ getDataFetchIdWithErrorMsgs,
157
+ getDataFetchInfo,
158
+ getDataFetchItem,
159
+ getDataFetchMap,
160
+ getDataFetchMapKey,
161
+ initDataFetchMap,
162
+ isDataLoaderExpose,
163
+ loadDataFetchModule,
164
+ setDataFetchItemLoadedStatus,
165
+ wrapDataFetchId
166
+ };
@@ -0,0 +1,27 @@
1
+ function getLoadedRemoteInfos(id, instance) {
2
+ if (!instance) {
3
+ return;
4
+ }
5
+ const { name, expose } = instance.remoteHandler.idToRemoteMap[id] || {};
6
+ if (!name) {
7
+ return;
8
+ }
9
+ const module = instance.moduleCache.get(name);
10
+ if (!module) {
11
+ return;
12
+ }
13
+ const { remoteSnapshot } = instance.snapshotHandler.getGlobalRemoteInfo(module.remoteInfo);
14
+ return {
15
+ ...module.remoteInfo,
16
+ snapshot: remoteSnapshot,
17
+ expose
18
+ };
19
+ }
20
+ function isCSROnly() {
21
+ return window._SSR_DATA === void 0;
22
+ }
23
+ export * from "./dataFetch";
24
+ export {
25
+ getLoadedRemoteInfos,
26
+ isCSROnly
27
+ };
@@ -0,0 +1,21 @@
1
+ import { isWebTarget, skipByTarget } from './utils';
2
+ import { moduleFederationPlugin } from '@module-federation/sdk';
3
+ import { PluginOptions } from '../types';
4
+ import type { InternalModernPluginOptions } from '../types';
5
+ import type { AppTools, webpack, UserConfig, Rspack, CliPluginFuture } from '@modern-js/app-tools';
6
+ import type { BundlerChainConfig } from '../interfaces/bundler';
7
+ export type ConfigType<T> = T extends 'webpack' ? webpack.Configuration : T extends 'rspack' ? Rspack.Configuration : never;
8
+ export declare function setEnv(enableSSR: boolean): void;
9
+ export declare const getMFConfig: (userConfig: PluginOptions) => Promise<moduleFederationPlugin.ModuleFederationPluginOptions>;
10
+ export declare const patchMFConfig: (mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions, isServer: boolean, remoteIpStrategy?: "ipv4" | "inherit", enableSSR?: boolean) => moduleFederationPlugin.ModuleFederationPluginOptions;
11
+ export declare function addMyTypes2Ignored(chain: BundlerChainConfig, mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions): void;
12
+ export declare function patchBundlerConfig(options: {
13
+ chain: BundlerChainConfig;
14
+ isServer: boolean;
15
+ modernjsConfig: UserConfig<AppTools>;
16
+ mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions;
17
+ enableSSR: boolean;
18
+ }): void;
19
+ export declare const moduleFederationConfigPlugin: (userConfig: InternalModernPluginOptions) => CliPluginFuture<AppTools>;
20
+ export default moduleFederationConfigPlugin;
21
+ export { isWebTarget, skipByTarget };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ import type { CliPluginFuture, AppTools } from '@modern-js/app-tools';
2
+ import type { PluginOptions } from '../types';
3
+ export declare const moduleFederationPlugin: (userConfig?: PluginOptions) => CliPluginFuture<AppTools>;
4
+ export default moduleFederationPlugin;
5
+ export { createModuleFederationConfig } from '@module-federation/enhanced';
6
+ export type { FederationRuntimePlugin } from '@module-federation/enhanced/runtime';
@@ -0,0 +1,3 @@
1
+ import type { FederationRuntimePlugin } from '@module-federation/enhanced/runtime';
2
+ declare const autoFetchData: () => FederationRuntimePlugin;
3
+ export default autoFetchData;
@@ -0,0 +1,3 @@
1
+ import type { FederationRuntimePlugin } from '@module-federation/enhanced/runtime';
2
+ declare const injectNodeFetchPlugin: () => FederationRuntimePlugin;
3
+ export default injectNodeFetchPlugin;
@@ -0,0 +1,3 @@
1
+ import type { FederationRuntimePlugin } from '@module-federation/enhanced/runtime';
2
+ declare const resolveEntryIpv4Plugin: () => FederationRuntimePlugin;
3
+ export default resolveEntryIpv4Plugin;
@@ -0,0 +1,3 @@
1
+ import type { FederationRuntimePlugin } from '@module-federation/enhanced/runtime';
2
+ declare const sharedStrategy: () => FederationRuntimePlugin;
3
+ export default sharedStrategy;
@@ -0,0 +1,3 @@
1
+ import type { ServerPlugin } from '@modern-js/server-runtime';
2
+ declare const dataFetchServePlugin: () => ServerPlugin;
3
+ export default dataFetchServePlugin;
@@ -0,0 +1,6 @@
1
+ import type { CliPluginFuture, AppTools } from '@modern-js/app-tools';
2
+ import type { InternalModernPluginOptions } from '../types';
3
+ export declare function setEnv(): void;
4
+ export declare const CHAIN_MF_PLUGIN_ID = "plugin-module-federation-server";
5
+ export declare const moduleFederationSSRPlugin: (pluginOptions: Required<InternalModernPluginOptions>) => CliPluginFuture<AppTools>;
6
+ export default moduleFederationSSRPlugin;
@@ -0,0 +1,6 @@
1
+ import type { webpack, Rspack } from '@modern-js/app-tools';
2
+ export type ConfigType<T> = T extends 'webpack' ? webpack.Configuration : T extends 'rspack' ? Rspack.Configuration : never;
3
+ export declare const getIPV4: () => string;
4
+ export declare const isWebTarget: (target: string[] | string) => boolean;
5
+ export declare const skipByTarget: (target: string[] | string) => boolean;
6
+ export declare function isDev(): boolean;
@@ -0,0 +1,25 @@
1
+ export declare const LOCALHOST = "localhost";
2
+ export declare const PLUGIN_IDENTIFIER = "[ Modern.js Module Federation ]";
3
+ export declare const DATA_FETCH_QUERY = "x-mf-data-fetch";
4
+ export declare const DATA_FETCH_ERROR_PREFIX = "caught the following error during dataFetch: ";
5
+ export declare const LOAD_REMOTE_ERROR_PREFIX = "caught the following error during loadRemote: ";
6
+ export declare const DOWNGRADE_KEY = "_mfSSRDowngrade";
7
+ export declare const DATA_FETCH_MAP_KEY = "__MF_DATA_FETCH_MAP__";
8
+ export declare const DATA_FETCH_FUNCTION = "_mfDataFetch";
9
+ export declare const FS_HREF = "_mfFSHref";
10
+ export declare const ERROR_TYPE: {
11
+ DATA_FETCH: number;
12
+ LOAD_REMOTE: number;
13
+ UNKNOWN: number;
14
+ };
15
+ export declare const WRAP_DATA_FETCH_ID_IDENTIFIER = "wrap_dfip_identifier";
16
+ export declare const enum MF_DATA_FETCH_TYPE {
17
+ FETCH_SERVER = 1,
18
+ FETCH_CLIENT = 2
19
+ }
20
+ export declare const enum MF_DATA_FETCH_STATUS {
21
+ LOADED = 1,
22
+ LOADING = 2,
23
+ AWAIT = 0,
24
+ ERROR = 3
25
+ }
@@ -0,0 +1,18 @@
1
+ import type { AppTools, Bundler, UserConfig } from '@modern-js/app-tools';
2
+ type AppToolsUserConfig<T extends Bundler> = AppTools<T>['userConfig']['tools'];
3
+ type ExcludeUndefined<T> = T extends undefined ? never : T;
4
+ type ExtractObjectType<T> = T extends (...args: any[]) => any ? never : T;
5
+ type OmitArrayConfiguration<T> = T extends Array<any> ? (T extends (infer U)[] ? U : T) : ExtractObjectType<T>;
6
+ type WebpackConfigs = ExcludeUndefined<AppToolsUserConfig<'webpack'>> extends {
7
+ webpack?: infer U;
8
+ } ? U : never;
9
+ type ObjectWebpack = ExtractObjectType<OmitArrayConfiguration<WebpackConfigs>>;
10
+ type RspackConfigs = ExcludeUndefined<AppToolsUserConfig<'rspack'>> extends {
11
+ rspack?: infer U;
12
+ } ? U : never;
13
+ type ObjectRspack = ExtractObjectType<OmitArrayConfiguration<RspackConfigs>>;
14
+ type BundlerChain = ExcludeUndefined<ExcludeUndefined<UserConfig<AppTools>['tools']>['bundlerChain']>;
15
+ type BundlerChainFunc = Extract<BundlerChain, (chain: any, utils: any) => any>;
16
+ export type BundlerChainConfig = Parameters<BundlerChainFunc>[0];
17
+ export type BundlerConfig<T extends Bundler> = T extends 'rspack' ? ObjectRspack : ObjectWebpack;
18
+ export {};
@@ -0,0 +1,27 @@
1
+ import { MF_DATA_FETCH_TYPE, MF_DATA_FETCH_STATUS } from '../constant';
2
+ export type DataFetchParams = {
3
+ isDowngrade: boolean;
4
+ } & Record<string, unknown>;
5
+ export type DataFetch<T> = (params: DataFetchParams) => Promise<T>;
6
+ export type MF_DATA_FETCH_MAP_VALUE = [
7
+ [
8
+ () => Promise<DataFetch<unknown>>,
9
+ MF_DATA_FETCH_TYPE,
10
+ Promise<DataFetch<unknown>>?
11
+ ],
12
+ [
13
+ Promise<unknown>,
14
+ ((data: unknown) => void)?,
15
+ ((err: unknown) => void)?
16
+ ]?,
17
+ MF_DATA_FETCH_STATUS?
18
+ ];
19
+ export type MF_DATA_FETCH_MAP = Record<string, MF_DATA_FETCH_MAP_VALUE>;
20
+ export type MF_SSR_DOWNGRADE = string[] | true | undefined;
21
+ export type NoSSRRemoteInfo = {
22
+ name: string;
23
+ version: string;
24
+ ssrPublicPath: string;
25
+ ssrRemoteEntry: string;
26
+ globalName: string;
27
+ };
@@ -0,0 +1,2 @@
1
+ declare const logger: import("@module-federation/sdk").Logger;
2
+ export default logger;
@@ -0,0 +1,19 @@
1
+ import React, { ReactNode } from 'react';
2
+ import type { DataFetchParams } from '../interfaces/global';
3
+ export type ErrorInfo = {
4
+ error: Error;
5
+ errorType: number;
6
+ dataFetchMapKey?: string;
7
+ };
8
+ export declare const transformError: (err: string | Error) => ErrorInfo;
9
+ export interface AwaitProps<T> {
10
+ resolve: T | Promise<T>;
11
+ loading?: ReactNode;
12
+ errorElement?: ReactNode | ((errorInfo: ErrorInfo) => ReactNode);
13
+ children: (data: T) => ReactNode;
14
+ params?: DataFetchParams;
15
+ }
16
+ export interface AwaitErrorHandlerProps<T = any> extends Omit<AwaitProps<T>, 'resolve'> {
17
+ resolve: () => T | string;
18
+ }
19
+ export declare function AwaitDataFetch<T>({ resolve, loading, errorElement, children, params, }: AwaitProps<T>): React.JSX.Element;
@@ -0,0 +1,26 @@
1
+ import React, { ReactNode } from 'react';
2
+ import type { ErrorInfo } from './AwaitDataFetch';
3
+ import type { DataFetchParams } from '../interfaces/global';
4
+ type IProps = {
5
+ id: string;
6
+ injectScript?: boolean;
7
+ injectLink?: boolean;
8
+ };
9
+ export type CreateRemoteComponentOptions<T, E extends keyof T> = {
10
+ loader: () => Promise<T>;
11
+ loading: React.ReactNode;
12
+ fallback: ReactNode | ((errorInfo: ErrorInfo) => ReactNode);
13
+ export?: E;
14
+ dataFetchParams?: DataFetchParams;
15
+ noSSR?: boolean;
16
+ };
17
+ type ReactKey = {
18
+ key?: React.Key | null;
19
+ };
20
+ export declare function collectSSRAssets(options: IProps): React.ReactNode[];
21
+ export declare function createRemoteComponent<T, E extends keyof T>(options: CreateRemoteComponentOptions<T, E>): (props: T[E] extends (...args: any) => any ? Parameters<T[E]>[0] extends undefined ? ReactKey : Parameters<T[E]>[0] & ReactKey : ReactKey) => React.JSX.Element;
22
+ /**
23
+ * @deprecated createRemoteSSRComponent is deprecated, please use createRemoteComponent instead!
24
+ */
25
+ export declare function createRemoteSSRComponent<T, E extends keyof T>(options: CreateRemoteComponentOptions<T, E>): (props: T[E] extends (...args: any) => any ? Parameters<T[E]>[0] extends undefined ? ReactKey : Parameters<T[E]>[0] & ReactKey : ReactKey) => React.JSX.Element;
26
+ export {};
@@ -0,0 +1,10 @@
1
+ export * from '@module-federation/enhanced/runtime';
2
+ export type { DataFetchParams } from '../interfaces/global';
3
+ export { ERROR_TYPE } from '../constant';
4
+ export declare const kit: {
5
+ readonly createRemoteSSRComponent: typeof import("./createRemoteComponent").createRemoteSSRComponent;
6
+ readonly createRemoteComponent: typeof import("./createRemoteComponent").createRemoteComponent;
7
+ readonly collectSSRAssets: typeof import("./createRemoteComponent").collectSSRAssets;
8
+ readonly wrapNoSSR: typeof import("./wrapNoSSR").wrapNoSSR;
9
+ };
10
+ export { setSSREnv } from '../ssr-runtime/injectDataFetchFunctionPlugin';
@@ -0,0 +1,9 @@
1
+ import { createRemoteComponent } from './createRemoteComponent';
2
+ import type { CreateRemoteComponentOptions } from './createRemoteComponent';
3
+ export declare function wrapNoSSR<T, E extends keyof T>(createComponentFn: typeof createRemoteComponent<T, E>): (options: Omit<CreateRemoteComponentOptions<T, E>, "noSSR">) => (props: T[E] extends (...args: any) => any ? Parameters<T[E]>[0] extends undefined ? {
4
+ key?: import("react").Key | null;
5
+ } : Parameters<T[E]>[0] & {
6
+ key?: import("react").Key | null;
7
+ } : {
8
+ key?: import("react").Key | null;
9
+ }) => import("react").JSX.Element;
@@ -0,0 +1,14 @@
1
+ export interface FileResult {
2
+ content: string;
3
+ lastModified: number;
4
+ }
5
+ export declare class FileCache {
6
+ private cache;
7
+ /**
8
+ * Check if file exists and return file info
9
+ * @param filepath Path to the file
10
+ * @returns FileResult or null if file doesn't exist
11
+ */
12
+ getFile(filepath: string): Promise<FileResult | null>;
13
+ }
14
+ export declare const fileCache: FileCache;
@@ -0,0 +1 @@
1
+ export {};