@module-federation/modern-js 0.16.0 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) 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/package.json +24 -24
  34. package/dist/cjs/cli/mfRuntimePlugins/auto-fetch-data.js +0 -100
  35. package/dist/cjs/interfaces/global.js +0 -16
  36. package/dist/cjs/runtime/AwaitDataFetch.js +0 -144
  37. package/dist/cjs/runtime/createRemoteComponent.js +0 -327
  38. package/dist/cjs/ssr-runtime/downgrade.js +0 -114
  39. package/dist/cjs/utils/dataFetch.js +0 -211
  40. package/dist/cjs/utils/index.js +0 -54
  41. package/dist/esm/cli/mfRuntimePlugins/auto-fetch-data.js +0 -76
  42. package/dist/esm/interfaces/global.js +0 -0
  43. package/dist/esm/runtime/AwaitDataFetch.js +0 -131
  44. package/dist/esm/runtime/createRemoteComponent.js +0 -417
  45. package/dist/esm/runtime/wrapNoSSR.js +0 -12
  46. package/dist/esm/ssr-runtime/downgrade.js +0 -150
  47. package/dist/esm/utils/dataFetch.js +0 -237
  48. package/dist/esm/utils/index.js +0 -28
  49. package/dist/esm-node/cli/mfRuntimePlugins/auto-fetch-data.js +0 -70
  50. package/dist/esm-node/interfaces/global.js +0 -0
  51. package/dist/esm-node/runtime/AwaitDataFetch.js +0 -109
  52. package/dist/esm-node/runtime/createRemoteComponent.js +0 -291
  53. package/dist/esm-node/runtime/wrapNoSSR.js +0 -11
  54. package/dist/esm-node/ssr-runtime/downgrade.js +0 -88
  55. package/dist/esm-node/utils/dataFetch.js +0 -166
  56. package/dist/esm-node/utils/index.js +0 -27
  57. package/dist/types/cli/mfRuntimePlugins/auto-fetch-data.d.ts +0 -3
  58. package/dist/types/interfaces/global.d.ts +0 -27
  59. package/dist/types/runtime/AwaitDataFetch.d.ts +0 -19
  60. package/dist/types/runtime/createRemoteComponent.d.ts +0 -26
  61. package/dist/types/runtime/wrapNoSSR.d.ts +0 -9
  62. package/dist/types/ssr-runtime/downgrade.d.ts +0 -4
  63. package/dist/types/utils/dataFetch.d.ts +0 -26
  64. package/dist/types/utils/index.d.ts +0 -15
@@ -148,7 +148,6 @@ 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/modern-js/auto-fetch-data"), runtimePlugins);
152
151
  if (enableSSR && (0, import_utils3.isDev)()) {
153
152
  injectRuntimePlugins(require.resolve("@module-federation/modern-js/resolve-entry-ipv4"), runtimePlugins);
154
153
  }
@@ -352,11 +351,13 @@ const moduleFederationConfigPlugin = (userConfig) => ({
352
351
  headers: corsHeaders
353
352
  }
354
353
  },
355
- source: {
354
+ resolve: {
356
355
  alias: {
357
356
  // TODO: deprecated
358
357
  "@modern-js/runtime/mf": require.resolve("@module-federation/modern-js/runtime")
359
- },
358
+ }
359
+ },
360
+ source: {
360
361
  define: defineConfig,
361
362
  enableAsyncEntry: bundlerType === "rspack" ? (_modernjsConfig_source_enableAsyncEntry = (_modernjsConfig_source = modernjsConfig.source) === null || _modernjsConfig_source === void 0 ? void 0 : _modernjsConfig_source.enableAsyncEntry) !== null && _modernjsConfig_source_enableAsyncEntry !== void 0 ? _modernjsConfig_source_enableAsyncEntry : true : (_modernjsConfig_source1 = modernjsConfig.source) === null || _modernjsConfig_source1 === void 0 ? void 0 : _modernjsConfig_source1.enableAsyncEntry
362
363
  },
@@ -61,7 +61,6 @@ const mfConfig = {
61
61
  remoteType: "script",
62
62
  runtimePlugins: [
63
63
  require.resolve("@module-federation/modern-js/shared-strategy"),
64
- require.resolve("@module-federation/modern-js/auto-fetch-data"),
65
64
  require.resolve("@module-federation/node/runtimePlugin"),
66
65
  require.resolve("@module-federation/modern-js/inject-node-fetch")
67
66
  ],
@@ -89,8 +88,7 @@ const mfConfig = {
89
88
  },
90
89
  remoteType: "script",
91
90
  runtimePlugins: [
92
- require.resolve("@module-federation/modern-js/shared-strategy"),
93
- require.resolve("@module-federation/modern-js/auto-fetch-data")
91
+ require.resolve("@module-federation/modern-js/shared-strategy")
94
92
  ],
95
93
  shared: {
96
94
  react: {
@@ -31,148 +31,7 @@ __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 import_constant = require("../../constant");
35
- var import_logger = __toESM(require("../../logger"));
36
- var import_utils = require("../../utils");
37
- var import_dataFetch = require("../../utils/dataFetch");
38
- var import_sdk = require("@module-federation/sdk");
39
- function wrapSetTimeout(targetPromise, delay = 2e4, id) {
40
- if (targetPromise && typeof targetPromise.then === "function") {
41
- return new Promise((resolve, reject) => {
42
- const timeoutId = setTimeout(() => {
43
- import_logger.default.warn(`Data fetch for ID ${id} timed out after 20 seconds.`);
44
- reject(new Error(`Data fetch for ID ${id} timed out after 20 seconds`));
45
- }, delay);
46
- targetPromise.then((value) => {
47
- clearTimeout(timeoutId);
48
- resolve(value);
49
- }).catch((err) => {
50
- clearTimeout(timeoutId);
51
- reject(err);
52
- });
53
- });
54
- }
55
- }
56
- function addProtocol(url) {
57
- if (url.startsWith("//")) {
58
- return "https:" + url;
59
- }
60
- return url;
61
- }
62
- const getDecodeQuery = (url, name) => {
63
- const res = url.searchParams.get(name);
64
- if (!res) {
65
- return null;
66
- }
67
- return decodeURIComponent(res);
68
- };
69
- const middleware = async (ctx, next) => {
70
- var _globalThis___FEDERATION__;
71
- let url;
72
- let dataFetchId;
73
- let params;
74
- let remoteInfo;
75
- try {
76
- url = new URL(ctx.req.url);
77
- dataFetchId = getDecodeQuery(url, import_constant.DATA_FETCH_QUERY);
78
- params = JSON.parse(getDecodeQuery(url, "params") || "{}");
79
- const remoteInfoQuery = getDecodeQuery(url, "remoteInfo");
80
- remoteInfo = remoteInfoQuery ? JSON.parse(remoteInfoQuery) : null;
81
- } catch (e) {
82
- import_logger.default.error("fetch data from server, error: ", e);
83
- return next();
84
- }
85
- if (!dataFetchId) {
86
- return next();
87
- }
88
- import_logger.default.log("fetch data from server, dataFetchId: ", dataFetchId);
89
- import_logger.default.debug("fetch data from server, moduleInfo: ", (_globalThis___FEDERATION__ = globalThis.__FEDERATION__) === null || _globalThis___FEDERATION__ === void 0 ? void 0 : _globalThis___FEDERATION__.moduleInfo);
90
- try {
91
- var _dataFetchMap_dataFetchId, _dataFetchMap_dataFetchId1;
92
- const dataFetchMap = (0, import_utils.getDataFetchMap)();
93
- if (!dataFetchMap) {
94
- (0, import_dataFetch.initDataFetchMap)();
95
- }
96
- const fetchDataPromise = (_dataFetchMap_dataFetchId = dataFetchMap[dataFetchId]) === null || _dataFetchMap_dataFetchId === void 0 ? void 0 : _dataFetchMap_dataFetchId[1];
97
- 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]) !== import_constant.MF_DATA_FETCH_STATUS.ERROR) {
99
- const targetPromise = fetchDataPromise[0];
100
- const wrappedPromise = wrapSetTimeout(targetPromise, 2e4, dataFetchId);
101
- if (wrappedPromise) {
102
- const res = await wrappedPromise;
103
- import_logger.default.log("fetch data from server, fetchDataPromise res: ", res);
104
- return ctx.json(res);
105
- }
106
- import_logger.default.error(`Expected a Promise from fetchDataPromise[0] for dataFetchId ${dataFetchId}, but received:`, targetPromise, "Will try call new dataFetch again...");
107
- }
108
- if (remoteInfo) {
109
- try {
110
- const hostInstance2 = globalThis.__FEDERATION__.__INSTANCES__[0];
111
- const remoteEntry = `${addProtocol(remoteInfo.ssrPublicPath) + remoteInfo.ssrRemoteEntry}`;
112
- if (!hostInstance2) {
113
- throw new Error("host instance not found!");
114
- }
115
- const remote = hostInstance2.options.remotes.find((remote2) => remote2.name === remoteInfo.name);
116
- import_logger.default.debug("find remote: ", JSON.stringify(remote));
117
- if (!remote) {
118
- hostInstance2.registerRemotes([
119
- {
120
- name: remoteInfo.name,
121
- entry: remoteEntry,
122
- entryGlobalName: remoteInfo.globalName
123
- }
124
- ]);
125
- } else if (!("entry" in remote) || !remote.entry.includes(import_sdk.MANIFEST_EXT)) {
126
- const { hostGlobalSnapshot, remoteSnapshot } = hostInstance2.snapshotHandler.getGlobalRemoteInfo(remoteInfo);
127
- import_logger.default.debug("find hostGlobalSnapshot: ", JSON.stringify(hostGlobalSnapshot));
128
- import_logger.default.debug("find remoteSnapshot: ", JSON.stringify(remoteSnapshot));
129
- if (!hostGlobalSnapshot || !remoteSnapshot) {
130
- if ("version" in remote) {
131
- delete remote.version;
132
- }
133
- remote.entry = remoteEntry;
134
- remote.entryGlobalName = remoteInfo.globalName;
135
- }
136
- }
137
- } catch (e) {
138
- ctx.status(500);
139
- return ctx.text(`failed to fetch ${remoteInfo.name} data, error:
140
- ${e}`);
141
- }
142
- }
143
- const dataFetchItem = dataFetchMap[dataFetchId];
144
- import_logger.default.debug("fetch data from server, dataFetchItem: ", dataFetchItem);
145
- if (dataFetchItem) {
146
- const callFetchDataPromise = (0, import_dataFetch.fetchData)(dataFetchId, {
147
- ...params,
148
- isDowngrade: !remoteInfo
149
- });
150
- const wrappedPromise = wrapSetTimeout(callFetchDataPromise, 2e4, dataFetchId);
151
- if (wrappedPromise) {
152
- const res = await wrappedPromise;
153
- import_logger.default.log("fetch data from server, dataFetchItem res: ", res);
154
- return ctx.json(res);
155
- }
156
- }
157
- const remoteId = dataFetchId.split(import_sdk.SEPARATOR)[0];
158
- const hostInstance = globalThis.__FEDERATION__.__INSTANCES__[0];
159
- if (!hostInstance) {
160
- throw new Error("host instance not found!");
161
- }
162
- const dataFetchFn = await (0, import_dataFetch.loadDataFetchModule)(hostInstance, remoteId);
163
- const data = await dataFetchFn({
164
- ...params,
165
- isDowngrade: !remoteInfo
166
- });
167
- import_logger.default.log("fetch data from server, loadDataFetchModule res: ", data);
168
- return ctx.json(data);
169
- } catch (e) {
170
- import_logger.default.error("server plugin data fetch error: ", e);
171
- ctx.status(500);
172
- return ctx.text(`failed to fetch ${remoteInfo.name} data, error:
173
- ${e}`);
174
- }
175
- };
34
+ var import_data_fetch_server_middleware = __toESM(require("@module-federation/bridge-react/data-fetch-server-middleware"));
176
35
  const dataFetchServePlugin = () => ({
177
36
  name: "mf-data-fetch-server-plugin",
178
37
  setup: (api) => {
@@ -181,7 +40,7 @@ const dataFetchServePlugin = () => ({
181
40
  middlewares.push({
182
41
  name: "module-federation-serve-manifest",
183
42
  // @ts-ignore type error
184
- handler: middleware
43
+ handler: import_data_fetch_server_middleware.default
185
44
  });
186
45
  });
187
46
  }
@@ -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
- MF_DATA_FETCH_STATUS: () => MF_DATA_FETCH_STATUS,
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
- MF_DATA_FETCH_STATUS,
75
- MF_DATA_FETCH_TYPE,
76
- PLUGIN_IDENTIFIER,
77
- WRAP_DATA_FETCH_ID_IDENTIFIER
30
+ PLUGIN_IDENTIFIER
78
31
  });
@@ -16,20 +16,29 @@ var __copyProps = (to, from, except, desc) => {
16
16
  return to;
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var wrapNoSSR_exports = {};
20
- __export(wrapNoSSR_exports, {
21
- wrapNoSSR: () => wrapNoSSR
19
+ var react_exports = {};
20
+ __export(react_exports, {
21
+ CacheSize: () => import_bridge_react.CacheSize,
22
+ CacheTime: () => import_bridge_react.CacheTime,
23
+ ERROR_TYPE: () => import_bridge_react.ERROR_TYPE,
24
+ cache: () => import_bridge_react.cache,
25
+ clearStore: () => import_bridge_react.clearStore,
26
+ configureCache: () => import_bridge_react.configureCache,
27
+ generateKey: () => import_bridge_react.generateKey,
28
+ lazyLoadComponentPlugin: () => import_bridge_react.lazyLoadComponentPlugin,
29
+ revalidateTag: () => import_bridge_react.revalidateTag
22
30
  });
23
- module.exports = __toCommonJS(wrapNoSSR_exports);
24
- function wrapNoSSR(createComponentFn) {
25
- return (options) => {
26
- return createComponentFn({
27
- ...options,
28
- noSSR: true
29
- });
30
- };
31
- }
31
+ module.exports = __toCommonJS(react_exports);
32
+ var import_bridge_react = require("@module-federation/bridge-react");
32
33
  // Annotate the CommonJS export names for ESM import in node:
33
34
  0 && (module.exports = {
34
- wrapNoSSR
35
+ CacheSize,
36
+ CacheTime,
37
+ ERROR_TYPE,
38
+ cache,
39
+ clearStore,
40
+ configureCache,
41
+ generateKey,
42
+ lazyLoadComponentPlugin,
43
+ revalidateTag
35
44
  });
@@ -3,10 +3,6 @@ var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
6
  var __copyProps = (to, from, except, desc) => {
11
7
  if (from && typeof from === "object" || typeof from === "function") {
12
8
  for (let key of __getOwnPropNames(from))
@@ -18,33 +14,9 @@ var __copyProps = (to, from, except, desc) => {
18
14
  var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
19
15
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
16
  var runtime_exports = {};
21
- __export(runtime_exports, {
22
- ERROR_TYPE: () => import_constant.ERROR_TYPE,
23
- kit: () => kit,
24
- setSSREnv: () => import_injectDataFetchFunctionPlugin.setSSREnv
25
- });
26
17
  module.exports = __toCommonJS(runtime_exports);
27
18
  __reExport(runtime_exports, require("@module-federation/enhanced/runtime"), module.exports);
28
- var import_constant = require("../constant");
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
- };
44
19
  // Annotate the CommonJS export names for ESM import in node:
45
20
  0 && (module.exports = {
46
- ERROR_TYPE,
47
- kit,
48
- setSSREnv,
49
21
  ...require("@module-federation/enhanced/runtime")
50
22
  });
@@ -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 import_utils = require("../utils");
36
+ var import_lazy_utils = require("@module-federation/bridge-react/lazy-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, import_utils.flushDataFetch)();
51
+ (0, import_lazy_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,26 @@ 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 import_constant = require("../constant");
36
- var import_logger = __toESM(require("../logger"));
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_data_fetch_utils = require("@module-federation/bridge-react/data-fetch-utils");
25
+ var import_lazy_utils = require("@module-federation/bridge-react/lazy-utils");
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
- setSSREnv({
30
+ (0, import_lazy_utils.setSSREnv)({
49
31
  fetchServerQuery
50
32
  });
51
- if (typeof window === "undefined") {
52
- return;
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
+ await (0, import_data_fetch_utils.callDataFetch)();
129
34
  });
130
35
  }
131
36
  });
132
37
  // Annotate the CommonJS export names for ESM import in node:
133
38
  0 && (module.exports = {
134
- injectDataFetchFunctionPlugin,
135
- setSSREnv
39
+ injectDataFetchFunctionPlugin
136
40
  });
@@ -138,7 +138,6 @@ 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/modern-js/auto-fetch-data"), runtimePlugins);
142
141
  if (enableSSR && isDev()) {
143
142
  injectRuntimePlugins(require.resolve("@module-federation/modern-js/resolve-entry-ipv4"), runtimePlugins);
144
143
  }
@@ -349,11 +348,13 @@ var moduleFederationConfigPlugin = function(userConfig) {
349
348
  headers: corsHeaders
350
349
  }
351
350
  },
352
- source: {
351
+ resolve: {
353
352
  alias: {
354
353
  // TODO: deprecated
355
354
  "@modern-js/runtime/mf": require.resolve("@module-federation/modern-js/runtime")
356
- },
355
+ }
356
+ },
357
+ source: {
357
358
  define: defineConfig,
358
359
  enableAsyncEntry: bundlerType === "rspack" ? (_modernjsConfig_source_enableAsyncEntry = (_modernjsConfig_source = modernjsConfig.source) === null || _modernjsConfig_source === void 0 ? void 0 : _modernjsConfig_source.enableAsyncEntry) !== null && _modernjsConfig_source_enableAsyncEntry !== void 0 ? _modernjsConfig_source_enableAsyncEntry : true : (_modernjsConfig_source1 = modernjsConfig.source) === null || _modernjsConfig_source1 === void 0 ? void 0 : _modernjsConfig_source1.enableAsyncEntry
359
360
  },
@@ -43,7 +43,6 @@ 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/modern-js/auto-fetch-data"),
47
46
  require.resolve("@module-federation/node/runtimePlugin"),
48
47
  require.resolve("@module-federation/modern-js/inject-node-fetch")
49
48
  ],
@@ -77,8 +76,7 @@ describe("patchMFConfig", /* @__PURE__ */ _async_to_generator(function() {
77
76
  },
78
77
  remoteType: "script",
79
78
  runtimePlugins: [
80
- require.resolve("@module-federation/modern-js/shared-strategy"),
81
- require.resolve("@module-federation/modern-js/auto-fetch-data")
79
+ require.resolve("@module-federation/modern-js/shared-strategy")
82
80
  ],
83
81
  shared: {
84
82
  react: {