@module-federation/modern-js 0.0.0-next-20250526033636 → 0.0.0-next-20250526035905

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 (82) hide show
  1. package/dist/cjs/cli/configPlugin.js +6 -8
  2. package/dist/cjs/cli/configPlugin.spec.js +1 -3
  3. package/dist/cjs/{runtime/wrapNoSSR.js → cli/constant.js} +6 -13
  4. package/dist/cjs/{logger.js → cli/logger.js} +1 -1
  5. package/dist/cjs/cli/ssrPlugin.js +11 -27
  6. package/dist/cjs/cli/utils.js +0 -5
  7. package/dist/cjs/constant.js +2 -49
  8. package/dist/cjs/runtime/createRemoteSSRComponent.js +210 -0
  9. package/dist/cjs/runtime/index.js +2 -11
  10. package/dist/cjs/{interfaces/global.js → ssr-runtime/index.js} +8 -2
  11. package/dist/cjs/ssr-runtime/{devPlugin.js → plugin.js} +6 -9
  12. package/dist/esm/cli/configPlugin.js +7 -9
  13. package/dist/esm/cli/configPlugin.spec.js +1 -3
  14. package/dist/esm/cli/constant.js +4 -0
  15. package/dist/esm/{logger.js → cli/logger.js} +1 -1
  16. package/dist/esm/cli/ssrPlugin.js +7 -24
  17. package/dist/esm/cli/utils.js +0 -4
  18. package/dist/esm/constant.js +1 -37
  19. package/dist/esm/runtime/createRemoteSSRComponent.js +263 -0
  20. package/dist/esm/runtime/index.js +2 -10
  21. package/dist/esm/ssr-runtime/index.js +1 -0
  22. package/dist/esm/ssr-runtime/{devPlugin.js → plugin.js} +2 -5
  23. package/dist/esm-node/cli/configPlugin.js +7 -9
  24. package/dist/esm-node/cli/configPlugin.spec.js +1 -3
  25. package/dist/esm-node/cli/constant.js +4 -0
  26. package/dist/esm-node/{logger.js → cli/logger.js} +1 -1
  27. package/dist/esm-node/cli/ssrPlugin.js +7 -23
  28. package/dist/esm-node/cli/utils.js +0 -4
  29. package/dist/esm-node/constant.js +1 -37
  30. package/dist/esm-node/runtime/createRemoteSSRComponent.js +175 -0
  31. package/dist/esm-node/runtime/index.js +2 -10
  32. package/dist/esm-node/ssr-runtime/index.js +1 -0
  33. package/dist/esm-node/ssr-runtime/{devPlugin.js → plugin.js} +2 -5
  34. package/dist/types/cli/constant.d.ts +1 -0
  35. package/dist/types/cli/index.d.ts +0 -1
  36. package/dist/types/cli/utils.d.ts +0 -1
  37. package/dist/types/constant.d.ts +0 -23
  38. package/dist/types/runtime/createRemoteSSRComponent.d.ts +19 -0
  39. package/dist/types/runtime/index.d.ts +2 -6
  40. package/dist/types/ssr-runtime/index.d.ts +1 -0
  41. package/dist/types/ssr-runtime/plugin.d.ts +2 -0
  42. package/package.json +17 -41
  43. package/dist/cjs/cli/mfRuntimePlugins/auto-fetch-data.js +0 -98
  44. package/dist/cjs/cli/server/data-fetch-server-plugin.js +0 -192
  45. package/dist/cjs/runtime/AwaitDataFetch.js +0 -144
  46. package/dist/cjs/runtime/createRemoteComponent.js +0 -327
  47. package/dist/cjs/ssr-runtime/downgrade.js +0 -108
  48. package/dist/cjs/ssr-runtime/injectDataFetchFunctionPlugin.js +0 -128
  49. package/dist/cjs/utils/dataFetch.js +0 -211
  50. package/dist/cjs/utils/index.js +0 -54
  51. package/dist/esm/cli/mfRuntimePlugins/auto-fetch-data.js +0 -74
  52. package/dist/esm/cli/server/data-fetch-server-plugin.js +0 -240
  53. package/dist/esm/interfaces/global.js +0 -0
  54. package/dist/esm/runtime/AwaitDataFetch.js +0 -131
  55. package/dist/esm/runtime/createRemoteComponent.js +0 -417
  56. package/dist/esm/runtime/wrapNoSSR.js +0 -12
  57. package/dist/esm/ssr-runtime/downgrade.js +0 -143
  58. package/dist/esm/ssr-runtime/injectDataFetchFunctionPlugin.js +0 -168
  59. package/dist/esm/utils/dataFetch.js +0 -237
  60. package/dist/esm/utils/index.js +0 -28
  61. package/dist/esm-node/cli/mfRuntimePlugins/auto-fetch-data.js +0 -68
  62. package/dist/esm-node/cli/server/data-fetch-server-plugin.js +0 -162
  63. package/dist/esm-node/interfaces/global.js +0 -0
  64. package/dist/esm-node/runtime/AwaitDataFetch.js +0 -109
  65. package/dist/esm-node/runtime/createRemoteComponent.js +0 -291
  66. package/dist/esm-node/runtime/wrapNoSSR.js +0 -11
  67. package/dist/esm-node/ssr-runtime/downgrade.js +0 -82
  68. package/dist/esm-node/ssr-runtime/injectDataFetchFunctionPlugin.js +0 -94
  69. package/dist/esm-node/utils/dataFetch.js +0 -166
  70. package/dist/esm-node/utils/index.js +0 -27
  71. package/dist/types/cli/mfRuntimePlugins/auto-fetch-data.d.ts +0 -3
  72. package/dist/types/cli/server/data-fetch-server-plugin.d.ts +0 -3
  73. package/dist/types/interfaces/global.d.ts +0 -27
  74. package/dist/types/runtime/AwaitDataFetch.d.ts +0 -19
  75. package/dist/types/runtime/createRemoteComponent.d.ts +0 -26
  76. package/dist/types/runtime/wrapNoSSR.d.ts +0 -9
  77. package/dist/types/ssr-runtime/devPlugin.d.ts +0 -2
  78. package/dist/types/ssr-runtime/downgrade.d.ts +0 -4
  79. package/dist/types/ssr-runtime/injectDataFetchFunctionPlugin.d.ts +0 -2
  80. package/dist/types/utils/dataFetch.d.ts +0 -26
  81. package/dist/types/utils/index.d.ts +0 -15
  82. /package/dist/types/{logger.d.ts → cli/logger.d.ts} +0 -0
@@ -45,9 +45,9 @@ var import_sdk = require("@module-federation/sdk");
45
45
  var import_node_bundle_require = require("@modern-js/node-bundle-require");
46
46
  var import_constant = require("../constant");
47
47
  var import_utils2 = require("@module-federation/rsbuild-plugin/utils");
48
- var import_logger = __toESM(require("../logger"));
49
- var import_utils3 = require("./utils");
48
+ var import_logger = __toESM(require("./logger"));
50
49
  const defaultPath = import_path.default.resolve(process.cwd(), "module-federation.config.ts");
50
+ const isDev = process.env.NODE_ENV === "development";
51
51
  function setEnv(enableSSR) {
52
52
  if (enableSSR) {
53
53
  process.env["MF_DISABLE_EMIT_STATS"] = "true";
@@ -136,7 +136,6 @@ const patchDTSConfig = (mfConfig, isServer) => {
136
136
  };
137
137
  const patchMFConfig = (mfConfig, isServer, remoteIpStrategy) => {
138
138
  replaceRemoteUrl(mfConfig, remoteIpStrategy);
139
- (0, import_utils2.addDataFetchExposes)(mfConfig.exposes, isServer);
140
139
  if (mfConfig.remoteType === void 0) {
141
140
  mfConfig.remoteType = "script";
142
141
  }
@@ -148,13 +147,12 @@ const patchMFConfig = (mfConfig, isServer, remoteIpStrategy) => {
148
147
  ];
149
148
  patchDTSConfig(mfConfig, isServer);
150
149
  injectRuntimePlugins(require.resolve("@module-federation/modern-js/shared-strategy"), runtimePlugins);
151
- injectRuntimePlugins(require.resolve("@module-federation/modern-js/auto-fetch-data"), runtimePlugins);
152
- if ((0, import_utils3.isDev)()) {
150
+ if (isDev) {
153
151
  injectRuntimePlugins(require.resolve("@module-federation/modern-js/resolve-entry-ipv4"), runtimePlugins);
154
152
  }
155
153
  if (isServer) {
156
154
  injectRuntimePlugins(require.resolve("@module-federation/node/runtimePlugin"), runtimePlugins);
157
- if ((0, import_utils3.isDev)()) {
155
+ if (isDev) {
158
156
  injectRuntimePlugins(require.resolve("@module-federation/node/record-dynamic-remote-entry-hash-plugin"), runtimePlugins);
159
157
  }
160
158
  injectRuntimePlugins(require.resolve("@module-federation/modern-js/inject-node-fetch"), runtimePlugins);
@@ -254,7 +252,7 @@ function patchBundlerConfig(options) {
254
252
  splitChunkConfig.chunks = "async";
255
253
  import_logger.default.warn(`splitChunks.chunks = async is not allowed with stream SSR mode, it will auto changed to "async"`);
256
254
  }
257
- if ((0, import_utils3.isDev)() && chain.output.get("publicPath") === "auto") {
255
+ if (isDev && chain.output.get("publicPath") === "auto") {
258
256
  var _modernjsConfig_dev, _modernjsConfig_server;
259
257
  const port = ((_modernjsConfig_dev = modernjsConfig.dev) === null || _modernjsConfig_dev === void 0 ? void 0 : _modernjsConfig_dev.port) || ((_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.port) || 8080;
260
258
  const publicPath = `http://localhost:${port}/`;
@@ -268,7 +266,7 @@ function patchBundlerConfig(options) {
268
266
  chain.output.chunkFilename(chunkFileName.replace(".js", suffix));
269
267
  }
270
268
  }
271
- if ((0, import_utils3.isDev)() && enableSSR && !isServer) {
269
+ if (isDev && enableSSR && !isServer) {
272
270
  chain.resolve.fallback.set("crypto", false).set("stream", false).set("vm", false);
273
271
  }
274
272
  if (((_modernjsConfig_deploy = modernjsConfig.deploy) === null || _modernjsConfig_deploy === void 0 ? void 0 : _modernjsConfig_deploy.microFrontend) && Object.keys(mfConfig.exposes || {}).length) {
@@ -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: {
@@ -16,20 +16,13 @@ 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 constant_exports = {};
20
+ __export(constant_exports, {
21
+ isDev: () => isDev
22
22
  });
23
- module.exports = __toCommonJS(wrapNoSSR_exports);
24
- function wrapNoSSR(createComponentFn) {
25
- return (options) => {
26
- return createComponentFn({
27
- ...options,
28
- noSSR: true
29
- });
30
- };
31
- }
23
+ module.exports = __toCommonJS(constant_exports);
24
+ const isDev = process.env.NODE_ENV === "development";
32
25
  // Annotate the CommonJS export names for ESM import in node:
33
26
  0 && (module.exports = {
34
- wrapNoSSR
27
+ isDev
35
28
  });
@@ -22,6 +22,6 @@ __export(logger_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(logger_exports);
24
24
  var import_sdk = require("@module-federation/sdk");
25
- var import_constant = require("./constant");
25
+ var import_constant = require("../constant");
26
26
  const logger = (0, import_sdk.createLogger)(import_constant.PLUGIN_IDENTIFIER);
27
27
  var logger_default = logger;
@@ -40,9 +40,9 @@ var import_webpack = require("@module-federation/enhanced/webpack");
40
40
  var import_rspack = require("@module-federation/enhanced/rspack");
41
41
  var import_universe_entry_chunk_tracker_plugin = __toESM(require("@module-federation/node/universe-entry-chunk-tracker-plugin"));
42
42
  var import_manifest = require("./manifest");
43
- var import_logger = __toESM(require("../logger"));
43
+ var import_constant = require("./constant");
44
+ var import_logger = __toESM(require("./logger"));
44
45
  var import_utils2 = require("./utils");
45
- var import_utils3 = require("./utils");
46
46
  function setEnv() {
47
47
  process.env["MF_DISABLE_EMIT_STATS"] = "true";
48
48
  process.env["MF_SSR_PRJ"] = "true";
@@ -63,10 +63,10 @@ const mfSSRRsbuildPlugin = (pluginOptions) => {
63
63
  let ssrEnv = "";
64
64
  api.modifyEnvironmentConfig((config, { name }) => {
65
65
  const target = config.output.target;
66
- if ((0, import_utils3.skipByTarget)(target)) {
66
+ if ((0, import_utils2.skipByTarget)(target)) {
67
67
  return config;
68
68
  }
69
- if ((0, import_utils3.isWebTarget)(target)) {
69
+ if ((0, import_utils2.isWebTarget)(target)) {
70
70
  csrOutputPath = config.output.distPath.root;
71
71
  } else {
72
72
  ssrOutputPath = config.output.distPath.root;
@@ -112,20 +112,15 @@ const moduleFederationSSRPlugin = (pluginOptions) => ({
112
112
  }
113
113
  setEnv();
114
114
  api._internalRuntimePlugins(({ entrypoint, plugins }) => {
115
- plugins.push({
116
- name: "injectDataFetchFunction",
117
- path: "@module-federation/modern-js/ssr-inject-data-fetch-function-plugin",
118
- config: {}
119
- });
120
- if (!(0, import_utils2.isDev)()) {
115
+ if (!import_constant.isDev) {
121
116
  return {
122
117
  entrypoint,
123
118
  plugins
124
119
  };
125
120
  }
126
121
  plugins.push({
127
- name: "mfSSRDev",
128
- path: "@module-federation/modern-js/ssr-dev-plugin",
122
+ name: "mfSSR",
123
+ path: "@module-federation/modern-js/ssr-runtime",
129
124
  config: {}
130
125
  });
131
126
  return {
@@ -133,25 +128,14 @@ const moduleFederationSSRPlugin = (pluginOptions) => ({
133
128
  plugins
134
129
  };
135
130
  });
136
- if (pluginOptions.ssrConfig.remotes) {
137
- api._internalServerPlugins(({ plugins }) => {
138
- plugins.push({
139
- name: "@module-federation/modern-js/data-fetch-server-plugin",
140
- options: {}
141
- });
142
- return {
143
- plugins
144
- };
145
- });
146
- }
147
131
  api.modifyBundlerChain((chain) => {
148
132
  const target = chain.get("target");
149
- if ((0, import_utils3.skipByTarget)(target)) {
133
+ if ((0, import_utils2.skipByTarget)(target)) {
150
134
  return;
151
135
  }
152
136
  const bundlerType = api.getAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
153
137
  const MFPlugin = bundlerType === "webpack" ? import_webpack.ModuleFederationPlugin : import_rspack.ModuleFederationPlugin;
154
- const isWeb = (0, import_utils3.isWebTarget)(target);
138
+ const isWeb = (0, import_utils2.isWebTarget)(target);
155
139
  if (!isWeb) {
156
140
  if (!chain.plugins.has(CHAIN_MF_PLUGIN_ID)) {
157
141
  chain.plugin(CHAIN_MF_PLUGIN_ID).use(MFPlugin, [
@@ -164,7 +148,7 @@ const moduleFederationSSRPlugin = (pluginOptions) => ({
164
148
  }
165
149
  if (!isWeb) {
166
150
  chain.target("async-node");
167
- if ((0, import_utils2.isDev)()) {
151
+ if (import_constant.isDev) {
168
152
  chain.plugin("UniverseEntryChunkTrackerPlugin").use(import_universe_entry_chunk_tracker_plugin.default);
169
153
  }
170
154
  const userSSRConfig = pluginOptions.userConfig.ssr ? typeof pluginOptions.userConfig.ssr === "object" ? pluginOptions.userConfig.ssr : {} : {};
@@ -173,7 +157,7 @@ const moduleFederationSSRPlugin = (pluginOptions) => ({
173
157
  chain.output.publicPath(`${publicPath}${userSSRConfig.distOutputDir}/`);
174
158
  }
175
159
  }
176
- if ((0, import_utils2.isDev)() && isWeb) {
160
+ if (import_constant.isDev && isWeb) {
177
161
  chain.externals({
178
162
  "@module-federation/node/utils": "NOT_USED_IN_BROWSER"
179
163
  });
@@ -29,7 +29,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
29
29
  var utils_exports = {};
30
30
  __export(utils_exports, {
31
31
  getIPV4: () => getIPV4,
32
- isDev: () => isDev,
33
32
  isWebTarget: () => isWebTarget,
34
33
  skipByTarget: () => skipByTarget
35
34
  });
@@ -78,13 +77,9 @@ const skipByTarget = (target) => {
78
77
  }
79
78
  return false;
80
79
  };
81
- function isDev() {
82
- return process.env.NODE_ENV === "development";
83
- }
84
80
  // Annotate the CommonJS export names for ESM import in node:
85
81
  0 && (module.exports = {
86
82
  getIPV4,
87
- isDev,
88
83
  isWebTarget,
89
84
  skipByTarget
90
85
  });
@@ -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
  });
@@ -0,0 +1,210 @@
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 createRemoteSSRComponent_exports = {};
30
+ __export(createRemoteSSRComponent_exports, {
31
+ collectSSRAssets: () => collectSSRAssets,
32
+ createRemoteSSRComponent: () => createRemoteSSRComponent
33
+ });
34
+ module.exports = __toCommonJS(createRemoteSSRComponent_exports);
35
+ var import_jsx_runtime = require("react/jsx-runtime");
36
+ var import_react = __toESM(require("react"));
37
+ var import_runtime = require("@module-federation/enhanced/runtime");
38
+ var import_react_error_boundary = require("react-error-boundary");
39
+ function getLoadedRemoteInfos(instance, id) {
40
+ const { name, expose } = instance.remoteHandler.idToRemoteMap[id] || {};
41
+ if (!name) {
42
+ return;
43
+ }
44
+ const module2 = instance.moduleCache.get(name);
45
+ if (!module2) {
46
+ return;
47
+ }
48
+ const { remoteSnapshot } = instance.snapshotHandler.getGlobalRemoteInfo(module2.remoteInfo);
49
+ return {
50
+ ...module2.remoteInfo,
51
+ snapshot: remoteSnapshot,
52
+ expose
53
+ };
54
+ }
55
+ function getTargetModuleInfo(id) {
56
+ const instance = (0, import_runtime.getInstance)();
57
+ if (!instance) {
58
+ return;
59
+ }
60
+ const loadedRemoteInfo = getLoadedRemoteInfos(instance, id);
61
+ if (!loadedRemoteInfo) {
62
+ return;
63
+ }
64
+ const snapshot = loadedRemoteInfo.snapshot;
65
+ if (!snapshot) {
66
+ return;
67
+ }
68
+ const publicPath = "publicPath" in snapshot ? snapshot.publicPath : "getPublicPath" in snapshot ? new Function(snapshot.getPublicPath)() : "";
69
+ if (!publicPath) {
70
+ return;
71
+ }
72
+ const modules = "modules" in snapshot ? snapshot.modules : [];
73
+ const targetModule = modules.find((m) => m.modulePath === loadedRemoteInfo.expose);
74
+ if (!targetModule) {
75
+ return;
76
+ }
77
+ const remoteEntry = "remoteEntry" in snapshot ? snapshot.remoteEntry : "";
78
+ if (!remoteEntry) {
79
+ return;
80
+ }
81
+ return {
82
+ module: targetModule,
83
+ publicPath,
84
+ remoteEntry
85
+ };
86
+ }
87
+ async function collectSSRAssets(options) {
88
+ const { id, injectLink = true, injectScript = true, inlineCSS = false } = typeof options === "string" ? {
89
+ id: options
90
+ } : options;
91
+ const links = [];
92
+ const scripts = [];
93
+ const instance = (0, import_runtime.getInstance)();
94
+ if (!instance || !injectLink && !injectScript) {
95
+ return [
96
+ ...scripts,
97
+ ...links
98
+ ];
99
+ }
100
+ const moduleAndPublicPath = getTargetModuleInfo(id);
101
+ if (!moduleAndPublicPath) {
102
+ return [
103
+ ...scripts,
104
+ ...links
105
+ ];
106
+ }
107
+ const { module: targetModule, publicPath, remoteEntry } = moduleAndPublicPath;
108
+ if (injectLink) {
109
+ await Promise.all([
110
+ ...targetModule.assets.css.sync,
111
+ ...targetModule.assets.css.async
112
+ ].map(async (file, index) => {
113
+ const href = `${publicPath}${file}`;
114
+ const key = `${file.split(".")[0]}_${index}`;
115
+ if (inlineCSS) {
116
+ const content = await fetch(href).then((res) => res.text());
117
+ links.push(/* @__PURE__ */ (0, import_jsx_runtime.jsx)("style", {
118
+ children: content
119
+ }, key));
120
+ return;
121
+ }
122
+ links.push(/* @__PURE__ */ (0, import_jsx_runtime.jsx)("link", {
123
+ href: `${publicPath}${file}`,
124
+ rel: "stylesheet",
125
+ type: "text/css"
126
+ }, key));
127
+ }));
128
+ }
129
+ if (injectScript) {
130
+ scripts.push(/* @__PURE__ */ (0, import_jsx_runtime.jsx)("script", {
131
+ async: true,
132
+ src: `${publicPath}${remoteEntry}`,
133
+ crossOrigin: "anonymous"
134
+ }, remoteEntry.split(".")[0]));
135
+ [
136
+ ...targetModule.assets.js.sync
137
+ ].forEach((file, index) => {
138
+ scripts.push(/* @__PURE__ */ (0, import_jsx_runtime.jsx)("script", {
139
+ async: true,
140
+ src: `${publicPath}${file}`,
141
+ crossOrigin: "anonymous"
142
+ }, `${file.split(".")[0]}_${index}`));
143
+ });
144
+ }
145
+ return [
146
+ ...scripts,
147
+ ...links
148
+ ];
149
+ }
150
+ function createRemoteSSRComponent(info) {
151
+ const exportName = (info === null || info === void 0 ? void 0 : info.export) || "default";
152
+ const LazyComponent = /* @__PURE__ */ import_react.default.lazy(async () => {
153
+ try {
154
+ const m = await info.loader();
155
+ if (!m) {
156
+ throw new Error("load remote failed");
157
+ }
158
+ const moduleId = m && m[Symbol.for("mf_module_id")];
159
+ const assets = await collectSSRAssets({
160
+ id: moduleId
161
+ });
162
+ const Com = m[exportName];
163
+ if (exportName in m && typeof Com === "function") {
164
+ return {
165
+ default: (props) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
166
+ children: [
167
+ assets,
168
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Com, {
169
+ ...props
170
+ })
171
+ ]
172
+ })
173
+ };
174
+ } else {
175
+ throw Error(`Make sure that ${moduleId} has the correct export when export is ${String(exportName)}`);
176
+ }
177
+ } catch (err) {
178
+ if (!info.fallback) {
179
+ throw err;
180
+ }
181
+ const FallbackFunctionComponent = info.fallback;
182
+ const FallbackNode = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FallbackFunctionComponent, {
183
+ error: err,
184
+ resetErrorBoundary: () => {
185
+ console.log('SSR mode not support "resetErrorBoundary" !');
186
+ }
187
+ });
188
+ return {
189
+ default: () => FallbackNode
190
+ };
191
+ }
192
+ });
193
+ return (props) => {
194
+ const { key, ...args } = props;
195
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_error_boundary.ErrorBoundary, {
196
+ FallbackComponent: info.fallback,
197
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.default.Suspense, {
198
+ fallback: info.loading,
199
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LazyComponent, {
200
+ ...args
201
+ })
202
+ })
203
+ });
204
+ };
205
+ }
206
+ // Annotate the CommonJS export names for ESM import in node:
207
+ 0 && (module.exports = {
208
+ collectSSRAssets,
209
+ createRemoteSSRComponent
210
+ });
@@ -19,29 +19,20 @@ 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: () => import_constant.ERROR_TYPE,
23
22
  kit: () => kit
24
23
  });
25
24
  module.exports = __toCommonJS(runtime_exports);
26
25
  __reExport(runtime_exports, require("@module-federation/enhanced/runtime"), module.exports);
27
- var import_constant = require("../constant");
28
26
  const kit = {
29
27
  get createRemoteSSRComponent() {
30
- return require("./createRemoteComponent").createRemoteSSRComponent;
31
- },
32
- get createRemoteComponent() {
33
- return require("./createRemoteComponent").createRemoteComponent;
28
+ return require("./createRemoteSSRComponent").createRemoteSSRComponent;
34
29
  },
35
30
  get collectSSRAssets() {
36
- return require("./createRemoteComponent").collectSSRAssets;
37
- },
38
- get wrapNoSSR() {
39
- return require("./wrapNoSSR").wrapNoSSR;
31
+ return require("./createRemoteSSRComponent").collectSSRAssets;
40
32
  }
41
33
  };
42
34
  // Annotate the CommonJS export names for ESM import in node:
43
35
  0 && (module.exports = {
44
- ERROR_TYPE,
45
36
  kit,
46
37
  ...require("@module-federation/enhanced/runtime")
47
38
  });
@@ -11,6 +11,12 @@ var __copyProps = (to, from, except, desc) => {
11
11
  }
12
12
  return to;
13
13
  };
14
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
14
15
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
- var global_exports = {};
16
- module.exports = __toCommonJS(global_exports);
16
+ var ssr_runtime_exports = {};
17
+ module.exports = __toCommonJS(ssr_runtime_exports);
18
+ __reExport(ssr_runtime_exports, require("./plugin"), module.exports);
19
+ // Annotate the CommonJS export names for ESM import in node:
20
+ 0 && (module.exports = {
21
+ ...require("./plugin")
22
+ });
@@ -26,15 +26,14 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  mod
27
27
  ));
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var devPlugin_exports = {};
30
- __export(devPlugin_exports, {
31
- mfSSRDevPlugin: () => mfSSRDevPlugin
29
+ var plugin_exports = {};
30
+ __export(plugin_exports, {
31
+ mfSSRPlugin: () => mfSSRPlugin
32
32
  });
33
- module.exports = __toCommonJS(devPlugin_exports);
33
+ module.exports = __toCommonJS(plugin_exports);
34
34
  var import_jsx_runtime = require("react/jsx-runtime");
35
35
  var import_SSRLiveReload = require("./SSRLiveReload");
36
- var import_utils = require("../utils");
37
- const mfSSRDevPlugin = () => ({
36
+ const mfSSRPlugin = () => ({
38
37
  name: "@module-federation/modern-js",
39
38
  setup: (api) => {
40
39
  api.onBeforeRender(async () => {
@@ -44,11 +43,9 @@ const mfSSRDevPlugin = () => ({
44
43
  globalThis.shouldUpdate = false;
45
44
  const nodeUtils = await Promise.resolve().then(() => __toESM(require("@module-federation/node/utils")));
46
45
  const shouldUpdate = await nodeUtils.revalidate();
47
- console.log("shouldUpdate: ", shouldUpdate);
48
46
  if (shouldUpdate) {
49
47
  console.log("should RELOAD", shouldUpdate);
50
48
  await nodeUtils.flushChunks();
51
- (0, import_utils.flushDataFetch)();
52
49
  globalThis.shouldUpdate = true;
53
50
  }
54
51
  });
@@ -67,5 +64,5 @@ const mfSSRDevPlugin = () => ({
67
64
  });
68
65
  // Annotate the CommonJS export names for ESM import in node:
69
66
  0 && (module.exports = {
70
- mfSSRDevPlugin
67
+ mfSSRPlugin
71
68
  });
@@ -9,10 +9,10 @@ import { getIPV4, isWebTarget, skipByTarget } from "./utils";
9
9
  import { encodeName } from "@module-federation/sdk";
10
10
  import { bundle } from "@modern-js/node-bundle-require";
11
11
  import { LOCALHOST, PLUGIN_IDENTIFIER } from "../constant";
12
- import { autoDeleteSplitChunkCacheGroups, addDataFetchExposes } from "@module-federation/rsbuild-plugin/utils";
13
- import logger from "../logger";
14
- import { isDev } from "./utils";
12
+ import { autoDeleteSplitChunkCacheGroups } from "@module-federation/rsbuild-plugin/utils";
13
+ import logger from "./logger";
15
14
  var defaultPath = path.resolve(process.cwd(), "module-federation.config.ts");
15
+ var isDev = process.env.NODE_ENV === "development";
16
16
  function setEnv(enableSSR) {
17
17
  if (enableSSR) {
18
18
  process.env["MF_DISABLE_EMIT_STATS"] = "true";
@@ -128,7 +128,6 @@ var patchDTSConfig = function(mfConfig, isServer) {
128
128
  };
129
129
  var patchMFConfig = function(mfConfig, isServer, remoteIpStrategy) {
130
130
  replaceRemoteUrl(mfConfig, remoteIpStrategy);
131
- addDataFetchExposes(mfConfig.exposes, isServer);
132
131
  if (mfConfig.remoteType === void 0) {
133
132
  mfConfig.remoteType = "script";
134
133
  }
@@ -138,13 +137,12 @@ var patchMFConfig = function(mfConfig, isServer, remoteIpStrategy) {
138
137
  var runtimePlugins = _to_consumable_array(mfConfig.runtimePlugins || []);
139
138
  patchDTSConfig(mfConfig, isServer);
140
139
  injectRuntimePlugins(require.resolve("@module-federation/modern-js/shared-strategy"), runtimePlugins);
141
- injectRuntimePlugins(require.resolve("@module-federation/modern-js/auto-fetch-data"), runtimePlugins);
142
- if (isDev()) {
140
+ if (isDev) {
143
141
  injectRuntimePlugins(require.resolve("@module-federation/modern-js/resolve-entry-ipv4"), runtimePlugins);
144
142
  }
145
143
  if (isServer) {
146
144
  injectRuntimePlugins(require.resolve("@module-federation/node/runtimePlugin"), runtimePlugins);
147
- if (isDev()) {
145
+ if (isDev) {
148
146
  injectRuntimePlugins(require.resolve("@module-federation/node/record-dynamic-remote-entry-hash-plugin"), runtimePlugins);
149
147
  }
150
148
  injectRuntimePlugins(require.resolve("@module-federation/modern-js/inject-node-fetch"), runtimePlugins);
@@ -242,7 +240,7 @@ function patchBundlerConfig(options) {
242
240
  splitChunkConfig.chunks = "async";
243
241
  logger.warn('splitChunks.chunks = async is not allowed with stream SSR mode, it will auto changed to "async"');
244
242
  }
245
- if (isDev() && chain.output.get("publicPath") === "auto") {
243
+ if (isDev && chain.output.get("publicPath") === "auto") {
246
244
  var _modernjsConfig_dev, _modernjsConfig_server;
247
245
  var port = ((_modernjsConfig_dev = modernjsConfig.dev) === null || _modernjsConfig_dev === void 0 ? void 0 : _modernjsConfig_dev.port) || ((_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.port) || 8080;
248
246
  var publicPath = "http://localhost:".concat(port, "/");
@@ -256,7 +254,7 @@ function patchBundlerConfig(options) {
256
254
  chain.output.chunkFilename(chunkFileName.replace(".js", suffix));
257
255
  }
258
256
  }
259
- if (isDev() && enableSSR && !isServer) {
257
+ if (isDev && enableSSR && !isServer) {
260
258
  chain.resolve.fallback.set("crypto", false).set("stream", false).set("vm", false);
261
259
  }
262
260
  if (((_modernjsConfig_deploy = modernjsConfig.deploy) === null || _modernjsConfig_deploy === void 0 ? void 0 : _modernjsConfig_deploy.microFrontend) && Object.keys(mfConfig.exposes || {}).length) {
@@ -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: {
@@ -0,0 +1,4 @@
1
+ var isDev = process.env.NODE_ENV === "development";
2
+ export {
3
+ isDev
4
+ };