@module-federation/modern-js 0.16.0 → 0.17.1

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 (65) hide show
  1. package/dist/cjs/cli/configPlugin.js +4 -3
  2. package/dist/cjs/cli/configPlugin.spec.js +1 -3
  3. package/dist/cjs/cli/server/data-fetch-server-plugin.js +2 -143
  4. package/dist/cjs/constant.js +2 -49
  5. package/dist/cjs/{runtime/wrapNoSSR.js → react/index.js} +22 -13
  6. package/dist/cjs/runtime/index.js +0 -28
  7. package/dist/cjs/ssr-runtime/devPlugin.js +2 -2
  8. package/dist/cjs/ssr-runtime/injectDataFetchFunctionPlugin.js +6 -102
  9. package/dist/esm/cli/configPlugin.js +4 -3
  10. package/dist/esm/cli/configPlugin.spec.js +1 -3
  11. package/dist/esm/cli/server/data-fetch-server-plugin.js +2 -219
  12. package/dist/esm/constant.js +1 -37
  13. package/dist/esm/react/index.js +12 -0
  14. package/dist/esm/runtime/index.js +0 -21
  15. package/dist/esm/ssr-runtime/devPlugin.js +1 -1
  16. package/dist/esm/ssr-runtime/injectDataFetchFunctionPlugin.js +4 -147
  17. package/dist/esm-node/cli/configPlugin.js +4 -3
  18. package/dist/esm-node/cli/configPlugin.spec.js +1 -3
  19. package/dist/esm-node/cli/server/data-fetch-server-plugin.js +2 -143
  20. package/dist/esm-node/constant.js +1 -37
  21. package/dist/esm-node/react/index.js +12 -0
  22. package/dist/esm-node/runtime/index.js +0 -21
  23. package/dist/esm-node/ssr-runtime/devPlugin.js +1 -1
  24. package/dist/esm-node/ssr-runtime/injectDataFetchFunctionPlugin.js +4 -89
  25. package/dist/types/cli/index.d.ts +1 -1
  26. package/dist/types/cli/mfRuntimePlugins/inject-node-fetch.d.ts +2 -2
  27. package/dist/types/cli/mfRuntimePlugins/resolve-entry-ipv4.d.ts +2 -2
  28. package/dist/types/cli/mfRuntimePlugins/shared-strategy.d.ts +2 -2
  29. package/dist/types/constant.d.ts +0 -23
  30. package/dist/types/react/index.d.ts +2 -0
  31. package/dist/types/runtime/index.d.ts +0 -9
  32. package/dist/types/ssr-runtime/injectDataFetchFunctionPlugin.d.ts +0 -3
  33. package/dist/types/types/index.d.ts +1 -3
  34. package/package.json +26 -24
  35. package/dist/cjs/cli/mfRuntimePlugins/auto-fetch-data.js +0 -100
  36. package/dist/cjs/interfaces/global.js +0 -16
  37. package/dist/cjs/runtime/AwaitDataFetch.js +0 -144
  38. package/dist/cjs/runtime/createRemoteComponent.js +0 -327
  39. package/dist/cjs/ssr-runtime/downgrade.js +0 -114
  40. package/dist/cjs/utils/dataFetch.js +0 -211
  41. package/dist/cjs/utils/index.js +0 -54
  42. package/dist/esm/cli/mfRuntimePlugins/auto-fetch-data.js +0 -76
  43. package/dist/esm/interfaces/global.js +0 -0
  44. package/dist/esm/runtime/AwaitDataFetch.js +0 -131
  45. package/dist/esm/runtime/createRemoteComponent.js +0 -417
  46. package/dist/esm/runtime/wrapNoSSR.js +0 -12
  47. package/dist/esm/ssr-runtime/downgrade.js +0 -150
  48. package/dist/esm/utils/dataFetch.js +0 -237
  49. package/dist/esm/utils/index.js +0 -28
  50. package/dist/esm-node/cli/mfRuntimePlugins/auto-fetch-data.js +0 -70
  51. package/dist/esm-node/interfaces/global.js +0 -0
  52. package/dist/esm-node/runtime/AwaitDataFetch.js +0 -109
  53. package/dist/esm-node/runtime/createRemoteComponent.js +0 -291
  54. package/dist/esm-node/runtime/wrapNoSSR.js +0 -11
  55. package/dist/esm-node/ssr-runtime/downgrade.js +0 -88
  56. package/dist/esm-node/utils/dataFetch.js +0 -166
  57. package/dist/esm-node/utils/index.js +0 -27
  58. package/dist/types/cli/mfRuntimePlugins/auto-fetch-data.d.ts +0 -3
  59. package/dist/types/interfaces/global.d.ts +0 -27
  60. package/dist/types/runtime/AwaitDataFetch.d.ts +0 -19
  61. package/dist/types/runtime/createRemoteComponent.d.ts +0 -26
  62. package/dist/types/runtime/wrapNoSSR.d.ts +0 -9
  63. package/dist/types/ssr-runtime/downgrade.d.ts +0 -4
  64. package/dist/types/utils/dataFetch.d.ts +0 -26
  65. package/dist/types/utils/index.d.ts +0 -15
@@ -1,145 +1,4 @@
1
- import { DATA_FETCH_QUERY, MF_DATA_FETCH_STATUS } from "../../constant";
2
- import logger from "../../logger";
3
- import { getDataFetchMap } from "../../utils";
4
- import { fetchData, initDataFetchMap, loadDataFetchModule } from "../../utils/dataFetch";
5
- import { SEPARATOR, MANIFEST_EXT } from "@module-federation/sdk";
6
- function wrapSetTimeout(targetPromise, delay = 2e4, id) {
7
- if (targetPromise && typeof targetPromise.then === "function") {
8
- return new Promise((resolve, reject) => {
9
- const timeoutId = setTimeout(() => {
10
- logger.warn(`Data fetch for ID ${id} timed out after 20 seconds.`);
11
- reject(new Error(`Data fetch for ID ${id} timed out after 20 seconds`));
12
- }, delay);
13
- targetPromise.then((value) => {
14
- clearTimeout(timeoutId);
15
- resolve(value);
16
- }).catch((err) => {
17
- clearTimeout(timeoutId);
18
- reject(err);
19
- });
20
- });
21
- }
22
- }
23
- function addProtocol(url) {
24
- if (url.startsWith("//")) {
25
- return "https:" + url;
26
- }
27
- return url;
28
- }
29
- const getDecodeQuery = (url, name) => {
30
- const res = url.searchParams.get(name);
31
- if (!res) {
32
- return null;
33
- }
34
- return decodeURIComponent(res);
35
- };
36
- const middleware = async (ctx, next) => {
37
- var _globalThis___FEDERATION__;
38
- let url;
39
- let dataFetchId;
40
- let params;
41
- let remoteInfo;
42
- try {
43
- url = new URL(ctx.req.url);
44
- dataFetchId = getDecodeQuery(url, DATA_FETCH_QUERY);
45
- params = JSON.parse(getDecodeQuery(url, "params") || "{}");
46
- const remoteInfoQuery = getDecodeQuery(url, "remoteInfo");
47
- remoteInfo = remoteInfoQuery ? JSON.parse(remoteInfoQuery) : null;
48
- } catch (e) {
49
- logger.error("fetch data from server, error: ", e);
50
- return next();
51
- }
52
- if (!dataFetchId) {
53
- return next();
54
- }
55
- logger.log("fetch data from server, dataFetchId: ", dataFetchId);
56
- logger.debug("fetch data from server, moduleInfo: ", (_globalThis___FEDERATION__ = globalThis.__FEDERATION__) === null || _globalThis___FEDERATION__ === void 0 ? void 0 : _globalThis___FEDERATION__.moduleInfo);
57
- try {
58
- var _dataFetchMap_dataFetchId, _dataFetchMap_dataFetchId1;
59
- const dataFetchMap = getDataFetchMap();
60
- if (!dataFetchMap) {
61
- initDataFetchMap();
62
- }
63
- const fetchDataPromise = (_dataFetchMap_dataFetchId = dataFetchMap[dataFetchId]) === null || _dataFetchMap_dataFetchId === void 0 ? void 0 : _dataFetchMap_dataFetchId[1];
64
- logger.debug("fetch data from server, fetchDataPromise: ", fetchDataPromise);
65
- if (fetchDataPromise && ((_dataFetchMap_dataFetchId1 = dataFetchMap[dataFetchId]) === null || _dataFetchMap_dataFetchId1 === void 0 ? void 0 : _dataFetchMap_dataFetchId1[2]) !== MF_DATA_FETCH_STATUS.ERROR) {
66
- const targetPromise = fetchDataPromise[0];
67
- const wrappedPromise = wrapSetTimeout(targetPromise, 2e4, dataFetchId);
68
- if (wrappedPromise) {
69
- const res = await wrappedPromise;
70
- logger.log("fetch data from server, fetchDataPromise res: ", res);
71
- return ctx.json(res);
72
- }
73
- logger.error(`Expected a Promise from fetchDataPromise[0] for dataFetchId ${dataFetchId}, but received:`, targetPromise, "Will try call new dataFetch again...");
74
- }
75
- if (remoteInfo) {
76
- try {
77
- const hostInstance2 = globalThis.__FEDERATION__.__INSTANCES__[0];
78
- const remoteEntry = `${addProtocol(remoteInfo.ssrPublicPath) + remoteInfo.ssrRemoteEntry}`;
79
- if (!hostInstance2) {
80
- throw new Error("host instance not found!");
81
- }
82
- const remote = hostInstance2.options.remotes.find((remote2) => remote2.name === remoteInfo.name);
83
- logger.debug("find remote: ", JSON.stringify(remote));
84
- if (!remote) {
85
- hostInstance2.registerRemotes([
86
- {
87
- name: remoteInfo.name,
88
- entry: remoteEntry,
89
- entryGlobalName: remoteInfo.globalName
90
- }
91
- ]);
92
- } else if (!("entry" in remote) || !remote.entry.includes(MANIFEST_EXT)) {
93
- const { hostGlobalSnapshot, remoteSnapshot } = hostInstance2.snapshotHandler.getGlobalRemoteInfo(remoteInfo);
94
- logger.debug("find hostGlobalSnapshot: ", JSON.stringify(hostGlobalSnapshot));
95
- logger.debug("find remoteSnapshot: ", JSON.stringify(remoteSnapshot));
96
- if (!hostGlobalSnapshot || !remoteSnapshot) {
97
- if ("version" in remote) {
98
- delete remote.version;
99
- }
100
- remote.entry = remoteEntry;
101
- remote.entryGlobalName = remoteInfo.globalName;
102
- }
103
- }
104
- } catch (e) {
105
- ctx.status(500);
106
- return ctx.text(`failed to fetch ${remoteInfo.name} data, error:
107
- ${e}`);
108
- }
109
- }
110
- const dataFetchItem = dataFetchMap[dataFetchId];
111
- logger.debug("fetch data from server, dataFetchItem: ", dataFetchItem);
112
- if (dataFetchItem) {
113
- const callFetchDataPromise = fetchData(dataFetchId, {
114
- ...params,
115
- isDowngrade: !remoteInfo
116
- });
117
- const wrappedPromise = wrapSetTimeout(callFetchDataPromise, 2e4, dataFetchId);
118
- if (wrappedPromise) {
119
- const res = await wrappedPromise;
120
- logger.log("fetch data from server, dataFetchItem res: ", res);
121
- return ctx.json(res);
122
- }
123
- }
124
- const remoteId = dataFetchId.split(SEPARATOR)[0];
125
- const hostInstance = globalThis.__FEDERATION__.__INSTANCES__[0];
126
- if (!hostInstance) {
127
- throw new Error("host instance not found!");
128
- }
129
- const dataFetchFn = await loadDataFetchModule(hostInstance, remoteId);
130
- const data = await dataFetchFn({
131
- ...params,
132
- isDowngrade: !remoteInfo
133
- });
134
- logger.log("fetch data from server, loadDataFetchModule res: ", data);
135
- return ctx.json(data);
136
- } catch (e) {
137
- logger.error("server plugin data fetch error: ", e);
138
- ctx.status(500);
139
- return ctx.text(`failed to fetch ${remoteInfo.name} data, error:
140
- ${e}`);
141
- }
142
- };
1
+ import dataFetchMiddleWare from "@module-federation/bridge-react/data-fetch-server-middleware";
143
2
  const dataFetchServePlugin = () => ({
144
3
  name: "mf-data-fetch-server-plugin",
145
4
  setup: (api) => {
@@ -148,7 +7,7 @@ const dataFetchServePlugin = () => ({
148
7
  middlewares.push({
149
8
  name: "module-federation-serve-manifest",
150
9
  // @ts-ignore type error
151
- handler: middleware
10
+ handler: dataFetchMiddleWare
152
11
  });
153
12
  });
154
13
  }
@@ -1,42 +1,6 @@
1
1
  const LOCALHOST = "localhost";
2
2
  const PLUGIN_IDENTIFIER = "[ Modern.js Module Federation ]";
3
- const DATA_FETCH_QUERY = "x-mf-data-fetch";
4
- const DATA_FETCH_ERROR_PREFIX = "caught the following error during dataFetch: ";
5
- const LOAD_REMOTE_ERROR_PREFIX = "caught the following error during loadRemote: ";
6
- const DOWNGRADE_KEY = "_mfSSRDowngrade";
7
- const DATA_FETCH_MAP_KEY = "__MF_DATA_FETCH_MAP__";
8
- const DATA_FETCH_FUNCTION = "_mfDataFetch";
9
- const FS_HREF = "_mfFSHref";
10
- const ERROR_TYPE = {
11
- DATA_FETCH: 1,
12
- LOAD_REMOTE: 2,
13
- UNKNOWN: 3
14
- };
15
- const 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
- MF_DATA_FETCH_STATUS,
39
- MF_DATA_FETCH_TYPE,
40
- PLUGIN_IDENTIFIER,
41
- WRAP_DATA_FETCH_ID_IDENTIFIER
5
+ PLUGIN_IDENTIFIER
42
6
  };
@@ -0,0 +1,12 @@
1
+ import { ERROR_TYPE, CacheSize, CacheTime, configureCache, generateKey, cache, revalidateTag, clearStore, lazyLoadComponentPlugin } from "@module-federation/bridge-react";
2
+ export {
3
+ CacheSize,
4
+ CacheTime,
5
+ ERROR_TYPE,
6
+ cache,
7
+ clearStore,
8
+ configureCache,
9
+ generateKey,
10
+ lazyLoadComponentPlugin,
11
+ revalidateTag
12
+ };
@@ -1,22 +1 @@
1
1
  export * from "@module-federation/enhanced/runtime";
2
- import { ERROR_TYPE } from "../constant";
3
- const 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";
18
- export {
19
- ERROR_TYPE,
20
- kit,
21
- setSSREnv
22
- };
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { SSRLiveReload } from "./SSRLiveReload";
3
- import { flushDataFetch } from "../utils";
3
+ import { flushDataFetch } from "@module-federation/bridge-react/lazy-utils";
4
4
  const mfSSRDevPlugin = () => ({
5
5
  name: "@module-federation/modern-js",
6
6
  setup: (api) => {
@@ -1,101 +1,16 @@
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
- }
1
+ import { callDataFetch } from "@module-federation/bridge-react/data-fetch-utils";
2
+ import { setSSREnv } from "@module-federation/bridge-react/lazy-utils";
9
3
  const injectDataFetchFunctionPlugin = ({ fetchServerQuery }) => ({
10
4
  name: "@module-federation/inject-data-fetch-function-plugin",
11
5
  setup: (api) => {
12
6
  api.onBeforeRender(async () => {
13
- var _globalThis, _DATA_FETCH_FUNCTION;
14
7
  setSSREnv({
15
8
  fetchServerQuery
16
9
  });
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;
10
+ await callDataFetch();
95
11
  });
96
12
  }
97
13
  });
98
14
  export {
99
- injectDataFetchFunctionPlugin,
100
- setSSREnv
15
+ injectDataFetchFunctionPlugin
101
16
  };
@@ -3,4 +3,4 @@ import type { PluginOptions } from '../types';
3
3
  export declare const moduleFederationPlugin: (userConfig?: PluginOptions) => CliPluginFuture<AppTools>;
4
4
  export default moduleFederationPlugin;
5
5
  export { createModuleFederationConfig } from '@module-federation/enhanced';
6
- export type { FederationRuntimePlugin } from '@module-federation/enhanced/runtime';
6
+ export type { ModuleFederationRuntimePlugin } from '@module-federation/enhanced/runtime';
@@ -1,3 +1,3 @@
1
- import type { FederationRuntimePlugin } from '@module-federation/enhanced/runtime';
2
- declare const injectNodeFetchPlugin: () => FederationRuntimePlugin;
1
+ import type { ModuleFederationRuntimePlugin } from '@module-federation/enhanced/runtime';
2
+ declare const injectNodeFetchPlugin: () => ModuleFederationRuntimePlugin;
3
3
  export default injectNodeFetchPlugin;
@@ -1,3 +1,3 @@
1
- import type { FederationRuntimePlugin } from '@module-federation/enhanced/runtime';
2
- declare const resolveEntryIpv4Plugin: () => FederationRuntimePlugin;
1
+ import type { ModuleFederationRuntimePlugin } from '@module-federation/enhanced/runtime';
2
+ declare const resolveEntryIpv4Plugin: () => ModuleFederationRuntimePlugin;
3
3
  export default resolveEntryIpv4Plugin;
@@ -1,3 +1,3 @@
1
- import type { FederationRuntimePlugin } from '@module-federation/enhanced/runtime';
2
- declare const sharedStrategy: () => FederationRuntimePlugin;
1
+ import type { ModuleFederationRuntimePlugin } from '@module-federation/enhanced/runtime';
2
+ declare const sharedStrategy: () => ModuleFederationRuntimePlugin;
3
3
  export default sharedStrategy;
@@ -1,25 +1,2 @@
1
1
  export declare const LOCALHOST = "localhost";
2
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,2 @@
1
+ export { ERROR_TYPE, CacheSize, CacheTime, configureCache, generateKey, cache, revalidateTag, clearStore, lazyLoadComponentPlugin, } from '@module-federation/bridge-react';
2
+ export type { DataFetchParams, CacheStatus, CacheStatsInfo, } from '@module-federation/bridge-react';
@@ -1,10 +1 @@
1
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';
@@ -1,7 +1,4 @@
1
1
  import type { RuntimePluginFuture } from '@modern-js/runtime';
2
- export declare function setSSREnv({ fetchServerQuery, }: {
3
- fetchServerQuery?: Record<string, unknown>;
4
- }): void;
5
2
  export declare const injectDataFetchFunctionPlugin: ({ fetchServerQuery, }: {
6
3
  fetchServerQuery?: Record<string, unknown>;
7
4
  }) => RuntimePluginFuture;
@@ -1,6 +1,4 @@
1
1
  import { moduleFederationPlugin } from '@module-federation/sdk';
2
- import type { ModuleFederationPlugin as WebpackModuleFederationPlugin } from '@module-federation/enhanced';
3
- import type { ModuleFederationPlugin as RspackModuleFederationPlugin } from '@module-federation/enhanced/rspack';
4
2
  export interface PluginOptions {
5
3
  config?: moduleFederationPlugin.ModuleFederationPluginOptions;
6
4
  configPath?: string;
@@ -21,4 +19,4 @@ export interface InternalModernPluginOptions {
21
19
  userConfig?: PluginOptions;
22
20
  fetchServerQuery?: Record<string, unknown>;
23
21
  }
24
- export type BundlerPlugin = WebpackModuleFederationPlugin | RspackModuleFederationPlugin;
22
+ export type BundlerPlugin = any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/modern-js",
3
- "version": "0.16.0",
3
+ "version": "0.17.1",
4
4
  "files": [
5
5
  "dist/",
6
6
  "types.d.ts",
@@ -24,6 +24,10 @@
24
24
  "types": "./dist/types/runtime/index.d.ts",
25
25
  "default": "./dist/esm/runtime/index.js"
26
26
  },
27
+ "./react": {
28
+ "types": "./dist/types/react/index.d.ts",
29
+ "default": "./dist/esm/react/index.js"
30
+ },
27
31
  "./ssr-dev-plugin": {
28
32
  "types": "./dist/types/ssr-runtime/devPlugin.d.ts",
29
33
  "default": "./dist/esm/ssr-runtime/devPlugin.js"
@@ -52,11 +56,6 @@
52
56
  "import": "./dist/esm/cli/mfRuntimePlugins/resolve-entry-ipv4.js",
53
57
  "require": "./dist/esm/cli/mfRuntimePlugins/resolve-entry-ipv4.js"
54
58
  },
55
- "./auto-fetch-data": {
56
- "types": "./dist/types/cli/mfRuntimePlugins/auto-fetch-data.d.ts",
57
- "import": "./dist/esm/cli/mfRuntimePlugins/auto-fetch-data.js",
58
- "require": "./dist/esm/cli/mfRuntimePlugins/auto-fetch-data.js"
59
- },
60
59
  "./inject-node-fetch": {
61
60
  "types": "./dist/types/cli/mfRuntimePlugins/inject-node-fetch.d.ts",
62
61
  "import": "./dist/esm/cli/mfRuntimePlugins/inject-node-fetch.js",
@@ -79,6 +78,9 @@
79
78
  "runtime": [
80
79
  "./dist/types/runtime/index.d.ts"
81
80
  ],
81
+ "react": [
82
+ "./dist/types/react/index.d.ts"
83
+ ],
82
84
  "config-plugin": [
83
85
  "./dist/types/cli/configPlugin.d.ts"
84
86
  ],
@@ -91,9 +93,6 @@
91
93
  "resolve-entry-ipv4": [
92
94
  "./dist/types/cli/mfRuntimePlugins/resolve-entry-ipv4.d.ts"
93
95
  ],
94
- "auto-fetch-data": [
95
- "./dist/types/cli/mfRuntimePlugins/auto-fetch-data.d.ts"
96
- ],
97
96
  "inject-node-fetch": [
98
97
  "./dist/types/cli/mfRuntimePlugins/inject-node-fetch.d.ts"
99
98
  ],
@@ -113,29 +112,32 @@
113
112
  "author": "hanric <hanric.zhang@gmail.com>",
114
113
  "license": "MIT",
115
114
  "dependencies": {
116
- "@modern-js/utils": "2.67.5",
117
- "@modern-js/node-bundle-require": "2.67.6",
115
+ "@modern-js/utils": "2.68.2",
116
+ "@modern-js/node-bundle-require": "2.68.2",
118
117
  "fs-extra": "11.3.0",
119
118
  "lru-cache": "10.4.3",
120
119
  "@swc/helpers": "^0.5.17",
121
120
  "node-fetch": "~3.3.0",
122
121
  "react-error-boundary": "4.1.2",
123
- "@module-federation/rsbuild-plugin": "0.16.0",
124
- "@module-federation/enhanced": "0.16.0",
125
- "@module-federation/runtime": "0.16.0",
126
- "@module-federation/node": "2.7.8",
127
- "@module-federation/sdk": "0.16.0",
128
- "@module-federation/cli": "0.16.0"
122
+ "@module-federation/rsbuild-plugin": "0.17.1",
123
+ "@module-federation/bridge-react": "0.17.1",
124
+ "@module-federation/enhanced": "0.17.1",
125
+ "@module-federation/runtime": "0.17.1",
126
+ "@module-federation/node": "2.7.10",
127
+ "@module-federation/sdk": "0.17.1",
128
+ "@module-federation/cli": "0.17.1"
129
129
  },
130
130
  "devDependencies": {
131
- "@modern-js/core": "2.67.5",
131
+ "@modern-js/core": "2.68.2",
132
132
  "@rsbuild/core": "1.3.21",
133
- "@modern-js/app-tools": "2.67.6",
134
- "@modern-js/server-runtime": "2.67.6",
135
- "@modern-js/module-tools": "2.67.6",
136
- "@modern-js/runtime": "2.67.6",
137
- "@modern-js/tsconfig": "2.67.6",
138
- "@module-federation/manifest": "0.16.0"
133
+ "@modern-js/app-tools": "2.68.2",
134
+ "@modern-js/server-runtime": "2.68.2",
135
+ "@modern-js/module-tools": "2.68.2",
136
+ "@modern-js/runtime": "2.68.2",
137
+ "@modern-js/tsconfig": "2.68.2",
138
+ "@types/react": "^18.3.11",
139
+ "@types/react-dom": "^18.3.0",
140
+ "@module-federation/manifest": "0.17.1"
139
141
  },
140
142
  "peerDependencies": {
141
143
  "react": ">=17",
@@ -1,100 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var auto_fetch_data_exports = {};
30
- __export(auto_fetch_data_exports, {
31
- default: () => auto_fetch_data_default
32
- });
33
- module.exports = __toCommonJS(auto_fetch_data_exports);
34
- var import_utils = require("../../utils");
35
- var import_logger = __toESM(require("../../logger"));
36
- var import_dataFetch = require("../../utils/dataFetch");
37
- var import_constant = require("../../constant");
38
- var import_constant2 = require("@module-federation/rsbuild-plugin/constant");
39
- const autoFetchData = () => ({
40
- name: "auto-fetch-data-plugin",
41
- beforeInit(args) {
42
- (0, import_utils.initDataFetchMap)();
43
- return args;
44
- },
45
- afterLoadSnapshot(args) {
46
- const { id, moduleInfo, remoteSnapshot, host } = args;
47
- if (typeof id === "string" && (0, import_dataFetch.isDataLoaderExpose)(id)) {
48
- return args;
49
- }
50
- if (!remoteSnapshot || !id || !("modules" in remoteSnapshot)) {
51
- return args;
52
- }
53
- const { name, alias } = moduleInfo;
54
- const dataFetchInfo = (0, import_utils.getDataFetchInfo)({
55
- name,
56
- alias,
57
- id,
58
- remoteSnapshot
59
- });
60
- if (!dataFetchInfo) {
61
- return args;
62
- }
63
- const { dataFetchId, dataFetchName } = dataFetchInfo;
64
- const dataFetchMapKey = (0, import_dataFetch.getDataFetchMapKey)(dataFetchInfo, {
65
- name: host.name,
66
- version: host.options.version
67
- });
68
- import_logger.default.debug("======= auto fetch plugin dataFetchMapKey: ", dataFetchMapKey);
69
- if (!dataFetchMapKey) {
70
- return args;
71
- }
72
- const dataFetchItem = (0, import_utils.getDataFetchItem)(dataFetchMapKey);
73
- if (dataFetchItem) {
74
- return args;
75
- }
76
- const dataFetchMap = (0, import_utils.getDataFetchMap)();
77
- const hasSSRAsset = Boolean(remoteSnapshot.ssrRemoteEntry);
78
- const hasDataFetchClient = Boolean(remoteSnapshot.modules.find((module2) => module2.moduleName === `${dataFetchName}${import_constant2.DATA_FETCH_CLIENT_SUFFIX}`));
79
- const downgradeType = hasDataFetchClient ? import_constant.MF_DATA_FETCH_TYPE.FETCH_CLIENT : hasSSRAsset ? import_constant.MF_DATA_FETCH_TYPE.FETCH_SERVER : import_constant.MF_DATA_FETCH_TYPE.FETCH_CLIENT;
80
- let finalDataFetchId = dataFetchId;
81
- if (typeof window !== "undefined") {
82
- finalDataFetchId = downgradeType === import_constant.MF_DATA_FETCH_TYPE.FETCH_CLIENT ? hasDataFetchClient ? `${dataFetchId}${import_constant2.DATA_FETCH_CLIENT_SUFFIX}` : dataFetchId : dataFetchId;
83
- }
84
- const getDataFetchGetter = () => (0, import_dataFetch.loadDataFetchModule)(host, finalDataFetchId);
85
- const dataFetchFnItem = [
86
- getDataFetchGetter,
87
- downgradeType
88
- ];
89
- if (typeof window === "undefined" || (0, import_utils.isCSROnly)()) {
90
- dataFetchFnItem.push(getDataFetchGetter());
91
- }
92
- dataFetchMap[dataFetchMapKey] = [
93
- dataFetchFnItem,
94
- void 0,
95
- import_constant.MF_DATA_FETCH_STATUS.AWAIT
96
- ];
97
- return args;
98
- }
99
- });
100
- var auto_fetch_data_default = autoFetchData;
@@ -1,16 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __copyProps = (to, from, except, desc) => {
7
- if (from && typeof from === "object" || typeof from === "function") {
8
- for (let key of __getOwnPropNames(from))
9
- if (!__hasOwnProp.call(to, key) && key !== except)
10
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
- }
12
- return to;
13
- };
14
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
- var global_exports = {};
16
- module.exports = __toCommonJS(global_exports);