@module-federation/modern-js 0.0.0-next-20250613153606 → 0.0.0-next-20250616091910
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.
- package/dist/cjs/cli/configPlugin.js +1 -1
- package/dist/cjs/cli/configPlugin.spec.js +2 -2
- package/dist/cjs/cli/server/data-fetch-server-plugin.js +9 -10
- package/dist/cjs/constant.js +2 -49
- package/dist/cjs/runtime/index.js +3 -20
- package/dist/cjs/ssr-runtime/devPlugin.js +2 -2
- package/dist/cjs/ssr-runtime/injectDataFetchFunctionPlugin.js +6 -101
- package/dist/esm/cli/configPlugin.js +1 -1
- package/dist/esm/cli/configPlugin.spec.js +2 -2
- package/dist/esm/cli/server/data-fetch-server-plugin.js +3 -4
- package/dist/esm/constant.js +1 -37
- package/dist/esm/runtime/index.js +2 -18
- package/dist/esm/ssr-runtime/devPlugin.js +1 -1
- package/dist/esm/ssr-runtime/injectDataFetchFunctionPlugin.js +5 -147
- package/dist/esm-node/cli/configPlugin.js +1 -1
- package/dist/esm-node/cli/configPlugin.spec.js +2 -2
- package/dist/esm-node/cli/server/data-fetch-server-plugin.js +3 -4
- package/dist/esm-node/constant.js +1 -37
- package/dist/esm-node/runtime/index.js +2 -18
- package/dist/esm-node/ssr-runtime/devPlugin.js +1 -1
- package/dist/esm-node/ssr-runtime/injectDataFetchFunctionPlugin.js +5 -89
- package/dist/types/constant.d.ts +0 -23
- package/dist/types/runtime/index.d.ts +2 -9
- package/dist/types/ssr-runtime/injectDataFetchFunctionPlugin.d.ts +0 -3
- package/package.json +9 -16
- package/dist/cjs/cli/mfRuntimePlugins/auto-fetch-data.js +0 -100
- package/dist/cjs/interfaces/global.js +0 -16
- package/dist/cjs/runtime/AwaitDataFetch.js +0 -144
- package/dist/cjs/runtime/createRemoteComponent.js +0 -327
- package/dist/cjs/runtime/wrapNoSSR.js +0 -35
- package/dist/cjs/ssr-runtime/downgrade.js +0 -114
- package/dist/cjs/utils/dataFetch.js +0 -211
- package/dist/cjs/utils/index.js +0 -54
- package/dist/esm/cli/mfRuntimePlugins/auto-fetch-data.js +0 -76
- package/dist/esm/interfaces/global.js +0 -0
- package/dist/esm/runtime/AwaitDataFetch.js +0 -131
- package/dist/esm/runtime/createRemoteComponent.js +0 -417
- package/dist/esm/runtime/wrapNoSSR.js +0 -12
- package/dist/esm/ssr-runtime/downgrade.js +0 -150
- package/dist/esm/utils/dataFetch.js +0 -237
- package/dist/esm/utils/index.js +0 -28
- package/dist/esm-node/cli/mfRuntimePlugins/auto-fetch-data.js +0 -70
- package/dist/esm-node/interfaces/global.js +0 -0
- package/dist/esm-node/runtime/AwaitDataFetch.js +0 -109
- package/dist/esm-node/runtime/createRemoteComponent.js +0 -291
- package/dist/esm-node/runtime/wrapNoSSR.js +0 -11
- package/dist/esm-node/ssr-runtime/downgrade.js +0 -88
- package/dist/esm-node/utils/dataFetch.js +0 -166
- package/dist/esm-node/utils/index.js +0 -27
- package/dist/types/cli/mfRuntimePlugins/auto-fetch-data.d.ts +0 -3
- package/dist/types/interfaces/global.d.ts +0 -27
- package/dist/types/runtime/AwaitDataFetch.d.ts +0 -19
- package/dist/types/runtime/createRemoteComponent.d.ts +0 -26
- package/dist/types/runtime/wrapNoSSR.d.ts +0 -9
- package/dist/types/ssr-runtime/downgrade.d.ts +0 -4
- package/dist/types/utils/dataFetch.d.ts +0 -26
- package/dist/types/utils/index.d.ts +0 -15
|
@@ -148,7 +148,7 @@ const patchMFConfig = (mfConfig, isServer, remoteIpStrategy, enableSSR) => {
|
|
|
148
148
|
];
|
|
149
149
|
patchDTSConfig(mfConfig, isServer);
|
|
150
150
|
injectRuntimePlugins(require.resolve("@module-federation/modern-js/shared-strategy"), runtimePlugins);
|
|
151
|
-
injectRuntimePlugins(require.resolve("@module-federation/
|
|
151
|
+
injectRuntimePlugins(require.resolve("@module-federation/bridge-react/data-fetch-runtime-plugin"), runtimePlugins);
|
|
152
152
|
if (enableSSR && (0, import_utils3.isDev)()) {
|
|
153
153
|
injectRuntimePlugins(require.resolve("@module-federation/modern-js/resolve-entry-ipv4"), runtimePlugins);
|
|
154
154
|
}
|
|
@@ -61,7 +61,7 @@ const mfConfig = {
|
|
|
61
61
|
remoteType: "script",
|
|
62
62
|
runtimePlugins: [
|
|
63
63
|
require.resolve("@module-federation/modern-js/shared-strategy"),
|
|
64
|
-
require.resolve("@module-federation/
|
|
64
|
+
require.resolve("@module-federation/bridge-react/data-fetch-runtime-plugin"),
|
|
65
65
|
require.resolve("@module-federation/node/runtimePlugin"),
|
|
66
66
|
require.resolve("@module-federation/modern-js/inject-node-fetch")
|
|
67
67
|
],
|
|
@@ -90,7 +90,7 @@ const mfConfig = {
|
|
|
90
90
|
remoteType: "script",
|
|
91
91
|
runtimePlugins: [
|
|
92
92
|
require.resolve("@module-federation/modern-js/shared-strategy"),
|
|
93
|
-
require.resolve("@module-federation/
|
|
93
|
+
require.resolve("@module-federation/bridge-react/data-fetch-runtime-plugin")
|
|
94
94
|
],
|
|
95
95
|
shared: {
|
|
96
96
|
react: {
|
|
@@ -31,11 +31,10 @@ __export(data_fetch_server_plugin_exports, {
|
|
|
31
31
|
default: () => data_fetch_server_plugin_default
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(data_fetch_server_plugin_exports);
|
|
34
|
-
var
|
|
35
|
-
var
|
|
36
|
-
var import_utils = require("../../utils");
|
|
37
|
-
var import_dataFetch = require("../../utils/dataFetch");
|
|
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");
|
|
38
36
|
var import_sdk = require("@module-federation/sdk");
|
|
37
|
+
var import_logger = __toESM(require("../../logger"));
|
|
39
38
|
function wrapSetTimeout(targetPromise, delay = 2e4, id) {
|
|
40
39
|
if (targetPromise && typeof targetPromise.then === "function") {
|
|
41
40
|
return new Promise((resolve, reject) => {
|
|
@@ -74,7 +73,7 @@ const middleware = async (ctx, next) => {
|
|
|
74
73
|
let remoteInfo;
|
|
75
74
|
try {
|
|
76
75
|
url = new URL(ctx.req.url);
|
|
77
|
-
dataFetchId = getDecodeQuery(url,
|
|
76
|
+
dataFetchId = getDecodeQuery(url, import_data_fetch_constant.DATA_FETCH_QUERY);
|
|
78
77
|
params = JSON.parse(getDecodeQuery(url, "params") || "{}");
|
|
79
78
|
const remoteInfoQuery = getDecodeQuery(url, "remoteInfo");
|
|
80
79
|
remoteInfo = remoteInfoQuery ? JSON.parse(remoteInfoQuery) : null;
|
|
@@ -89,13 +88,13 @@ const middleware = async (ctx, next) => {
|
|
|
89
88
|
import_logger.default.debug("fetch data from server, moduleInfo: ", (_globalThis___FEDERATION__ = globalThis.__FEDERATION__) === null || _globalThis___FEDERATION__ === void 0 ? void 0 : _globalThis___FEDERATION__.moduleInfo);
|
|
90
89
|
try {
|
|
91
90
|
var _dataFetchMap_dataFetchId, _dataFetchMap_dataFetchId1;
|
|
92
|
-
const dataFetchMap = (0,
|
|
91
|
+
const dataFetchMap = (0, import_data_fetch_utils.getDataFetchMap)();
|
|
93
92
|
if (!dataFetchMap) {
|
|
94
|
-
(0,
|
|
93
|
+
(0, import_data_fetch_utils.initDataFetchMap)();
|
|
95
94
|
}
|
|
96
95
|
const fetchDataPromise = (_dataFetchMap_dataFetchId = dataFetchMap[dataFetchId]) === null || _dataFetchMap_dataFetchId === void 0 ? void 0 : _dataFetchMap_dataFetchId[1];
|
|
97
96
|
import_logger.default.debug("fetch data from server, fetchDataPromise: ", fetchDataPromise);
|
|
98
|
-
if (fetchDataPromise && ((_dataFetchMap_dataFetchId1 = dataFetchMap[dataFetchId]) === null || _dataFetchMap_dataFetchId1 === void 0 ? void 0 : _dataFetchMap_dataFetchId1[2]) !==
|
|
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) {
|
|
99
98
|
const targetPromise = fetchDataPromise[0];
|
|
100
99
|
const wrappedPromise = wrapSetTimeout(targetPromise, 2e4, dataFetchId);
|
|
101
100
|
if (wrappedPromise) {
|
|
@@ -143,7 +142,7 @@ const middleware = async (ctx, next) => {
|
|
|
143
142
|
const dataFetchItem = dataFetchMap[dataFetchId];
|
|
144
143
|
import_logger.default.debug("fetch data from server, dataFetchItem: ", dataFetchItem);
|
|
145
144
|
if (dataFetchItem) {
|
|
146
|
-
const callFetchDataPromise = (0,
|
|
145
|
+
const callFetchDataPromise = (0, import_data_fetch_utils.fetchData)(dataFetchId, {
|
|
147
146
|
...params,
|
|
148
147
|
isDowngrade: !remoteInfo
|
|
149
148
|
});
|
|
@@ -159,7 +158,7 @@ const middleware = async (ctx, next) => {
|
|
|
159
158
|
if (!hostInstance) {
|
|
160
159
|
throw new Error("host instance not found!");
|
|
161
160
|
}
|
|
162
|
-
const dataFetchFn = await (0,
|
|
161
|
+
const dataFetchFn = await (0, import_data_fetch_utils.loadDataFetchModule)(hostInstance, remoteId);
|
|
163
162
|
const data = await dataFetchFn({
|
|
164
163
|
...params,
|
|
165
164
|
isDowngrade: !remoteInfo
|
package/dist/cjs/constant.js
CHANGED
|
@@ -18,61 +18,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var constant_exports = {};
|
|
20
20
|
__export(constant_exports, {
|
|
21
|
-
DATA_FETCH_ERROR_PREFIX: () => DATA_FETCH_ERROR_PREFIX,
|
|
22
|
-
DATA_FETCH_FUNCTION: () => DATA_FETCH_FUNCTION,
|
|
23
|
-
DATA_FETCH_MAP_KEY: () => DATA_FETCH_MAP_KEY,
|
|
24
|
-
DATA_FETCH_QUERY: () => DATA_FETCH_QUERY,
|
|
25
|
-
DOWNGRADE_KEY: () => DOWNGRADE_KEY,
|
|
26
|
-
ERROR_TYPE: () => ERROR_TYPE,
|
|
27
|
-
FS_HREF: () => FS_HREF,
|
|
28
|
-
LOAD_REMOTE_ERROR_PREFIX: () => LOAD_REMOTE_ERROR_PREFIX,
|
|
29
21
|
LOCALHOST: () => LOCALHOST,
|
|
30
|
-
|
|
31
|
-
MF_DATA_FETCH_TYPE: () => MF_DATA_FETCH_TYPE,
|
|
32
|
-
PLUGIN_IDENTIFIER: () => PLUGIN_IDENTIFIER,
|
|
33
|
-
WRAP_DATA_FETCH_ID_IDENTIFIER: () => WRAP_DATA_FETCH_ID_IDENTIFIER
|
|
22
|
+
PLUGIN_IDENTIFIER: () => PLUGIN_IDENTIFIER
|
|
34
23
|
});
|
|
35
24
|
module.exports = __toCommonJS(constant_exports);
|
|
36
25
|
const LOCALHOST = "localhost";
|
|
37
26
|
const PLUGIN_IDENTIFIER = "[ Modern.js Module Federation ]";
|
|
38
|
-
const DATA_FETCH_QUERY = "x-mf-data-fetch";
|
|
39
|
-
const DATA_FETCH_ERROR_PREFIX = "caught the following error during dataFetch: ";
|
|
40
|
-
const LOAD_REMOTE_ERROR_PREFIX = "caught the following error during loadRemote: ";
|
|
41
|
-
const DOWNGRADE_KEY = "_mfSSRDowngrade";
|
|
42
|
-
const DATA_FETCH_MAP_KEY = "__MF_DATA_FETCH_MAP__";
|
|
43
|
-
const DATA_FETCH_FUNCTION = "_mfDataFetch";
|
|
44
|
-
const FS_HREF = "_mfFSHref";
|
|
45
|
-
const ERROR_TYPE = {
|
|
46
|
-
DATA_FETCH: 1,
|
|
47
|
-
LOAD_REMOTE: 2,
|
|
48
|
-
UNKNOWN: 3
|
|
49
|
-
};
|
|
50
|
-
const WRAP_DATA_FETCH_ID_IDENTIFIER = "wrap_dfip_identifier";
|
|
51
|
-
var MF_DATA_FETCH_TYPE;
|
|
52
|
-
(function(MF_DATA_FETCH_TYPE2) {
|
|
53
|
-
MF_DATA_FETCH_TYPE2[MF_DATA_FETCH_TYPE2["FETCH_SERVER"] = 1] = "FETCH_SERVER";
|
|
54
|
-
MF_DATA_FETCH_TYPE2[MF_DATA_FETCH_TYPE2["FETCH_CLIENT"] = 2] = "FETCH_CLIENT";
|
|
55
|
-
})(MF_DATA_FETCH_TYPE || (MF_DATA_FETCH_TYPE = {}));
|
|
56
|
-
var MF_DATA_FETCH_STATUS;
|
|
57
|
-
(function(MF_DATA_FETCH_STATUS2) {
|
|
58
|
-
MF_DATA_FETCH_STATUS2[MF_DATA_FETCH_STATUS2["LOADED"] = 1] = "LOADED";
|
|
59
|
-
MF_DATA_FETCH_STATUS2[MF_DATA_FETCH_STATUS2["LOADING"] = 2] = "LOADING";
|
|
60
|
-
MF_DATA_FETCH_STATUS2[MF_DATA_FETCH_STATUS2["AWAIT"] = 0] = "AWAIT";
|
|
61
|
-
MF_DATA_FETCH_STATUS2[MF_DATA_FETCH_STATUS2["ERROR"] = 3] = "ERROR";
|
|
62
|
-
})(MF_DATA_FETCH_STATUS || (MF_DATA_FETCH_STATUS = {}));
|
|
63
27
|
// Annotate the CommonJS export names for ESM import in node:
|
|
64
28
|
0 && (module.exports = {
|
|
65
|
-
DATA_FETCH_ERROR_PREFIX,
|
|
66
|
-
DATA_FETCH_FUNCTION,
|
|
67
|
-
DATA_FETCH_MAP_KEY,
|
|
68
|
-
DATA_FETCH_QUERY,
|
|
69
|
-
DOWNGRADE_KEY,
|
|
70
|
-
ERROR_TYPE,
|
|
71
|
-
FS_HREF,
|
|
72
|
-
LOAD_REMOTE_ERROR_PREFIX,
|
|
73
29
|
LOCALHOST,
|
|
74
|
-
|
|
75
|
-
MF_DATA_FETCH_TYPE,
|
|
76
|
-
PLUGIN_IDENTIFIER,
|
|
77
|
-
WRAP_DATA_FETCH_ID_IDENTIFIER
|
|
30
|
+
PLUGIN_IDENTIFIER
|
|
78
31
|
});
|
|
@@ -19,32 +19,15 @@ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "defau
|
|
|
19
19
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
20
|
var runtime_exports = {};
|
|
21
21
|
__export(runtime_exports, {
|
|
22
|
-
ERROR_TYPE: () =>
|
|
23
|
-
kit: () => kit
|
|
24
|
-
setSSREnv: () => import_injectDataFetchFunctionPlugin.setSSREnv
|
|
22
|
+
ERROR_TYPE: () => import_bridge_react.ERROR_TYPE,
|
|
23
|
+
kit: () => import_bridge_react.kit
|
|
25
24
|
});
|
|
26
25
|
module.exports = __toCommonJS(runtime_exports);
|
|
27
26
|
__reExport(runtime_exports, require("@module-federation/enhanced/runtime"), module.exports);
|
|
28
|
-
var
|
|
29
|
-
var import_injectDataFetchFunctionPlugin = require("../ssr-runtime/injectDataFetchFunctionPlugin");
|
|
30
|
-
const kit = {
|
|
31
|
-
get createRemoteSSRComponent() {
|
|
32
|
-
return require("./createRemoteComponent").createRemoteSSRComponent;
|
|
33
|
-
},
|
|
34
|
-
get createRemoteComponent() {
|
|
35
|
-
return require("./createRemoteComponent").createRemoteComponent;
|
|
36
|
-
},
|
|
37
|
-
get collectSSRAssets() {
|
|
38
|
-
return require("./createRemoteComponent").collectSSRAssets;
|
|
39
|
-
},
|
|
40
|
-
get wrapNoSSR() {
|
|
41
|
-
return require("./wrapNoSSR").wrapNoSSR;
|
|
42
|
-
}
|
|
43
|
-
};
|
|
27
|
+
var import_bridge_react = require("@module-federation/bridge-react");
|
|
44
28
|
// Annotate the CommonJS export names for ESM import in node:
|
|
45
29
|
0 && (module.exports = {
|
|
46
30
|
ERROR_TYPE,
|
|
47
31
|
kit,
|
|
48
|
-
setSSREnv,
|
|
49
32
|
...require("@module-federation/enhanced/runtime")
|
|
50
33
|
});
|
|
@@ -33,7 +33,7 @@ __export(devPlugin_exports, {
|
|
|
33
33
|
module.exports = __toCommonJS(devPlugin_exports);
|
|
34
34
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
35
35
|
var import_SSRLiveReload = require("./SSRLiveReload");
|
|
36
|
-
var
|
|
36
|
+
var import_data_fetch_utils = require("@module-federation/bridge-react/data-fetch-utils");
|
|
37
37
|
const mfSSRDevPlugin = () => ({
|
|
38
38
|
name: "@module-federation/modern-js",
|
|
39
39
|
setup: (api) => {
|
|
@@ -48,7 +48,7 @@ const mfSSRDevPlugin = () => ({
|
|
|
48
48
|
if (shouldUpdate) {
|
|
49
49
|
console.log("should RELOAD", shouldUpdate);
|
|
50
50
|
await nodeUtils.flushChunks();
|
|
51
|
-
(0,
|
|
51
|
+
(0, import_data_fetch_utils.flushDataFetch)();
|
|
52
52
|
globalThis.shouldUpdate = true;
|
|
53
53
|
}
|
|
54
54
|
});
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,120 +15,27 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
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
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
var injectDataFetchFunctionPlugin_exports = {};
|
|
30
20
|
__export(injectDataFetchFunctionPlugin_exports, {
|
|
31
|
-
injectDataFetchFunctionPlugin: () => injectDataFetchFunctionPlugin
|
|
32
|
-
setSSREnv: () => setSSREnv
|
|
21
|
+
injectDataFetchFunctionPlugin: () => injectDataFetchFunctionPlugin
|
|
33
22
|
});
|
|
34
23
|
module.exports = __toCommonJS(injectDataFetchFunctionPlugin_exports);
|
|
35
|
-
var
|
|
36
|
-
|
|
37
|
-
var import_utils = require("../utils");
|
|
38
|
-
var import_downgrade = require("./downgrade");
|
|
39
|
-
function setSSREnv({ fetchServerQuery }) {
|
|
40
|
-
globalThis.FEDERATION_SSR = true;
|
|
41
|
-
globalThis.FEDERATION_SERVER_QUERY = fetchServerQuery;
|
|
42
|
-
}
|
|
24
|
+
var import_bridge_react = require("@module-federation/bridge-react");
|
|
25
|
+
const { callDataFetch, injectDataFetch, setSSREnv } = import_bridge_react.kit;
|
|
43
26
|
const injectDataFetchFunctionPlugin = ({ fetchServerQuery }) => ({
|
|
44
27
|
name: "@module-federation/inject-data-fetch-function-plugin",
|
|
45
28
|
setup: (api) => {
|
|
46
29
|
api.onBeforeRender(async () => {
|
|
47
|
-
var _globalThis, _DATA_FETCH_FUNCTION;
|
|
48
30
|
setSSREnv({
|
|
49
31
|
fetchServerQuery
|
|
50
32
|
});
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
const dataFetchFunction = async function(options) {
|
|
55
|
-
const [id, data, downgrade] = options;
|
|
56
|
-
import_logger.default.debug("==========call data fetch function!");
|
|
57
|
-
if (data) {
|
|
58
|
-
if (!id) {
|
|
59
|
-
throw new Error("id is required!");
|
|
60
|
-
}
|
|
61
|
-
if (!(0, import_utils.getDataFetchMap)()) {
|
|
62
|
-
(0, import_utils.initDataFetchMap)();
|
|
63
|
-
}
|
|
64
|
-
const dataFetchItem = (0, import_utils.getDataFetchItem)(id);
|
|
65
|
-
if (dataFetchItem) {
|
|
66
|
-
var _dataFetchItem__, _dataFetchItem_;
|
|
67
|
-
(_dataFetchItem_ = dataFetchItem[1]) === null || _dataFetchItem_ === void 0 ? void 0 : (_dataFetchItem__ = _dataFetchItem_[1]) === null || _dataFetchItem__ === void 0 ? void 0 : _dataFetchItem__.call(_dataFetchItem_, data);
|
|
68
|
-
dataFetchItem[2] = import_constant.MF_DATA_FETCH_STATUS.LOADED;
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
if (!dataFetchItem) {
|
|
72
|
-
const dataFetchMap = (0, import_utils.getDataFetchMap)();
|
|
73
|
-
let res;
|
|
74
|
-
let rej;
|
|
75
|
-
const p = new Promise((resolve, reject) => {
|
|
76
|
-
res = resolve;
|
|
77
|
-
rej = reject;
|
|
78
|
-
});
|
|
79
|
-
dataFetchMap[id] = [
|
|
80
|
-
[
|
|
81
|
-
async () => async () => {
|
|
82
|
-
return "";
|
|
83
|
-
},
|
|
84
|
-
import_constant.MF_DATA_FETCH_TYPE.FETCH_SERVER
|
|
85
|
-
],
|
|
86
|
-
[
|
|
87
|
-
p,
|
|
88
|
-
res,
|
|
89
|
-
rej
|
|
90
|
-
],
|
|
91
|
-
import_constant.MF_DATA_FETCH_STATUS.LOADED
|
|
92
|
-
];
|
|
93
|
-
res(data);
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
if (downgrade) {
|
|
98
|
-
const mfDowngrade2 = (0, import_downgrade.getDowngradeTag)();
|
|
99
|
-
if (!mfDowngrade2) {
|
|
100
|
-
globalThis[import_constant.DOWNGRADE_KEY] = id ? [
|
|
101
|
-
id
|
|
102
|
-
] : true;
|
|
103
|
-
} else if (Array.isArray(mfDowngrade2) && id && !mfDowngrade2.includes(id)) {
|
|
104
|
-
mfDowngrade2.push(id);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
const mfDowngrade = (0, import_downgrade.getDowngradeTag)();
|
|
108
|
-
if (typeof mfDowngrade === "boolean") {
|
|
109
|
-
return (0, import_downgrade.callAllDowngrade)();
|
|
110
|
-
}
|
|
111
|
-
if (Array.isArray(mfDowngrade)) {
|
|
112
|
-
if (!id) {
|
|
113
|
-
globalThis[import_constant.DOWNGRADE_KEY] = true;
|
|
114
|
-
return (0, import_downgrade.callAllDowngrade)();
|
|
115
|
-
}
|
|
116
|
-
if (!mfDowngrade.includes(id)) {
|
|
117
|
-
mfDowngrade.push(id);
|
|
118
|
-
}
|
|
119
|
-
return (0, import_downgrade.callDowngrade)(id);
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
globalThis[import_constant.FS_HREF] = window.location.href;
|
|
123
|
-
(_globalThis = globalThis)[_DATA_FETCH_FUNCTION = import_constant.DATA_FETCH_FUNCTION] || (_globalThis[_DATA_FETCH_FUNCTION] = []);
|
|
124
|
-
const dataFetch = globalThis[import_constant.DATA_FETCH_FUNCTION];
|
|
125
|
-
await Promise.all(dataFetch.map(async (options) => {
|
|
126
|
-
await dataFetchFunction(options);
|
|
127
|
-
}));
|
|
128
|
-
dataFetch.push = dataFetchFunction;
|
|
33
|
+
injectDataFetch();
|
|
34
|
+
await callDataFetch();
|
|
129
35
|
});
|
|
130
36
|
}
|
|
131
37
|
});
|
|
132
38
|
// Annotate the CommonJS export names for ESM import in node:
|
|
133
39
|
0 && (module.exports = {
|
|
134
|
-
injectDataFetchFunctionPlugin
|
|
135
|
-
setSSREnv
|
|
40
|
+
injectDataFetchFunctionPlugin
|
|
136
41
|
});
|
|
@@ -138,7 +138,7 @@ var patchMFConfig = function(mfConfig, isServer, remoteIpStrategy, enableSSR) {
|
|
|
138
138
|
var runtimePlugins = _to_consumable_array(mfConfig.runtimePlugins || []);
|
|
139
139
|
patchDTSConfig(mfConfig, isServer);
|
|
140
140
|
injectRuntimePlugins(require.resolve("@module-federation/modern-js/shared-strategy"), runtimePlugins);
|
|
141
|
-
injectRuntimePlugins(require.resolve("@module-federation/
|
|
141
|
+
injectRuntimePlugins(require.resolve("@module-federation/bridge-react/data-fetch-runtime-plugin"), runtimePlugins);
|
|
142
142
|
if (enableSSR && isDev()) {
|
|
143
143
|
injectRuntimePlugins(require.resolve("@module-federation/modern-js/resolve-entry-ipv4"), runtimePlugins);
|
|
144
144
|
}
|
|
@@ -43,7 +43,7 @@ describe("patchMFConfig", /* @__PURE__ */ _async_to_generator(function() {
|
|
|
43
43
|
remoteType: "script",
|
|
44
44
|
runtimePlugins: [
|
|
45
45
|
require.resolve("@module-federation/modern-js/shared-strategy"),
|
|
46
|
-
require.resolve("@module-federation/
|
|
46
|
+
require.resolve("@module-federation/bridge-react/data-fetch-runtime-plugin"),
|
|
47
47
|
require.resolve("@module-federation/node/runtimePlugin"),
|
|
48
48
|
require.resolve("@module-federation/modern-js/inject-node-fetch")
|
|
49
49
|
],
|
|
@@ -78,7 +78,7 @@ describe("patchMFConfig", /* @__PURE__ */ _async_to_generator(function() {
|
|
|
78
78
|
remoteType: "script",
|
|
79
79
|
runtimePlugins: [
|
|
80
80
|
require.resolve("@module-federation/modern-js/shared-strategy"),
|
|
81
|
-
require.resolve("@module-federation/
|
|
81
|
+
require.resolve("@module-federation/bridge-react/data-fetch-runtime-plugin")
|
|
82
82
|
],
|
|
83
83
|
shared: {
|
|
84
84
|
react: {
|
|
@@ -2,11 +2,10 @@ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
|
2
2
|
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
3
3
|
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
4
4
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
5
|
-
import { DATA_FETCH_QUERY, MF_DATA_FETCH_STATUS } from "
|
|
6
|
-
import
|
|
7
|
-
import { getDataFetchMap } from "../../utils";
|
|
8
|
-
import { fetchData, initDataFetchMap, loadDataFetchModule } from "../../utils/dataFetch";
|
|
5
|
+
import { DATA_FETCH_QUERY, MF_DATA_FETCH_STATUS } from "@module-federation/bridge-react/data-fetch-constant";
|
|
6
|
+
import { getDataFetchMap, fetchData, initDataFetchMap, loadDataFetchModule } from "@module-federation/bridge-react/data-fetch-utils";
|
|
9
7
|
import { SEPARATOR, MANIFEST_EXT } from "@module-federation/sdk";
|
|
8
|
+
import logger from "../../logger";
|
|
10
9
|
function wrapSetTimeout(targetPromise) {
|
|
11
10
|
var delay = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 2e4, id = arguments.length > 2 ? arguments[2] : void 0;
|
|
12
11
|
if (targetPromise && typeof targetPromise.then === "function") {
|
package/dist/esm/constant.js
CHANGED
|
@@ -1,42 +1,6 @@
|
|
|
1
1
|
var LOCALHOST = "localhost";
|
|
2
2
|
var PLUGIN_IDENTIFIER = "[ Modern.js Module Federation ]";
|
|
3
|
-
var DATA_FETCH_QUERY = "x-mf-data-fetch";
|
|
4
|
-
var DATA_FETCH_ERROR_PREFIX = "caught the following error during dataFetch: ";
|
|
5
|
-
var LOAD_REMOTE_ERROR_PREFIX = "caught the following error during loadRemote: ";
|
|
6
|
-
var DOWNGRADE_KEY = "_mfSSRDowngrade";
|
|
7
|
-
var DATA_FETCH_MAP_KEY = "__MF_DATA_FETCH_MAP__";
|
|
8
|
-
var DATA_FETCH_FUNCTION = "_mfDataFetch";
|
|
9
|
-
var FS_HREF = "_mfFSHref";
|
|
10
|
-
var ERROR_TYPE = {
|
|
11
|
-
DATA_FETCH: 1,
|
|
12
|
-
LOAD_REMOTE: 2,
|
|
13
|
-
UNKNOWN: 3
|
|
14
|
-
};
|
|
15
|
-
var WRAP_DATA_FETCH_ID_IDENTIFIER = "wrap_dfip_identifier";
|
|
16
|
-
var MF_DATA_FETCH_TYPE;
|
|
17
|
-
(function(MF_DATA_FETCH_TYPE2) {
|
|
18
|
-
MF_DATA_FETCH_TYPE2[MF_DATA_FETCH_TYPE2["FETCH_SERVER"] = 1] = "FETCH_SERVER";
|
|
19
|
-
MF_DATA_FETCH_TYPE2[MF_DATA_FETCH_TYPE2["FETCH_CLIENT"] = 2] = "FETCH_CLIENT";
|
|
20
|
-
})(MF_DATA_FETCH_TYPE || (MF_DATA_FETCH_TYPE = {}));
|
|
21
|
-
var MF_DATA_FETCH_STATUS;
|
|
22
|
-
(function(MF_DATA_FETCH_STATUS2) {
|
|
23
|
-
MF_DATA_FETCH_STATUS2[MF_DATA_FETCH_STATUS2["LOADED"] = 1] = "LOADED";
|
|
24
|
-
MF_DATA_FETCH_STATUS2[MF_DATA_FETCH_STATUS2["LOADING"] = 2] = "LOADING";
|
|
25
|
-
MF_DATA_FETCH_STATUS2[MF_DATA_FETCH_STATUS2["AWAIT"] = 0] = "AWAIT";
|
|
26
|
-
MF_DATA_FETCH_STATUS2[MF_DATA_FETCH_STATUS2["ERROR"] = 3] = "ERROR";
|
|
27
|
-
})(MF_DATA_FETCH_STATUS || (MF_DATA_FETCH_STATUS = {}));
|
|
28
3
|
export {
|
|
29
|
-
DATA_FETCH_ERROR_PREFIX,
|
|
30
|
-
DATA_FETCH_FUNCTION,
|
|
31
|
-
DATA_FETCH_MAP_KEY,
|
|
32
|
-
DATA_FETCH_QUERY,
|
|
33
|
-
DOWNGRADE_KEY,
|
|
34
|
-
ERROR_TYPE,
|
|
35
|
-
FS_HREF,
|
|
36
|
-
LOAD_REMOTE_ERROR_PREFIX,
|
|
37
4
|
LOCALHOST,
|
|
38
|
-
|
|
39
|
-
MF_DATA_FETCH_TYPE,
|
|
40
|
-
PLUGIN_IDENTIFIER,
|
|
41
|
-
WRAP_DATA_FETCH_ID_IDENTIFIER
|
|
5
|
+
PLUGIN_IDENTIFIER
|
|
42
6
|
};
|
|
@@ -1,22 +1,6 @@
|
|
|
1
1
|
export * from "@module-federation/enhanced/runtime";
|
|
2
|
-
import { ERROR_TYPE } from "
|
|
3
|
-
var kit = {
|
|
4
|
-
get createRemoteSSRComponent() {
|
|
5
|
-
return require("./createRemoteComponent").createRemoteSSRComponent;
|
|
6
|
-
},
|
|
7
|
-
get createRemoteComponent() {
|
|
8
|
-
return require("./createRemoteComponent").createRemoteComponent;
|
|
9
|
-
},
|
|
10
|
-
get collectSSRAssets() {
|
|
11
|
-
return require("./createRemoteComponent").collectSSRAssets;
|
|
12
|
-
},
|
|
13
|
-
get wrapNoSSR() {
|
|
14
|
-
return require("./wrapNoSSR").wrapNoSSR;
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
import { setSSREnv } from "../ssr-runtime/injectDataFetchFunctionPlugin";
|
|
2
|
+
import { kit, ERROR_TYPE } from "@module-federation/bridge-react";
|
|
18
3
|
export {
|
|
19
4
|
ERROR_TYPE,
|
|
20
|
-
kit
|
|
21
|
-
setSSREnv
|
|
5
|
+
kit
|
|
22
6
|
};
|
|
@@ -3,7 +3,7 @@ import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
|
3
3
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
4
4
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
5
5
|
import { SSRLiveReload } from "./SSRLiveReload";
|
|
6
|
-
import { flushDataFetch } from "
|
|
6
|
+
import { flushDataFetch } from "@module-federation/bridge-react/data-fetch-utils";
|
|
7
7
|
var mfSSRDevPlugin = function() {
|
|
8
8
|
return {
|
|
9
9
|
name: "@module-federation/modern-js",
|
|
@@ -1,167 +1,26 @@
|
|
|
1
1
|
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
-
import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
|
|
3
2
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
import { getDataFetchMap, getDataFetchItem, initDataFetchMap } from "../utils";
|
|
7
|
-
import { callAllDowngrade, callDowngrade, getDowngradeTag } from "./downgrade";
|
|
8
|
-
function setSSREnv(param) {
|
|
9
|
-
var fetchServerQuery = param.fetchServerQuery;
|
|
10
|
-
globalThis.FEDERATION_SSR = true;
|
|
11
|
-
globalThis.FEDERATION_SERVER_QUERY = fetchServerQuery;
|
|
12
|
-
}
|
|
3
|
+
import { kit } from "@module-federation/bridge-react";
|
|
4
|
+
var callDataFetch = kit.callDataFetch, injectDataFetch = kit.injectDataFetch, setSSREnv = kit.setSSREnv;
|
|
13
5
|
var injectDataFetchFunctionPlugin = function(param) {
|
|
14
6
|
var fetchServerQuery = param.fetchServerQuery;
|
|
15
7
|
return {
|
|
16
8
|
name: "@module-federation/inject-data-fetch-function-plugin",
|
|
17
9
|
setup: function(api) {
|
|
18
10
|
api.onBeforeRender(/* @__PURE__ */ _async_to_generator(function() {
|
|
19
|
-
var _globalThis, _DATA_FETCH_FUNCTION, dataFetchFunction, dataFetch;
|
|
20
11
|
return _ts_generator(this, function(_state) {
|
|
21
12
|
switch (_state.label) {
|
|
22
13
|
case 0:
|
|
23
14
|
setSSREnv({
|
|
24
15
|
fetchServerQuery
|
|
25
16
|
});
|
|
26
|
-
|
|
27
|
-
return [
|
|
28
|
-
2
|
|
29
|
-
];
|
|
30
|
-
}
|
|
31
|
-
dataFetchFunction = function() {
|
|
32
|
-
var _ref = _async_to_generator(function(options) {
|
|
33
|
-
var _options, id, data, downgrade, dataFetchItem, _dataFetchItem__, _dataFetchItem_, dataFetchMap, res, rej, p, mfDowngrade, mfDowngrade1;
|
|
34
|
-
return _ts_generator(this, function(_state2) {
|
|
35
|
-
_options = _sliced_to_array(options, 3), id = _options[0], data = _options[1], downgrade = _options[2];
|
|
36
|
-
logger.debug("==========call data fetch function!");
|
|
37
|
-
if (data) {
|
|
38
|
-
if (!id) {
|
|
39
|
-
throw new Error("id is required!");
|
|
40
|
-
}
|
|
41
|
-
if (!getDataFetchMap()) {
|
|
42
|
-
initDataFetchMap();
|
|
43
|
-
}
|
|
44
|
-
dataFetchItem = getDataFetchItem(id);
|
|
45
|
-
if (dataFetchItem) {
|
|
46
|
-
;
|
|
47
|
-
(_dataFetchItem_ = dataFetchItem[1]) === null || _dataFetchItem_ === void 0 ? void 0 : (_dataFetchItem__ = _dataFetchItem_[1]) === null || _dataFetchItem__ === void 0 ? void 0 : _dataFetchItem__.call(_dataFetchItem_, data);
|
|
48
|
-
dataFetchItem[2] = MF_DATA_FETCH_STATUS.LOADED;
|
|
49
|
-
return [
|
|
50
|
-
2
|
|
51
|
-
];
|
|
52
|
-
}
|
|
53
|
-
if (!dataFetchItem) {
|
|
54
|
-
dataFetchMap = getDataFetchMap();
|
|
55
|
-
;
|
|
56
|
-
;
|
|
57
|
-
p = new Promise(function(resolve, reject) {
|
|
58
|
-
res = resolve;
|
|
59
|
-
rej = reject;
|
|
60
|
-
});
|
|
61
|
-
dataFetchMap[id] = [
|
|
62
|
-
[
|
|
63
|
-
/* @__PURE__ */ _async_to_generator(function() {
|
|
64
|
-
return _ts_generator(this, function(_state3) {
|
|
65
|
-
return [
|
|
66
|
-
2,
|
|
67
|
-
_async_to_generator(function() {
|
|
68
|
-
return _ts_generator(this, function(_state4) {
|
|
69
|
-
return [
|
|
70
|
-
2,
|
|
71
|
-
""
|
|
72
|
-
];
|
|
73
|
-
});
|
|
74
|
-
})
|
|
75
|
-
];
|
|
76
|
-
});
|
|
77
|
-
}),
|
|
78
|
-
MF_DATA_FETCH_TYPE.FETCH_SERVER
|
|
79
|
-
],
|
|
80
|
-
[
|
|
81
|
-
p,
|
|
82
|
-
res,
|
|
83
|
-
rej
|
|
84
|
-
],
|
|
85
|
-
MF_DATA_FETCH_STATUS.LOADED
|
|
86
|
-
];
|
|
87
|
-
res(data);
|
|
88
|
-
return [
|
|
89
|
-
2
|
|
90
|
-
];
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
if (downgrade) {
|
|
94
|
-
mfDowngrade = getDowngradeTag();
|
|
95
|
-
if (!mfDowngrade) {
|
|
96
|
-
globalThis[DOWNGRADE_KEY] = id ? [
|
|
97
|
-
id
|
|
98
|
-
] : true;
|
|
99
|
-
} else if (Array.isArray(mfDowngrade) && id && !mfDowngrade.includes(id)) {
|
|
100
|
-
mfDowngrade.push(id);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
mfDowngrade1 = getDowngradeTag();
|
|
104
|
-
if (typeof mfDowngrade1 === "boolean") {
|
|
105
|
-
return [
|
|
106
|
-
2,
|
|
107
|
-
callAllDowngrade()
|
|
108
|
-
];
|
|
109
|
-
}
|
|
110
|
-
if (Array.isArray(mfDowngrade1)) {
|
|
111
|
-
if (!id) {
|
|
112
|
-
globalThis[DOWNGRADE_KEY] = true;
|
|
113
|
-
return [
|
|
114
|
-
2,
|
|
115
|
-
callAllDowngrade()
|
|
116
|
-
];
|
|
117
|
-
}
|
|
118
|
-
if (!mfDowngrade1.includes(id)) {
|
|
119
|
-
mfDowngrade1.push(id);
|
|
120
|
-
}
|
|
121
|
-
return [
|
|
122
|
-
2,
|
|
123
|
-
callDowngrade(id)
|
|
124
|
-
];
|
|
125
|
-
}
|
|
126
|
-
return [
|
|
127
|
-
2
|
|
128
|
-
];
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
return function dataFetchFunction2(options) {
|
|
132
|
-
return _ref.apply(this, arguments);
|
|
133
|
-
};
|
|
134
|
-
}();
|
|
135
|
-
globalThis[FS_HREF] = window.location.href;
|
|
136
|
-
(_globalThis = globalThis)[_DATA_FETCH_FUNCTION = DATA_FETCH_FUNCTION] || (_globalThis[_DATA_FETCH_FUNCTION] = []);
|
|
137
|
-
dataFetch = globalThis[DATA_FETCH_FUNCTION];
|
|
17
|
+
injectDataFetch();
|
|
138
18
|
return [
|
|
139
19
|
4,
|
|
140
|
-
|
|
141
|
-
var _ref = _async_to_generator(function(options) {
|
|
142
|
-
return _ts_generator(this, function(_state2) {
|
|
143
|
-
switch (_state2.label) {
|
|
144
|
-
case 0:
|
|
145
|
-
return [
|
|
146
|
-
4,
|
|
147
|
-
dataFetchFunction(options)
|
|
148
|
-
];
|
|
149
|
-
case 1:
|
|
150
|
-
_state2.sent();
|
|
151
|
-
return [
|
|
152
|
-
2
|
|
153
|
-
];
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
return function(options) {
|
|
158
|
-
return _ref.apply(this, arguments);
|
|
159
|
-
};
|
|
160
|
-
}()))
|
|
20
|
+
callDataFetch()
|
|
161
21
|
];
|
|
162
22
|
case 1:
|
|
163
23
|
_state.sent();
|
|
164
|
-
dataFetch.push = dataFetchFunction;
|
|
165
24
|
return [
|
|
166
25
|
2
|
|
167
26
|
];
|
|
@@ -172,6 +31,5 @@ var injectDataFetchFunctionPlugin = function(param) {
|
|
|
172
31
|
};
|
|
173
32
|
};
|
|
174
33
|
export {
|
|
175
|
-
injectDataFetchFunctionPlugin
|
|
176
|
-
setSSREnv
|
|
34
|
+
injectDataFetchFunctionPlugin
|
|
177
35
|
};
|
|
@@ -107,7 +107,7 @@ const patchMFConfig = (mfConfig, isServer, remoteIpStrategy, enableSSR) => {
|
|
|
107
107
|
];
|
|
108
108
|
patchDTSConfig(mfConfig, isServer);
|
|
109
109
|
injectRuntimePlugins(require.resolve("@module-federation/modern-js/shared-strategy"), runtimePlugins);
|
|
110
|
-
injectRuntimePlugins(require.resolve("@module-federation/
|
|
110
|
+
injectRuntimePlugins(require.resolve("@module-federation/bridge-react/data-fetch-runtime-plugin"), runtimePlugins);
|
|
111
111
|
if (enableSSR && isDev()) {
|
|
112
112
|
injectRuntimePlugins(require.resolve("@module-federation/modern-js/resolve-entry-ipv4"), runtimePlugins);
|
|
113
113
|
}
|