@module-federation/bridge-react 0.0.0-chore-bump-node-22-20260710161714

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 (59) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +131 -0
  3. package/dist/base.cjs.js +29 -0
  4. package/dist/base.d.ts +311 -0
  5. package/dist/base.es.js +30 -0
  6. package/dist/bridge-base-CIOXqUYV.mjs +214 -0
  7. package/dist/bridge-base-HLp3d7aF.js +229 -0
  8. package/dist/createHelpers-BY5Uj9_Z.mjs +192 -0
  9. package/dist/createHelpers-DNBacpxb.js +191 -0
  10. package/dist/data-fetch-server-middleware.cjs.js +163 -0
  11. package/dist/data-fetch-server-middleware.d.ts +15 -0
  12. package/dist/data-fetch-server-middleware.es.js +164 -0
  13. package/dist/data-fetch-utils.cjs.js +24 -0
  14. package/dist/data-fetch-utils.d.ts +81 -0
  15. package/dist/data-fetch-utils.es.js +26 -0
  16. package/dist/data-fetch.cjs.js +22 -0
  17. package/dist/data-fetch.d.ts +140 -0
  18. package/dist/data-fetch.es.js +22 -0
  19. package/dist/index-Bs2NxD2z.mjs +46 -0
  20. package/dist/index-DbjGCKOr.js +45 -0
  21. package/dist/index.cjs.js +125 -0
  22. package/dist/index.d.ts +299 -0
  23. package/dist/index.es.js +109 -0
  24. package/dist/lazy-load-component-plugin-BjMVNoep.js +521 -0
  25. package/dist/lazy-load-component-plugin-aj97Vt-4.mjs +522 -0
  26. package/dist/lazy-load-component-plugin.cjs.js +6 -0
  27. package/dist/lazy-load-component-plugin.d.ts +16 -0
  28. package/dist/lazy-load-component-plugin.es.js +6 -0
  29. package/dist/lazy-utils.cjs.js +24 -0
  30. package/dist/lazy-utils.d.ts +149 -0
  31. package/dist/lazy-utils.es.js +24 -0
  32. package/dist/logger-DwWkXsWl.mjs +139 -0
  33. package/dist/logger-Dxblx6P-.js +138 -0
  34. package/dist/plugin.cjs.js +14 -0
  35. package/dist/plugin.d.ts +22 -0
  36. package/dist/plugin.es.js +14 -0
  37. package/dist/prefetch-BwRDb4SJ.mjs +1082 -0
  38. package/dist/prefetch-DLhPTofn.js +1081 -0
  39. package/dist/router-v5.cjs.js +57 -0
  40. package/dist/router-v5.d.ts +17 -0
  41. package/dist/router-v5.es.js +34 -0
  42. package/dist/router-v6.cjs.js +84 -0
  43. package/dist/router-v6.d.ts +20 -0
  44. package/dist/router-v6.es.js +61 -0
  45. package/dist/router-v7.cjs.js +85 -0
  46. package/dist/router-v7.d.ts +19 -0
  47. package/dist/router-v7.es.js +63 -0
  48. package/dist/router.cjs.js +82 -0
  49. package/dist/router.d.ts +20 -0
  50. package/dist/router.es.js +60 -0
  51. package/dist/utils-CFTy4LVE.js +2029 -0
  52. package/dist/utils-DGS4pYp8.mjs +2030 -0
  53. package/dist/v18.cjs.js +15 -0
  54. package/dist/v18.d.ts +114 -0
  55. package/dist/v18.es.js +15 -0
  56. package/dist/v19.cjs.js +15 -0
  57. package/dist/v19.d.ts +115 -0
  58. package/dist/v19.es.js +15 -0
  59. package/package.json +189 -0
@@ -0,0 +1,191 @@
1
+ "use strict";
2
+ const bridgeBase = require("./bridge-base-HLp3d7aF.js");
3
+ const ReactDOM = require("react-dom");
4
+ const index = require("./index-DbjGCKOr.js");
5
+ const React = require("react");
6
+ const plugin = require("./plugin.cjs.js");
7
+ function createReact16Or17Root(container) {
8
+ return {
9
+ render(children) {
10
+ const reactVersion = ReactDOM.version || "";
11
+ const isReact18 = reactVersion.startsWith("18");
12
+ const isReact19 = reactVersion.startsWith("19");
13
+ if (isReact19) {
14
+ throw new Error(
15
+ `React 19 detected in legacy mode. This is not supported. Please use the version-specific import: import { createBridgeComponent } from '@module-federation/bridge-react/v19'`
16
+ );
17
+ }
18
+ if (isReact18) {
19
+ index.LoggerInstance.warn(
20
+ `[Bridge-React] React 18 detected in legacy mode. For better compatibility, please use the version-specific import: import { createBridgeComponent } from '@module-federation/bridge-react/v18'`
21
+ );
22
+ }
23
+ ReactDOM.render(children, container);
24
+ },
25
+ unmount() {
26
+ ReactDOM.unmountComponentAtNode(container);
27
+ }
28
+ };
29
+ }
30
+ function createBridgeComponent(bridgeInfo) {
31
+ const fullBridgeInfo = {
32
+ createRoot: createReact16Or17Root,
33
+ ...bridgeInfo
34
+ };
35
+ return bridgeBase.createBaseBridgeComponent(fullBridgeInfo);
36
+ }
37
+ const RemoteAppWrapper = React.forwardRef(function(props, ref) {
38
+ const {
39
+ moduleName,
40
+ memoryRoute,
41
+ basename,
42
+ providerInfo,
43
+ className,
44
+ style,
45
+ fallback,
46
+ loading,
47
+ ...resProps
48
+ } = props;
49
+ const instance = plugin.federationRuntime.instance;
50
+ const rootRef = ref && "current" in ref ? ref : React.useRef(null);
51
+ const renderDom = React.useRef(null);
52
+ const providerInfoRef = React.useRef(null);
53
+ const [initialized, setInitialized] = React.useState(false);
54
+ index.LoggerInstance.debug(`RemoteAppWrapper instance from props >>>`, instance);
55
+ React.useEffect(() => {
56
+ if (initialized) return;
57
+ const providerReturn = providerInfo();
58
+ providerInfoRef.current = providerReturn;
59
+ setInitialized(true);
60
+ return () => {
61
+ var _a, _b, _c, _d, _e, _f, _g, _h;
62
+ if ((_a = providerInfoRef.current) == null ? void 0 : _a.destroy) {
63
+ index.LoggerInstance.debug(
64
+ `createRemoteAppComponent LazyComponent destroy >>>`,
65
+ { moduleName, basename, dom: renderDom.current }
66
+ );
67
+ (_d = (_c = (_b = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _b.lifecycle) == null ? void 0 : _c.beforeBridgeDestroy) == null ? void 0 : _d.emit({
68
+ moduleName,
69
+ dom: renderDom.current,
70
+ basename,
71
+ memoryRoute,
72
+ fallback,
73
+ ...resProps
74
+ });
75
+ (_e = providerInfoRef.current) == null ? void 0 : _e.destroy({
76
+ moduleName,
77
+ dom: renderDom.current
78
+ });
79
+ (_h = (_g = (_f = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _f.lifecycle) == null ? void 0 : _g.afterBridgeDestroy) == null ? void 0 : _h.emit({
80
+ moduleName,
81
+ dom: renderDom.current,
82
+ basename,
83
+ memoryRoute,
84
+ fallback,
85
+ ...resProps
86
+ });
87
+ }
88
+ };
89
+ }, [moduleName]);
90
+ React.useEffect(() => {
91
+ var _a, _b, _c, _d, _e, _f;
92
+ if (!initialized || !providerInfoRef.current) return;
93
+ let renderProps = {
94
+ moduleName,
95
+ dom: rootRef.current,
96
+ basename,
97
+ memoryRoute,
98
+ fallback,
99
+ ...resProps
100
+ };
101
+ renderDom.current = rootRef.current;
102
+ const beforeBridgeRenderRes = ((_c = (_b = (_a = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _a.lifecycle) == null ? void 0 : _b.beforeBridgeRender) == null ? void 0 : _c.emit(renderProps)) || {};
103
+ renderProps = { ...renderProps, ...beforeBridgeRenderRes.extraProps };
104
+ providerInfoRef.current.render(renderProps);
105
+ (_f = (_e = (_d = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _d.lifecycle) == null ? void 0 : _e.afterBridgeRender) == null ? void 0 : _f.emit(renderProps);
106
+ }, [initialized, ...Object.values(props)]);
107
+ const rootComponentClassName = `${index.getRootDomDefaultClassName(moduleName)} ${className || ""}`;
108
+ return /* @__PURE__ */ React.createElement("div", { className: rootComponentClassName, style, ref: rootRef }, loading);
109
+ });
110
+ function createLazyRemoteComponentFactory(RemoteApp) {
111
+ return function createLazyRemoteComponent(info) {
112
+ const exportName = (info == null ? void 0 : info.export) || "default";
113
+ return React.lazy(async () => {
114
+ index.LoggerInstance.debug(
115
+ `createRemoteAppComponent LazyComponent create >>>`,
116
+ {
117
+ lazyComponent: info.loader,
118
+ exportName
119
+ }
120
+ );
121
+ try {
122
+ const m = await info.loader();
123
+ const moduleName = m && m[Symbol.for("mf_module_id")];
124
+ index.LoggerInstance.debug(
125
+ `createRemoteAppComponent LazyComponent loadRemote info >>>`,
126
+ { name: moduleName, module: m, exportName }
127
+ );
128
+ const exportFn = m[exportName];
129
+ if (exportName in m && typeof exportFn === "function") {
130
+ const RemoteAppComponent = React.forwardRef((props, ref) => {
131
+ return /* @__PURE__ */ React.createElement(
132
+ RemoteApp,
133
+ {
134
+ moduleName,
135
+ providerInfo: exportFn,
136
+ exportName: info.export || "default",
137
+ fallback: info.fallback,
138
+ loading: info.loading,
139
+ ref,
140
+ ...props
141
+ }
142
+ );
143
+ });
144
+ return {
145
+ default: RemoteAppComponent
146
+ };
147
+ } else {
148
+ index.LoggerInstance.debug(
149
+ `createRemoteAppComponent LazyComponent module not found >>>`,
150
+ { name: moduleName, module: m, exportName }
151
+ );
152
+ throw Error(
153
+ `Make sure that ${moduleName} has the correct export when export is ${String(
154
+ exportName
155
+ )}`
156
+ );
157
+ }
158
+ } catch (error) {
159
+ throw error;
160
+ }
161
+ });
162
+ };
163
+ }
164
+ function createRemoteAppComponentFactory(RemoteApp) {
165
+ const ErrorBoundaryComponent = bridgeBase.ErrorBoundary;
166
+ const createLazyRemoteComponent = createLazyRemoteComponentFactory(RemoteApp);
167
+ return function createRemoteAppComponent(info) {
168
+ const LazyComponent = createLazyRemoteComponent(info);
169
+ return React.forwardRef((props, ref) => {
170
+ return /* @__PURE__ */ React.createElement(
171
+ ErrorBoundaryComponent,
172
+ {
173
+ FallbackComponent: info.fallback
174
+ },
175
+ /* @__PURE__ */ React.createElement(React.Suspense, { fallback: info.loading }, /* @__PURE__ */ React.createElement(LazyComponent, { ...props, ref }))
176
+ );
177
+ });
178
+ };
179
+ }
180
+ function createDeprecatedRemoteComponentFactory(createFn) {
181
+ return function createRemoteComponent(info) {
182
+ index.LoggerInstance.warn(
183
+ `createRemoteComponent is deprecated, please use createRemoteAppComponent instead!`
184
+ );
185
+ return createFn(info);
186
+ };
187
+ }
188
+ exports.RemoteAppWrapper = RemoteAppWrapper;
189
+ exports.createBridgeComponent = createBridgeComponent;
190
+ exports.createDeprecatedRemoteComponentFactory = createDeprecatedRemoteComponentFactory;
191
+ exports.createRemoteAppComponentFactory = createRemoteAppComponentFactory;
@@ -0,0 +1,163 @@
1
+ "use strict";
2
+ const lazyUtils = require("./utils-CFTy4LVE.js");
3
+ const logger = require("./logger-Dxblx6P-.js");
4
+ function wrapSetTimeout(targetPromise, delay = 2e4, id) {
5
+ if (targetPromise && typeof targetPromise.then === "function") {
6
+ return new Promise((resolve, reject) => {
7
+ const timeoutId = setTimeout(() => {
8
+ lazyUtils.logger.warn(`Data fetch for ID ${id} timed out after 20 seconds.`);
9
+ reject(new Error(`Data fetch for ID ${id} timed out after 20 seconds`));
10
+ }, delay);
11
+ targetPromise.then((value) => {
12
+ clearTimeout(timeoutId);
13
+ resolve(value);
14
+ }).catch((err) => {
15
+ clearTimeout(timeoutId);
16
+ reject(err);
17
+ });
18
+ });
19
+ }
20
+ }
21
+ function addProtocol(url) {
22
+ if (url.startsWith("//")) {
23
+ return "https:" + url;
24
+ }
25
+ return url;
26
+ }
27
+ const getDecodeQuery = (url, name) => {
28
+ const res = url.searchParams.get(name);
29
+ if (!res) {
30
+ return null;
31
+ }
32
+ return decodeURIComponent(res);
33
+ };
34
+ const dataFetchServerMiddleware = async (ctx, next) => {
35
+ var _a, _b, _c;
36
+ let url;
37
+ let dataFetchKey;
38
+ let params;
39
+ let remoteInfo;
40
+ try {
41
+ url = new URL(ctx.req.url);
42
+ dataFetchKey = getDecodeQuery(url, lazyUtils.DATA_FETCH_QUERY);
43
+ params = JSON.parse(getDecodeQuery(url, "params") || "{}");
44
+ const remoteInfoQuery = getDecodeQuery(url, "remoteInfo");
45
+ remoteInfo = remoteInfoQuery ? JSON.parse(remoteInfoQuery) : null;
46
+ } catch (e) {
47
+ lazyUtils.logger.error("fetch data from server, error: ", e);
48
+ return next();
49
+ }
50
+ if (!dataFetchKey) {
51
+ return next();
52
+ }
53
+ lazyUtils.logger.log("fetch data from server, dataFetchKey: ", dataFetchKey);
54
+ lazyUtils.logger.debug(
55
+ "fetch data from server, moduleInfo: ",
56
+ (_a = globalThis.__FEDERATION__) == null ? void 0 : _a.moduleInfo
57
+ );
58
+ try {
59
+ const dataFetchMap = lazyUtils.getDataFetchMap();
60
+ if (!dataFetchMap) {
61
+ lazyUtils.initDataFetchMap();
62
+ }
63
+ const fetchDataPromise = (_b = dataFetchMap[dataFetchKey]) == null ? void 0 : _b[1];
64
+ lazyUtils.logger.debug(
65
+ "fetch data from server, fetchDataPromise: ",
66
+ fetchDataPromise
67
+ );
68
+ if (fetchDataPromise && ((_c = dataFetchMap[dataFetchKey]) == null ? void 0 : _c[2]) !== lazyUtils.MF_DATA_FETCH_STATUS.ERROR) {
69
+ const targetPromise = fetchDataPromise[0];
70
+ const wrappedPromise = wrapSetTimeout(targetPromise, 2e4, dataFetchKey);
71
+ if (wrappedPromise) {
72
+ const res = await wrappedPromise;
73
+ lazyUtils.logger.log("fetch data from server, fetchDataPromise res: ", res);
74
+ return ctx.json(res);
75
+ }
76
+ lazyUtils.logger.error(
77
+ `Expected a Promise from fetchDataPromise[0] for dataFetchKey ${dataFetchKey}, but received:`,
78
+ targetPromise,
79
+ "Will try call new dataFetch again..."
80
+ );
81
+ }
82
+ if (remoteInfo) {
83
+ try {
84
+ const hostInstance2 = globalThis.__FEDERATION__.__INSTANCES__[0];
85
+ const remoteEntry = `${addProtocol(remoteInfo.ssrPublicPath) + remoteInfo.ssrRemoteEntry}`;
86
+ if (!hostInstance2) {
87
+ throw new Error("host instance not found!");
88
+ }
89
+ const remote = hostInstance2.options.remotes.find(
90
+ (remote2) => remote2.name === remoteInfo.name
91
+ );
92
+ lazyUtils.logger.debug("find remote: ", JSON.stringify(remote));
93
+ if (!remote) {
94
+ hostInstance2.registerRemotes([
95
+ {
96
+ name: remoteInfo.name,
97
+ entry: remoteEntry,
98
+ entryGlobalName: remoteInfo.globalName
99
+ }
100
+ ]);
101
+ } else if (!("entry" in remote) || !remote.entry.includes(logger.MANIFEST_EXT)) {
102
+ const { hostGlobalSnapshot, remoteSnapshot } = hostInstance2.snapshotHandler.getGlobalRemoteInfo(remoteInfo);
103
+ lazyUtils.logger.debug(
104
+ "find hostGlobalSnapshot: ",
105
+ JSON.stringify(hostGlobalSnapshot)
106
+ );
107
+ lazyUtils.logger.debug("find remoteSnapshot: ", JSON.stringify(remoteSnapshot));
108
+ if (!hostGlobalSnapshot || !remoteSnapshot) {
109
+ if ("version" in remote) {
110
+ delete remote.version;
111
+ }
112
+ remote.entry = remoteEntry;
113
+ remote.entryGlobalName = remoteInfo.globalName;
114
+ }
115
+ }
116
+ } catch (e) {
117
+ ctx.status(500);
118
+ return ctx.text(
119
+ `failed to fetch ${remoteInfo.name} data, error:
120
+ ${e}`
121
+ );
122
+ }
123
+ }
124
+ const dataFetchItem = dataFetchMap[dataFetchKey];
125
+ lazyUtils.logger.debug("fetch data from server, dataFetchItem: ", dataFetchItem);
126
+ if (dataFetchItem) {
127
+ const callFetchDataPromise = lazyUtils.fetchData(dataFetchKey, {
128
+ ...params,
129
+ isDowngrade: !remoteInfo,
130
+ _id: dataFetchKey
131
+ });
132
+ const wrappedPromise = wrapSetTimeout(
133
+ callFetchDataPromise,
134
+ 2e4,
135
+ dataFetchKey
136
+ );
137
+ if (wrappedPromise) {
138
+ const res = await wrappedPromise;
139
+ lazyUtils.logger.log("fetch data from server, dataFetchItem res: ", res);
140
+ return ctx.json(res);
141
+ }
142
+ }
143
+ const remoteId = dataFetchKey.split(logger.SEPARATOR)[0];
144
+ const hostInstance = globalThis.__FEDERATION__.__INSTANCES__[0];
145
+ if (!hostInstance) {
146
+ throw new Error("host instance not found!");
147
+ }
148
+ const dataFetchFn = await lazyUtils.loadDataFetchModule(hostInstance, remoteId);
149
+ const data = await dataFetchFn({
150
+ ...params,
151
+ isDowngrade: !remoteInfo,
152
+ _id: dataFetchKey
153
+ });
154
+ lazyUtils.logger.log("fetch data from server, loadDataFetchModule res: ", data);
155
+ return ctx.json(data);
156
+ } catch (e) {
157
+ lazyUtils.logger.error("server plugin data fetch error: ", e);
158
+ ctx.status(500);
159
+ return ctx.text(`failed to fetch ${remoteInfo.name} data, error:
160
+ ${e}`);
161
+ }
162
+ };
163
+ module.exports = dataFetchServerMiddleware;
@@ -0,0 +1,15 @@
1
+ import { MiddlewareHandler } from 'hono';
2
+
3
+ declare const dataFetchServerMiddleware: MiddlewareHandler;
4
+ export default dataFetchServerMiddleware;
5
+
6
+ export { }
7
+
8
+
9
+ declare module '@module-federation/runtime-core' {
10
+ interface ModuleFederation {
11
+ createLazyComponent<T, E extends keyof T>(options: Omit<CreateLazyComponentOptions<T, E>, 'instance'>): ReturnType<typeof createLazyComponent<T, E>>;
12
+ prefetch(options: Omit<PrefetchOptions, 'instance'>): ReturnType<typeof prefetch>;
13
+ collectSSRAssets(options: Omit<Parameters<typeof collectSSRAssets>[0], 'instance'>): ReturnType<typeof collectSSRAssets>;
14
+ }
15
+ }
@@ -0,0 +1,164 @@
1
+ import { D as DATA_FETCH_QUERY, l as logger, e as getDataFetchMap, i as initDataFetchMap, M as MF_DATA_FETCH_STATUS, h as fetchData, j as loadDataFetchModule } from "./utils-DGS4pYp8.mjs";
2
+ import { M as MANIFEST_EXT, S as SEPARATOR } from "./logger-DwWkXsWl.mjs";
3
+ function wrapSetTimeout(targetPromise, delay = 2e4, id) {
4
+ if (targetPromise && typeof targetPromise.then === "function") {
5
+ return new Promise((resolve, reject) => {
6
+ const timeoutId = setTimeout(() => {
7
+ logger.warn(`Data fetch for ID ${id} timed out after 20 seconds.`);
8
+ reject(new Error(`Data fetch for ID ${id} timed out after 20 seconds`));
9
+ }, delay);
10
+ targetPromise.then((value) => {
11
+ clearTimeout(timeoutId);
12
+ resolve(value);
13
+ }).catch((err) => {
14
+ clearTimeout(timeoutId);
15
+ reject(err);
16
+ });
17
+ });
18
+ }
19
+ }
20
+ function addProtocol(url) {
21
+ if (url.startsWith("//")) {
22
+ return "https:" + url;
23
+ }
24
+ return url;
25
+ }
26
+ const getDecodeQuery = (url, name) => {
27
+ const res = url.searchParams.get(name);
28
+ if (!res) {
29
+ return null;
30
+ }
31
+ return decodeURIComponent(res);
32
+ };
33
+ const dataFetchServerMiddleware = async (ctx, next) => {
34
+ var _a, _b, _c;
35
+ let url;
36
+ let dataFetchKey;
37
+ let params;
38
+ let remoteInfo;
39
+ try {
40
+ url = new URL(ctx.req.url);
41
+ dataFetchKey = getDecodeQuery(url, DATA_FETCH_QUERY);
42
+ params = JSON.parse(getDecodeQuery(url, "params") || "{}");
43
+ const remoteInfoQuery = getDecodeQuery(url, "remoteInfo");
44
+ remoteInfo = remoteInfoQuery ? JSON.parse(remoteInfoQuery) : null;
45
+ } catch (e) {
46
+ logger.error("fetch data from server, error: ", e);
47
+ return next();
48
+ }
49
+ if (!dataFetchKey) {
50
+ return next();
51
+ }
52
+ logger.log("fetch data from server, dataFetchKey: ", dataFetchKey);
53
+ logger.debug(
54
+ "fetch data from server, moduleInfo: ",
55
+ (_a = globalThis.__FEDERATION__) == null ? void 0 : _a.moduleInfo
56
+ );
57
+ try {
58
+ const dataFetchMap = getDataFetchMap();
59
+ if (!dataFetchMap) {
60
+ initDataFetchMap();
61
+ }
62
+ const fetchDataPromise = (_b = dataFetchMap[dataFetchKey]) == null ? void 0 : _b[1];
63
+ logger.debug(
64
+ "fetch data from server, fetchDataPromise: ",
65
+ fetchDataPromise
66
+ );
67
+ if (fetchDataPromise && ((_c = dataFetchMap[dataFetchKey]) == null ? void 0 : _c[2]) !== MF_DATA_FETCH_STATUS.ERROR) {
68
+ const targetPromise = fetchDataPromise[0];
69
+ const wrappedPromise = wrapSetTimeout(targetPromise, 2e4, dataFetchKey);
70
+ if (wrappedPromise) {
71
+ const res = await wrappedPromise;
72
+ logger.log("fetch data from server, fetchDataPromise res: ", res);
73
+ return ctx.json(res);
74
+ }
75
+ logger.error(
76
+ `Expected a Promise from fetchDataPromise[0] for dataFetchKey ${dataFetchKey}, but received:`,
77
+ targetPromise,
78
+ "Will try call new dataFetch again..."
79
+ );
80
+ }
81
+ if (remoteInfo) {
82
+ try {
83
+ const hostInstance2 = globalThis.__FEDERATION__.__INSTANCES__[0];
84
+ const remoteEntry = `${addProtocol(remoteInfo.ssrPublicPath) + remoteInfo.ssrRemoteEntry}`;
85
+ if (!hostInstance2) {
86
+ throw new Error("host instance not found!");
87
+ }
88
+ const remote = hostInstance2.options.remotes.find(
89
+ (remote2) => remote2.name === remoteInfo.name
90
+ );
91
+ logger.debug("find remote: ", JSON.stringify(remote));
92
+ if (!remote) {
93
+ hostInstance2.registerRemotes([
94
+ {
95
+ name: remoteInfo.name,
96
+ entry: remoteEntry,
97
+ entryGlobalName: remoteInfo.globalName
98
+ }
99
+ ]);
100
+ } else if (!("entry" in remote) || !remote.entry.includes(MANIFEST_EXT)) {
101
+ const { hostGlobalSnapshot, remoteSnapshot } = hostInstance2.snapshotHandler.getGlobalRemoteInfo(remoteInfo);
102
+ logger.debug(
103
+ "find hostGlobalSnapshot: ",
104
+ JSON.stringify(hostGlobalSnapshot)
105
+ );
106
+ logger.debug("find remoteSnapshot: ", JSON.stringify(remoteSnapshot));
107
+ if (!hostGlobalSnapshot || !remoteSnapshot) {
108
+ if ("version" in remote) {
109
+ delete remote.version;
110
+ }
111
+ remote.entry = remoteEntry;
112
+ remote.entryGlobalName = remoteInfo.globalName;
113
+ }
114
+ }
115
+ } catch (e) {
116
+ ctx.status(500);
117
+ return ctx.text(
118
+ `failed to fetch ${remoteInfo.name} data, error:
119
+ ${e}`
120
+ );
121
+ }
122
+ }
123
+ const dataFetchItem = dataFetchMap[dataFetchKey];
124
+ logger.debug("fetch data from server, dataFetchItem: ", dataFetchItem);
125
+ if (dataFetchItem) {
126
+ const callFetchDataPromise = fetchData(dataFetchKey, {
127
+ ...params,
128
+ isDowngrade: !remoteInfo,
129
+ _id: dataFetchKey
130
+ });
131
+ const wrappedPromise = wrapSetTimeout(
132
+ callFetchDataPromise,
133
+ 2e4,
134
+ dataFetchKey
135
+ );
136
+ if (wrappedPromise) {
137
+ const res = await wrappedPromise;
138
+ logger.log("fetch data from server, dataFetchItem res: ", res);
139
+ return ctx.json(res);
140
+ }
141
+ }
142
+ const remoteId = dataFetchKey.split(SEPARATOR)[0];
143
+ const hostInstance = globalThis.__FEDERATION__.__INSTANCES__[0];
144
+ if (!hostInstance) {
145
+ throw new Error("host instance not found!");
146
+ }
147
+ const dataFetchFn = await loadDataFetchModule(hostInstance, remoteId);
148
+ const data = await dataFetchFn({
149
+ ...params,
150
+ isDowngrade: !remoteInfo,
151
+ _id: dataFetchKey
152
+ });
153
+ logger.log("fetch data from server, loadDataFetchModule res: ", data);
154
+ return ctx.json(data);
155
+ } catch (e) {
156
+ logger.error("server plugin data fetch error: ", e);
157
+ ctx.status(500);
158
+ return ctx.text(`failed to fetch ${remoteInfo.name} data, error:
159
+ ${e}`);
160
+ }
161
+ };
162
+ export {
163
+ dataFetchServerMiddleware as default
164
+ };
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const lazyUtils = require("./utils-CFTy4LVE.js");
4
+ const prefetch = require("./prefetch-DLhPTofn.js");
5
+ async function callDataFetch() {
6
+ const dataFetch = globalThis[lazyUtils.DATA_FETCH_FUNCTION];
7
+ if (dataFetch) {
8
+ await Promise.all(
9
+ dataFetch.map(async (options) => {
10
+ await prefetch.dataFetchFunction(options);
11
+ })
12
+ );
13
+ }
14
+ }
15
+ exports.CacheSize = lazyUtils.CacheSize;
16
+ exports.CacheTime = lazyUtils.CacheTime;
17
+ exports.cache = lazyUtils.cache;
18
+ exports.clearStore = lazyUtils.clearStore;
19
+ exports.configureCache = lazyUtils.configureCache;
20
+ exports.generateKey = lazyUtils.generateKey;
21
+ exports.revalidateTag = lazyUtils.revalidateTag;
22
+ exports.injectDataFetch = prefetch.injectDataFetch;
23
+ exports.prefetch = prefetch.prefetch;
24
+ exports.callDataFetch = callDataFetch;
@@ -0,0 +1,81 @@
1
+ import { getInstance } from '@module-federation/runtime';
2
+
3
+ export declare function cache<T>(fn: DataFetch<T>, options?: CacheOptions): DataFetch<T>;
4
+
5
+ declare interface CacheConfig {
6
+ maxSize?: number;
7
+ unstable_shouldDisable?: ({ request, }: {
8
+ request: Request;
9
+ }) => boolean | Promise<boolean>;
10
+ }
11
+
12
+ declare interface CacheOptions {
13
+ tag?: string | string[];
14
+ maxAge?: number;
15
+ revalidate?: number;
16
+ getKey?: <Args extends any[]>(...args: Args) => string;
17
+ onCache?: (info: CacheStatsInfo) => boolean;
18
+ }
19
+
20
+ export declare const CacheSize: {
21
+ readonly KB: 1024;
22
+ readonly MB: number;
23
+ readonly GB: number;
24
+ };
25
+
26
+ export declare interface CacheStatsInfo {
27
+ status: CacheStatus;
28
+ key: string | symbol;
29
+ params: DataFetchParams;
30
+ result: any;
31
+ }
32
+
33
+ export declare type CacheStatus = 'hit' | 'stale' | 'miss';
34
+
35
+ export declare const CacheTime: {
36
+ readonly SECOND: 1000;
37
+ readonly MINUTE: number;
38
+ readonly HOUR: number;
39
+ readonly DAY: number;
40
+ readonly WEEK: number;
41
+ readonly MONTH: number;
42
+ };
43
+
44
+ export declare function callDataFetch(): Promise<void>;
45
+
46
+ export declare function clearStore(): void;
47
+
48
+ export declare function configureCache(config: CacheConfig): void;
49
+
50
+ declare type DataFetch<T> = (params: DataFetchParams) => Promise<T>;
51
+
52
+ declare type DataFetchParams = {
53
+ isDowngrade: boolean;
54
+ _id?: string;
55
+ } & Record<string, unknown>;
56
+
57
+ export declare function generateKey(dataFetchOptions: DataFetchParams): string;
58
+
59
+ export declare function injectDataFetch(): void;
60
+
61
+ export declare function prefetch(options: PrefetchOptions): Promise<void>;
62
+
63
+ export declare type PrefetchOptions = {
64
+ id: string;
65
+ instance: ReturnType<typeof getInstance>;
66
+ dataFetchParams?: DataFetchParams;
67
+ preloadComponentResource?: boolean;
68
+ };
69
+
70
+ export declare function revalidateTag(tag: string): void;
71
+
72
+ export { }
73
+
74
+
75
+ declare module '@module-federation/runtime-core' {
76
+ interface ModuleFederation {
77
+ createLazyComponent<T, E extends keyof T>(options: Omit<CreateLazyComponentOptions<T, E>, 'instance'>): ReturnType<typeof createLazyComponent<T, E>>;
78
+ prefetch(options: Omit<PrefetchOptions, 'instance'>): ReturnType<typeof prefetch>;
79
+ collectSSRAssets(options: Omit<Parameters<typeof collectSSRAssets>[0], 'instance'>): ReturnType<typeof collectSSRAssets>;
80
+ }
81
+ }
@@ -0,0 +1,26 @@
1
+ import { y as DATA_FETCH_FUNCTION } from "./utils-DGS4pYp8.mjs";
2
+ import { C, a, c, b, d, g, r } from "./utils-DGS4pYp8.mjs";
3
+ import { d as dataFetchFunction } from "./prefetch-BwRDb4SJ.mjs";
4
+ import { i, p } from "./prefetch-BwRDb4SJ.mjs";
5
+ async function callDataFetch() {
6
+ const dataFetch = globalThis[DATA_FETCH_FUNCTION];
7
+ if (dataFetch) {
8
+ await Promise.all(
9
+ dataFetch.map(async (options) => {
10
+ await dataFetchFunction(options);
11
+ })
12
+ );
13
+ }
14
+ }
15
+ export {
16
+ C as CacheSize,
17
+ a as CacheTime,
18
+ c as cache,
19
+ callDataFetch,
20
+ b as clearStore,
21
+ d as configureCache,
22
+ g as generateKey,
23
+ i as injectDataFetch,
24
+ p as prefetch,
25
+ r as revalidateTag
26
+ };
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const lazyLoadComponentPlugin = require("./lazy-load-component-plugin-BjMVNoep.js");
4
+ const lazyUtils = require("./utils-CFTy4LVE.js");
5
+ const dataFetchUtils = require("./data-fetch-utils.cjs.js");
6
+ const prefetch = require("./prefetch-DLhPTofn.js");
7
+ exports.autoFetchDataPlugin = lazyLoadComponentPlugin.autoFetchData;
8
+ exports.collectSSRAssets = lazyLoadComponentPlugin.collectSSRAssets;
9
+ exports.createLazyComponent = lazyLoadComponentPlugin.createLazyComponent;
10
+ exports.lazyLoadComponentPlugin = lazyLoadComponentPlugin.lazyLoadComponentPlugin;
11
+ exports.CacheSize = lazyUtils.CacheSize;
12
+ exports.CacheTime = lazyUtils.CacheTime;
13
+ exports.ERROR_TYPE = lazyUtils.ERROR_TYPE;
14
+ exports.cache = lazyUtils.cache;
15
+ exports.clearStore = lazyUtils.clearStore;
16
+ exports.configureCache = lazyUtils.configureCache;
17
+ exports.flushDataFetch = lazyUtils.flushDataFetch;
18
+ exports.generateKey = lazyUtils.generateKey;
19
+ exports.revalidateTag = lazyUtils.revalidateTag;
20
+ exports.setSSREnv = lazyUtils.setSSREnv;
21
+ exports.callDataFetch = dataFetchUtils.callDataFetch;
22
+ exports.prefetch = prefetch.prefetch;