@module-federation/modern-js 0.0.0-next-20250526074234 → 0.0.0-next-20250527094526

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 (109) 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/cli/index.js +9 -3
  5. package/dist/cjs/{logger.js → cli/logger.js} +1 -1
  6. package/dist/cjs/cli/manifest.js +3 -3
  7. package/dist/cjs/cli/ssrPlugin.js +15 -34
  8. package/dist/cjs/cli/utils.js +0 -5
  9. package/dist/cjs/constant.js +2 -49
  10. package/dist/cjs/runtime/createRemoteSSRComponent.js +201 -0
  11. package/dist/cjs/runtime/index.js +3 -15
  12. package/dist/cjs/server/fileCache.js +84 -0
  13. package/dist/cjs/server/fileCache.spec.js +28 -0
  14. package/dist/cjs/server/index.js +58 -0
  15. package/dist/cjs/server/staticMiddleware.js +77 -0
  16. package/dist/cjs/server/staticMiddleware.spec.js +185 -0
  17. package/dist/cjs/{interfaces/global.js → ssr-runtime/index.js} +8 -2
  18. package/dist/cjs/ssr-runtime/{devPlugin.js → plugin.js} +6 -9
  19. package/dist/esm/cli/configPlugin.js +7 -9
  20. package/dist/esm/cli/configPlugin.spec.js +1 -3
  21. package/dist/esm/cli/constant.js +4 -0
  22. package/dist/esm/cli/index.js +10 -3
  23. package/dist/esm/{logger.js → cli/logger.js} +1 -1
  24. package/dist/esm/cli/manifest.js +1 -1
  25. package/dist/esm/cli/ssrPlugin.js +8 -28
  26. package/dist/esm/cli/utils.js +0 -4
  27. package/dist/esm/constant.js +1 -37
  28. package/dist/esm/runtime/createRemoteSSRComponent.js +191 -0
  29. package/dist/esm/runtime/index.js +3 -13
  30. package/dist/esm/server/fileCache.js +98 -0
  31. package/dist/esm/server/fileCache.spec.js +50 -0
  32. package/dist/esm/server/index.js +36 -0
  33. package/dist/esm/server/staticMiddleware.js +81 -0
  34. package/dist/esm/server/staticMiddleware.spec.js +328 -0
  35. package/dist/esm/ssr-runtime/index.js +1 -0
  36. package/dist/esm/ssr-runtime/{devPlugin.js → plugin.js} +2 -5
  37. package/dist/esm-node/cli/configPlugin.js +7 -9
  38. package/dist/esm-node/cli/configPlugin.spec.js +1 -3
  39. package/dist/esm-node/cli/constant.js +4 -0
  40. package/dist/esm-node/cli/index.js +9 -3
  41. package/dist/esm-node/{logger.js → cli/logger.js} +1 -1
  42. package/dist/esm-node/cli/manifest.js +1 -1
  43. package/dist/esm-node/cli/ssrPlugin.js +8 -27
  44. package/dist/esm-node/cli/utils.js +0 -4
  45. package/dist/esm-node/constant.js +1 -37
  46. package/dist/esm-node/runtime/createRemoteSSRComponent.js +166 -0
  47. package/dist/esm-node/runtime/index.js +3 -13
  48. package/dist/esm-node/server/fileCache.js +49 -0
  49. package/dist/esm-node/server/fileCache.spec.js +27 -0
  50. package/dist/esm-node/server/index.js +34 -0
  51. package/dist/esm-node/server/staticMiddleware.js +43 -0
  52. package/dist/esm-node/server/staticMiddleware.spec.js +162 -0
  53. package/dist/esm-node/ssr-runtime/index.js +1 -0
  54. package/dist/esm-node/ssr-runtime/{devPlugin.js → plugin.js} +2 -5
  55. package/dist/types/cli/constant.d.ts +1 -0
  56. package/dist/types/cli/index.d.ts +0 -1
  57. package/dist/types/cli/utils.d.ts +0 -1
  58. package/dist/types/constant.d.ts +0 -23
  59. package/dist/types/runtime/createRemoteSSRComponent.d.ts +18 -0
  60. package/dist/types/runtime/index.d.ts +2 -7
  61. package/dist/types/server/fileCache.d.ts +14 -0
  62. package/dist/types/server/fileCache.spec.d.ts +1 -0
  63. package/dist/types/server/index.d.ts +4 -0
  64. package/dist/types/server/staticMiddleware.d.ts +6 -0
  65. package/dist/types/server/staticMiddleware.spec.d.ts +1 -0
  66. package/dist/types/ssr-runtime/index.d.ts +1 -0
  67. package/dist/types/ssr-runtime/plugin.d.ts +2 -0
  68. package/dist/types/types/index.d.ts +0 -2
  69. package/package.json +23 -39
  70. package/dist/cjs/cli/mfRuntimePlugins/auto-fetch-data.js +0 -98
  71. package/dist/cjs/cli/server/data-fetch-server-plugin.js +0 -192
  72. package/dist/cjs/runtime/AwaitDataFetch.js +0 -144
  73. package/dist/cjs/runtime/createRemoteComponent.js +0 -327
  74. package/dist/cjs/ssr-runtime/downgrade.js +0 -114
  75. package/dist/cjs/ssr-runtime/injectDataFetchFunctionPlugin.js +0 -136
  76. package/dist/cjs/utils/dataFetch.js +0 -211
  77. package/dist/cjs/utils/index.js +0 -54
  78. package/dist/esm/cli/mfRuntimePlugins/auto-fetch-data.js +0 -74
  79. package/dist/esm/cli/server/data-fetch-server-plugin.js +0 -240
  80. package/dist/esm/interfaces/global.js +0 -0
  81. package/dist/esm/runtime/AwaitDataFetch.js +0 -131
  82. package/dist/esm/runtime/createRemoteComponent.js +0 -417
  83. package/dist/esm/runtime/wrapNoSSR.js +0 -12
  84. package/dist/esm/ssr-runtime/downgrade.js +0 -150
  85. package/dist/esm/ssr-runtime/injectDataFetchFunctionPlugin.js +0 -177
  86. package/dist/esm/utils/dataFetch.js +0 -237
  87. package/dist/esm/utils/index.js +0 -28
  88. package/dist/esm-node/cli/mfRuntimePlugins/auto-fetch-data.js +0 -68
  89. package/dist/esm-node/cli/server/data-fetch-server-plugin.js +0 -162
  90. package/dist/esm-node/interfaces/global.js +0 -0
  91. package/dist/esm-node/runtime/AwaitDataFetch.js +0 -109
  92. package/dist/esm-node/runtime/createRemoteComponent.js +0 -291
  93. package/dist/esm-node/runtime/wrapNoSSR.js +0 -11
  94. package/dist/esm-node/ssr-runtime/downgrade.js +0 -88
  95. package/dist/esm-node/ssr-runtime/injectDataFetchFunctionPlugin.js +0 -101
  96. package/dist/esm-node/utils/dataFetch.js +0 -166
  97. package/dist/esm-node/utils/index.js +0 -27
  98. package/dist/types/cli/mfRuntimePlugins/auto-fetch-data.d.ts +0 -3
  99. package/dist/types/cli/server/data-fetch-server-plugin.d.ts +0 -3
  100. package/dist/types/interfaces/global.d.ts +0 -27
  101. package/dist/types/runtime/AwaitDataFetch.d.ts +0 -19
  102. package/dist/types/runtime/createRemoteComponent.d.ts +0 -26
  103. package/dist/types/runtime/wrapNoSSR.d.ts +0 -9
  104. package/dist/types/ssr-runtime/devPlugin.d.ts +0 -2
  105. package/dist/types/ssr-runtime/downgrade.d.ts +0 -4
  106. package/dist/types/ssr-runtime/injectDataFetchFunctionPlugin.d.ts +0 -7
  107. package/dist/types/utils/dataFetch.d.ts +0 -26
  108. package/dist/types/utils/index.d.ts +0 -15
  109. /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
  });
@@ -30,7 +30,6 @@ var import_ssrPlugin = require("./ssrPlugin");
30
30
  var import_utils = require("./utils");
31
31
  var import_enhanced2 = require("@module-federation/enhanced");
32
32
  const moduleFederationPlugin = (userConfig = {}) => {
33
- var _userConfig_fetchServerQuery;
34
33
  const internalModernPluginOptions = {
35
34
  csrConfig: void 0,
36
35
  ssrConfig: void 0,
@@ -39,8 +38,7 @@ const moduleFederationPlugin = (userConfig = {}) => {
39
38
  distOutputDir: "",
40
39
  originPluginOptions: userConfig,
41
40
  remoteIpStrategy: userConfig === null || userConfig === void 0 ? void 0 : userConfig.remoteIpStrategy,
42
- userConfig: userConfig || {},
43
- fetchServerQuery: (_userConfig_fetchServerQuery = userConfig.fetchServerQuery) !== null && _userConfig_fetchServerQuery !== void 0 ? _userConfig_fetchServerQuery : void 0
41
+ userConfig: userConfig || {}
44
42
  };
45
43
  return {
46
44
  name: "@modern-js/plugin-module-federation",
@@ -72,6 +70,14 @@ const moduleFederationPlugin = (userConfig = {}) => {
72
70
  }
73
71
  }
74
72
  });
73
+ api._internalServerPlugins(({ plugins }) => {
74
+ plugins.push({
75
+ name: "@module-federation/modern-js/server"
76
+ });
77
+ return {
78
+ plugins
79
+ };
80
+ });
75
81
  },
76
82
  usePlugins: [
77
83
  (0, import_configPlugin.moduleFederationConfigPlugin)(internalModernPluginOptions),
@@ -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;
@@ -32,7 +32,7 @@ __export(manifest_exports, {
32
32
  });
33
33
  module.exports = __toCommonJS(manifest_exports);
34
34
  var import_path = __toESM(require("path"));
35
- var import_utils = require("@modern-js/utils");
35
+ var import_fs_extra = __toESM(require("fs-extra"));
36
36
  function mergeStats(browserStats, nodeStats) {
37
37
  const ssrRemoteEntry = nodeStats.metaData.remoteEntry;
38
38
  browserStats.metaData.ssrRemoteEntry = ssrRemoteEntry;
@@ -66,8 +66,8 @@ function mergeStatsAndManifest(nodePlugin, browserPlugin) {
66
66
  }
67
67
  function updateStatsAndManifest(nodePlugin, browserPlugin, outputDir) {
68
68
  const { mergedStats, mergedStatsFilePath, mergedManifest, mergedManifestFilePath } = mergeStatsAndManifest(nodePlugin, browserPlugin);
69
- import_utils.fs.writeFileSync(import_path.default.resolve(outputDir, mergedStatsFilePath), JSON.stringify(mergedStats, null, 2));
70
- import_utils.fs.writeFileSync(import_path.default.resolve(outputDir, mergedManifestFilePath), JSON.stringify(mergedManifest, null, 2));
69
+ import_fs_extra.default.writeFileSync(import_path.default.resolve(outputDir, mergedStatsFilePath), JSON.stringify(mergedStats, null, 2));
70
+ import_fs_extra.default.writeFileSync(import_path.default.resolve(outputDir, mergedManifestFilePath), JSON.stringify(mergedManifest, null, 2));
71
71
  }
72
72
  // Annotate the CommonJS export names for ESM import in node:
73
73
  0 && (module.exports = {
@@ -35,14 +35,14 @@ __export(ssrPlugin_exports, {
35
35
  });
36
36
  module.exports = __toCommonJS(ssrPlugin_exports);
37
37
  var import_path = __toESM(require("path"));
38
- var import_utils = require("@modern-js/utils");
38
+ var import_fs_extra = __toESM(require("fs-extra"));
39
39
  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"));
44
- var import_utils2 = require("./utils");
45
- var import_utils3 = require("./utils");
43
+ var import_constant = require("./constant");
44
+ var import_logger = __toESM(require("./logger"));
45
+ var import_utils = 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_utils.skipByTarget)(target)) {
67
67
  return config;
68
68
  }
69
- if ((0, import_utils3.isWebTarget)(target)) {
69
+ if ((0, import_utils.isWebTarget)(target)) {
70
70
  csrOutputPath = config.output.distPath.root;
71
71
  } else {
72
72
  ssrOutputPath = config.output.distPath.root;
@@ -112,23 +112,15 @@ const moduleFederationSSRPlugin = (pluginOptions) => ({
112
112
  }
113
113
  setEnv();
114
114
  api._internalRuntimePlugins(({ entrypoint, plugins }) => {
115
- const { fetchServerQuery } = pluginOptions;
116
- plugins.push({
117
- name: "injectDataFetchFunction",
118
- path: "@module-federation/modern-js/ssr-inject-data-fetch-function-plugin",
119
- config: {
120
- fetchServerQuery
121
- }
122
- });
123
- if (!(0, import_utils2.isDev)()) {
115
+ if (!import_constant.isDev) {
124
116
  return {
125
117
  entrypoint,
126
118
  plugins
127
119
  };
128
120
  }
129
121
  plugins.push({
130
- name: "mfSSRDev",
131
- path: "@module-federation/modern-js/ssr-dev-plugin",
122
+ name: "mfSSR",
123
+ path: "@module-federation/modern-js/ssr-runtime",
132
124
  config: {}
133
125
  });
134
126
  return {
@@ -136,25 +128,14 @@ const moduleFederationSSRPlugin = (pluginOptions) => ({
136
128
  plugins
137
129
  };
138
130
  });
139
- if (pluginOptions.ssrConfig.remotes) {
140
- api._internalServerPlugins(({ plugins }) => {
141
- plugins.push({
142
- name: "@module-federation/modern-js/data-fetch-server-plugin",
143
- options: {}
144
- });
145
- return {
146
- plugins
147
- };
148
- });
149
- }
150
131
  api.modifyBundlerChain((chain) => {
151
132
  const target = chain.get("target");
152
- if ((0, import_utils3.skipByTarget)(target)) {
133
+ if ((0, import_utils.skipByTarget)(target)) {
153
134
  return;
154
135
  }
155
136
  const bundlerType = api.getAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
156
137
  const MFPlugin = bundlerType === "webpack" ? import_webpack.ModuleFederationPlugin : import_rspack.ModuleFederationPlugin;
157
- const isWeb = (0, import_utils3.isWebTarget)(target);
138
+ const isWeb = (0, import_utils.isWebTarget)(target);
158
139
  if (!isWeb) {
159
140
  if (!chain.plugins.has(CHAIN_MF_PLUGIN_ID)) {
160
141
  chain.plugin(CHAIN_MF_PLUGIN_ID).use(MFPlugin, [
@@ -167,7 +148,7 @@ const moduleFederationSSRPlugin = (pluginOptions) => ({
167
148
  }
168
149
  if (!isWeb) {
169
150
  chain.target("async-node");
170
- if ((0, import_utils2.isDev)()) {
151
+ if (import_constant.isDev) {
171
152
  chain.plugin("UniverseEntryChunkTrackerPlugin").use(import_universe_entry_chunk_tracker_plugin.default);
172
153
  }
173
154
  const userSSRConfig = pluginOptions.userConfig.ssr ? typeof pluginOptions.userConfig.ssr === "object" ? pluginOptions.userConfig.ssr : {} : {};
@@ -176,7 +157,7 @@ const moduleFederationSSRPlugin = (pluginOptions) => ({
176
157
  chain.output.publicPath(`${publicPath}${userSSRConfig.distOutputDir}/`);
177
158
  }
178
159
  }
179
- if ((0, import_utils2.isDev)() && isWeb) {
160
+ if (import_constant.isDev && isWeb) {
180
161
  chain.externals({
181
162
  "@module-federation/node/utils": "NOT_USED_IN_BROWSER"
182
163
  });
@@ -199,11 +180,11 @@ const moduleFederationSSRPlugin = (pluginOptions) => ({
199
180
  var _req_url, _req_url1;
200
181
  if (((_req_url = req.url) === null || _req_url === void 0 ? void 0 : _req_url.includes(".json")) && !((_req_url1 = req.url) === null || _req_url1 === void 0 ? void 0 : _req_url1.includes("hot-update"))) {
201
182
  const filepath = import_path.default.join(process.cwd(), `dist${req.url}`);
202
- import_utils.fs.statSync(filepath);
183
+ import_fs_extra.default.statSync(filepath);
203
184
  res.setHeader("Access-Control-Allow-Origin", "*");
204
185
  res.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, PATCH, OPTIONS");
205
186
  res.setHeader("Access-Control-Allow-Headers", "*");
206
- import_utils.fs.createReadStream(filepath).pipe(res);
187
+ import_fs_extra.default.createReadStream(filepath).pipe(res);
207
188
  } else {
208
189
  next();
209
190
  }
@@ -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,201 @@
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
+ function collectSSRAssets(options) {
88
+ const { id, injectLink = true, injectScript = true } = 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
+ [
110
+ ...targetModule.assets.css.sync,
111
+ ...targetModule.assets.css.async
112
+ ].forEach((file, index) => {
113
+ links.push(/* @__PURE__ */ (0, import_jsx_runtime.jsx)("link", {
114
+ href: `${publicPath}${file}`,
115
+ rel: "stylesheet",
116
+ type: "text/css"
117
+ }, `${file.split(".")[0]}_${index}`));
118
+ });
119
+ }
120
+ if (injectScript) {
121
+ scripts.push(/* @__PURE__ */ (0, import_jsx_runtime.jsx)("script", {
122
+ async: true,
123
+ src: `${publicPath}${remoteEntry}`,
124
+ crossOrigin: "anonymous"
125
+ }, remoteEntry.split(".")[0]));
126
+ [
127
+ ...targetModule.assets.js.sync
128
+ ].forEach((file, index) => {
129
+ scripts.push(/* @__PURE__ */ (0, import_jsx_runtime.jsx)("script", {
130
+ async: true,
131
+ src: `${publicPath}${file}`,
132
+ crossOrigin: "anonymous"
133
+ }, `${file.split(".")[0]}_${index}`));
134
+ });
135
+ }
136
+ return [
137
+ ...scripts,
138
+ ...links
139
+ ];
140
+ }
141
+ function createRemoteSSRComponent(info) {
142
+ const exportName = (info === null || info === void 0 ? void 0 : info.export) || "default";
143
+ const LazyComponent = /* @__PURE__ */ import_react.default.lazy(async () => {
144
+ try {
145
+ const m = await info.loader();
146
+ if (!m) {
147
+ throw new Error("load remote failed");
148
+ }
149
+ const moduleId = m && m[Symbol.for("mf_module_id")];
150
+ const assets = collectSSRAssets({
151
+ id: moduleId
152
+ });
153
+ const Com = m[exportName];
154
+ if (exportName in m && typeof Com === "function") {
155
+ return {
156
+ default: (props) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
157
+ children: [
158
+ assets,
159
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Com, {
160
+ ...props
161
+ })
162
+ ]
163
+ })
164
+ };
165
+ } else {
166
+ throw Error(`Make sure that ${moduleId} has the correct export when export is ${String(exportName)}`);
167
+ }
168
+ } catch (err) {
169
+ if (!info.fallback) {
170
+ throw err;
171
+ }
172
+ const FallbackFunctionComponent = info.fallback;
173
+ const FallbackNode = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FallbackFunctionComponent, {
174
+ error: err,
175
+ resetErrorBoundary: () => {
176
+ console.log('SSR mode not support "resetErrorBoundary" !');
177
+ }
178
+ });
179
+ return {
180
+ default: () => FallbackNode
181
+ };
182
+ }
183
+ });
184
+ return (props) => {
185
+ const { key, ...args } = props;
186
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_error_boundary.ErrorBoundary, {
187
+ FallbackComponent: info.fallback,
188
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.default.Suspense, {
189
+ fallback: info.loading,
190
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LazyComponent, {
191
+ ...args
192
+ })
193
+ })
194
+ });
195
+ };
196
+ }
197
+ // Annotate the CommonJS export names for ESM import in node:
198
+ 0 && (module.exports = {
199
+ collectSSRAssets,
200
+ createRemoteSSRComponent
201
+ });
@@ -19,32 +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
- kit: () => kit,
24
- setSSREnv: () => import_injectDataFetchFunctionPlugin.setSSREnv
22
+ kit: () => kit
25
23
  });
26
24
  module.exports = __toCommonJS(runtime_exports);
27
25
  __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
26
  const kit = {
31
27
  get createRemoteSSRComponent() {
32
- return require("./createRemoteComponent").createRemoteSSRComponent;
33
- },
34
- get createRemoteComponent() {
35
- return require("./createRemoteComponent").createRemoteComponent;
28
+ return require("./createRemoteSSRComponent").createRemoteSSRComponent;
36
29
  },
37
30
  get collectSSRAssets() {
38
- return require("./createRemoteComponent").collectSSRAssets;
39
- },
40
- get wrapNoSSR() {
41
- return require("./wrapNoSSR").wrapNoSSR;
31
+ return require("./createRemoteSSRComponent").collectSSRAssets;
42
32
  }
43
33
  };
44
34
  // Annotate the CommonJS export names for ESM import in node:
45
35
  0 && (module.exports = {
46
- ERROR_TYPE,
47
36
  kit,
48
- setSSREnv,
49
37
  ...require("@module-federation/enhanced/runtime")
50
38
  });