@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
@@ -0,0 +1,328 @@
1
+ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
+ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
+ import { it, expect, describe, vi, beforeEach } from "vitest";
4
+ import { createStaticMiddleware } from "./staticMiddleware";
5
+ vi.mock("fs-extra", function() {
6
+ return {
7
+ default: {
8
+ pathExists: vi.fn()
9
+ }
10
+ };
11
+ });
12
+ vi.mock("./fileCache", function() {
13
+ return {
14
+ fileCache: {
15
+ getFile: vi.fn()
16
+ }
17
+ };
18
+ });
19
+ import fs from "fs-extra";
20
+ import { fileCache } from "./fileCache";
21
+ describe("staticMiddleware", function() {
22
+ var middleware;
23
+ var mockContext;
24
+ var nextSpy;
25
+ beforeEach(function() {
26
+ vi.clearAllMocks();
27
+ middleware = createStaticMiddleware({
28
+ assetPrefix: "",
29
+ pwd: "/test/path"
30
+ });
31
+ nextSpy = vi.fn();
32
+ mockContext = {
33
+ req: {
34
+ path: ""
35
+ },
36
+ header: vi.fn(),
37
+ body: vi.fn()
38
+ };
39
+ });
40
+ describe("file extension filtering", function() {
41
+ it("should call next() for non-js files", /* @__PURE__ */ _async_to_generator(function() {
42
+ return _ts_generator(this, function(_state) {
43
+ switch (_state.label) {
44
+ case 0:
45
+ mockContext.req.path = "/bundles/test.css";
46
+ return [
47
+ 4,
48
+ middleware(mockContext, nextSpy)
49
+ ];
50
+ case 1:
51
+ _state.sent();
52
+ expect(nextSpy).toHaveBeenCalledOnce();
53
+ expect(mockContext.header).not.toHaveBeenCalled();
54
+ expect(mockContext.body).not.toHaveBeenCalled();
55
+ return [
56
+ 2
57
+ ];
58
+ }
59
+ });
60
+ }));
61
+ it("should call next() for files without extension", /* @__PURE__ */ _async_to_generator(function() {
62
+ return _ts_generator(this, function(_state) {
63
+ switch (_state.label) {
64
+ case 0:
65
+ mockContext.req.path = "/bundles/test";
66
+ return [
67
+ 4,
68
+ middleware(mockContext, nextSpy)
69
+ ];
70
+ case 1:
71
+ _state.sent();
72
+ expect(nextSpy).toHaveBeenCalledOnce();
73
+ expect(mockContext.header).not.toHaveBeenCalled();
74
+ expect(mockContext.body).not.toHaveBeenCalled();
75
+ return [
76
+ 2
77
+ ];
78
+ }
79
+ });
80
+ }));
81
+ it("should process .js files", /* @__PURE__ */ _async_to_generator(function() {
82
+ return _ts_generator(this, function(_state) {
83
+ switch (_state.label) {
84
+ case 0:
85
+ mockContext.req.path = "/bundles/test.js";
86
+ fs.pathExists.mockResolvedValue(false);
87
+ return [
88
+ 4,
89
+ middleware(mockContext, nextSpy)
90
+ ];
91
+ case 1:
92
+ _state.sent();
93
+ expect(fs.pathExists).toHaveBeenCalled();
94
+ return [
95
+ 2
96
+ ];
97
+ }
98
+ });
99
+ }));
100
+ });
101
+ describe("asset prefix filtering", function() {
102
+ it("should call next() for paths not starting with /bundles", /* @__PURE__ */ _async_to_generator(function() {
103
+ return _ts_generator(this, function(_state) {
104
+ switch (_state.label) {
105
+ case 0:
106
+ mockContext.req.path = "/assets/test.js";
107
+ return [
108
+ 4,
109
+ middleware(mockContext, nextSpy)
110
+ ];
111
+ case 1:
112
+ _state.sent();
113
+ expect(nextSpy).toHaveBeenCalledOnce();
114
+ expect(fs.pathExists).not.toHaveBeenCalled();
115
+ expect(mockContext.header).not.toHaveBeenCalled();
116
+ expect(mockContext.body).not.toHaveBeenCalled();
117
+ return [
118
+ 2
119
+ ];
120
+ }
121
+ });
122
+ }));
123
+ it("should call next() for root path", /* @__PURE__ */ _async_to_generator(function() {
124
+ return _ts_generator(this, function(_state) {
125
+ switch (_state.label) {
126
+ case 0:
127
+ mockContext.req.path = "/test.js";
128
+ return [
129
+ 4,
130
+ middleware(mockContext, nextSpy)
131
+ ];
132
+ case 1:
133
+ _state.sent();
134
+ expect(nextSpy).toHaveBeenCalledOnce();
135
+ expect(fs.pathExists).not.toHaveBeenCalled();
136
+ return [
137
+ 2
138
+ ];
139
+ }
140
+ });
141
+ }));
142
+ it("should process paths starting with /bundles", /* @__PURE__ */ _async_to_generator(function() {
143
+ return _ts_generator(this, function(_state) {
144
+ switch (_state.label) {
145
+ case 0:
146
+ mockContext.req.path = "/bundles/test.js";
147
+ fs.pathExists.mockResolvedValue(false);
148
+ return [
149
+ 4,
150
+ middleware(mockContext, nextSpy)
151
+ ];
152
+ case 1:
153
+ _state.sent();
154
+ expect(fs.pathExists).toHaveBeenCalledWith("/test/path/bundles/test.js");
155
+ return [
156
+ 2
157
+ ];
158
+ }
159
+ });
160
+ }));
161
+ });
162
+ describe("file existence check", function() {
163
+ it("should call next() when file does not exist", /* @__PURE__ */ _async_to_generator(function() {
164
+ return _ts_generator(this, function(_state) {
165
+ switch (_state.label) {
166
+ case 0:
167
+ mockContext.req.path = "/bundles/nonexistent.js";
168
+ fs.pathExists.mockResolvedValue(false);
169
+ return [
170
+ 4,
171
+ middleware(mockContext, nextSpy)
172
+ ];
173
+ case 1:
174
+ _state.sent();
175
+ expect(fs.pathExists).toHaveBeenCalledWith("/test/path/bundles/nonexistent.js");
176
+ expect(nextSpy).toHaveBeenCalledOnce();
177
+ expect(fileCache.getFile).not.toHaveBeenCalled();
178
+ expect(mockContext.header).not.toHaveBeenCalled();
179
+ expect(mockContext.body).not.toHaveBeenCalled();
180
+ return [
181
+ 2
182
+ ];
183
+ }
184
+ });
185
+ }));
186
+ it("should proceed to file cache when file exists", /* @__PURE__ */ _async_to_generator(function() {
187
+ return _ts_generator(this, function(_state) {
188
+ switch (_state.label) {
189
+ case 0:
190
+ mockContext.req.path = "/bundles/existing.js";
191
+ fs.pathExists.mockResolvedValue(true);
192
+ fileCache.getFile.mockResolvedValue(null);
193
+ return [
194
+ 4,
195
+ middleware(mockContext, nextSpy)
196
+ ];
197
+ case 1:
198
+ _state.sent();
199
+ expect(fs.pathExists).toHaveBeenCalledWith("/test/path/bundles/existing.js");
200
+ expect(fileCache.getFile).toHaveBeenCalledWith("/test/path/bundles/existing.js");
201
+ return [
202
+ 2
203
+ ];
204
+ }
205
+ });
206
+ }));
207
+ });
208
+ describe("successful file serving", function() {
209
+ it("should serve file content with correct headers", /* @__PURE__ */ _async_to_generator(function() {
210
+ var mockFileContent, mockFileResult, result;
211
+ return _ts_generator(this, function(_state) {
212
+ switch (_state.label) {
213
+ case 0:
214
+ mockFileContent = 'console.log("test");';
215
+ mockFileResult = {
216
+ content: mockFileContent,
217
+ lastModified: Date.now()
218
+ };
219
+ mockContext.req.path = "/bundles/app.js";
220
+ fs.pathExists.mockResolvedValue(true);
221
+ fileCache.getFile.mockResolvedValue(mockFileResult);
222
+ mockContext.body.mockReturnValue("response");
223
+ return [
224
+ 4,
225
+ middleware(mockContext, nextSpy)
226
+ ];
227
+ case 1:
228
+ result = _state.sent();
229
+ expect(fs.pathExists).toHaveBeenCalledWith("/test/path/bundles/app.js");
230
+ expect(fileCache.getFile).toHaveBeenCalledWith("/test/path/bundles/app.js");
231
+ expect(nextSpy).not.toHaveBeenCalled();
232
+ expect(mockContext.header).toHaveBeenCalledWith("Content-Type", "application/javascript");
233
+ expect(mockContext.header).toHaveBeenCalledWith("Content-Length", String(mockFileResult.content.length));
234
+ expect(mockContext.body).toHaveBeenCalledWith(mockFileResult.content, 200);
235
+ expect(result).toBe("response");
236
+ return [
237
+ 2
238
+ ];
239
+ }
240
+ });
241
+ }));
242
+ it("should handle empty file content", /* @__PURE__ */ _async_to_generator(function() {
243
+ var mockFileResult, result;
244
+ return _ts_generator(this, function(_state) {
245
+ switch (_state.label) {
246
+ case 0:
247
+ mockFileResult = {
248
+ content: "",
249
+ lastModified: Date.now()
250
+ };
251
+ mockContext.req.path = "/bundles/empty.js";
252
+ fs.pathExists.mockResolvedValue(true);
253
+ fileCache.getFile.mockResolvedValue(mockFileResult);
254
+ mockContext.body.mockReturnValue("empty-response");
255
+ return [
256
+ 4,
257
+ middleware(mockContext, nextSpy)
258
+ ];
259
+ case 1:
260
+ result = _state.sent();
261
+ expect(mockContext.header).toHaveBeenCalledWith("Content-Length", "0");
262
+ expect(mockContext.body).toHaveBeenCalledWith(mockFileResult.content, 200);
263
+ expect(result).toBe("empty-response");
264
+ expect(nextSpy).not.toHaveBeenCalled();
265
+ return [
266
+ 2
267
+ ];
268
+ }
269
+ });
270
+ }));
271
+ });
272
+ describe("asset prefix handling", function() {
273
+ it("should handle custom asset prefix correctly", /* @__PURE__ */ _async_to_generator(function() {
274
+ var customMiddleware;
275
+ return _ts_generator(this, function(_state) {
276
+ switch (_state.label) {
277
+ case 0:
278
+ customMiddleware = createStaticMiddleware({
279
+ assetPrefix: "/custom-prefix",
280
+ pwd: "/test/path"
281
+ });
282
+ mockContext.req.path = "/bundles/test.js";
283
+ return [
284
+ 4,
285
+ customMiddleware(mockContext, nextSpy)
286
+ ];
287
+ case 1:
288
+ _state.sent();
289
+ expect(nextSpy).toHaveBeenCalledOnce();
290
+ expect(mockContext.header).not.toHaveBeenCalled();
291
+ expect(mockContext.body).not.toHaveBeenCalled();
292
+ return [
293
+ 2
294
+ ];
295
+ }
296
+ });
297
+ }));
298
+ it("should handle asset prefix removal correctly", /* @__PURE__ */ _async_to_generator(function() {
299
+ var customMiddleware, mockFileResult;
300
+ return _ts_generator(this, function(_state) {
301
+ switch (_state.label) {
302
+ case 0:
303
+ customMiddleware = createStaticMiddleware({
304
+ assetPrefix: "/prefix",
305
+ pwd: "/test/path"
306
+ });
307
+ mockFileResult = {
308
+ content: "test content",
309
+ lastModified: Date.now()
310
+ };
311
+ mockContext.req.path = "/prefix/bundles/test.js";
312
+ fs.pathExists.mockResolvedValue(true);
313
+ fileCache.getFile.mockResolvedValue(mockFileResult);
314
+ return [
315
+ 4,
316
+ customMiddleware(mockContext, nextSpy)
317
+ ];
318
+ case 1:
319
+ _state.sent();
320
+ expect(fs.pathExists).toHaveBeenCalledWith("/test/path/bundles/test.js");
321
+ return [
322
+ 2
323
+ ];
324
+ }
325
+ });
326
+ }));
327
+ });
328
+ });
@@ -0,0 +1 @@
1
+ export * from "./plugin";
@@ -3,8 +3,7 @@ import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
3
3
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
4
4
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
5
5
  import { SSRLiveReload } from "./SSRLiveReload";
6
- import { flushDataFetch } from "../utils";
7
- var mfSSRDevPlugin = function() {
6
+ var mfSSRPlugin = function() {
8
7
  return {
9
8
  name: "@module-federation/modern-js",
10
9
  setup: function(api) {
@@ -31,7 +30,6 @@ var mfSSRDevPlugin = function() {
31
30
  ];
32
31
  case 2:
33
32
  shouldUpdate = _state.sent();
34
- console.log("shouldUpdate: ", shouldUpdate);
35
33
  if (!shouldUpdate)
36
34
  return [
37
35
  3,
@@ -44,7 +42,6 @@ var mfSSRDevPlugin = function() {
44
42
  ];
45
43
  case 3:
46
44
  _state.sent();
47
- flushDataFetch();
48
45
  globalThis.shouldUpdate = true;
49
46
  _state.label = 4;
50
47
  case 4:
@@ -69,5 +66,5 @@ var mfSSRDevPlugin = function() {
69
66
  };
70
67
  };
71
68
  export {
72
- mfSSRDevPlugin
69
+ mfSSRPlugin
73
70
  };
@@ -3,10 +3,10 @@ import { getIPV4, isWebTarget, skipByTarget } from "./utils";
3
3
  import { encodeName } from "@module-federation/sdk";
4
4
  import { bundle } from "@modern-js/node-bundle-require";
5
5
  import { LOCALHOST, PLUGIN_IDENTIFIER } from "../constant";
6
- import { autoDeleteSplitChunkCacheGroups, addDataFetchExposes } from "@module-federation/rsbuild-plugin/utils";
7
- import logger from "../logger";
8
- import { isDev } from "./utils";
6
+ import { autoDeleteSplitChunkCacheGroups } from "@module-federation/rsbuild-plugin/utils";
7
+ import logger from "./logger";
9
8
  const defaultPath = path.resolve(process.cwd(), "module-federation.config.ts");
9
+ const isDev = process.env.NODE_ENV === "development";
10
10
  function setEnv(enableSSR) {
11
11
  if (enableSSR) {
12
12
  process.env["MF_DISABLE_EMIT_STATS"] = "true";
@@ -95,7 +95,6 @@ const patchDTSConfig = (mfConfig, isServer) => {
95
95
  };
96
96
  const patchMFConfig = (mfConfig, isServer, remoteIpStrategy) => {
97
97
  replaceRemoteUrl(mfConfig, remoteIpStrategy);
98
- addDataFetchExposes(mfConfig.exposes, isServer);
99
98
  if (mfConfig.remoteType === void 0) {
100
99
  mfConfig.remoteType = "script";
101
100
  }
@@ -107,13 +106,12 @@ const patchMFConfig = (mfConfig, isServer, remoteIpStrategy) => {
107
106
  ];
108
107
  patchDTSConfig(mfConfig, isServer);
109
108
  injectRuntimePlugins(require.resolve("@module-federation/modern-js/shared-strategy"), runtimePlugins);
110
- injectRuntimePlugins(require.resolve("@module-federation/modern-js/auto-fetch-data"), runtimePlugins);
111
- if (isDev()) {
109
+ if (isDev) {
112
110
  injectRuntimePlugins(require.resolve("@module-federation/modern-js/resolve-entry-ipv4"), runtimePlugins);
113
111
  }
114
112
  if (isServer) {
115
113
  injectRuntimePlugins(require.resolve("@module-federation/node/runtimePlugin"), runtimePlugins);
116
- if (isDev()) {
114
+ if (isDev) {
117
115
  injectRuntimePlugins(require.resolve("@module-federation/node/record-dynamic-remote-entry-hash-plugin"), runtimePlugins);
118
116
  }
119
117
  injectRuntimePlugins(require.resolve("@module-federation/modern-js/inject-node-fetch"), runtimePlugins);
@@ -213,7 +211,7 @@ function patchBundlerConfig(options) {
213
211
  splitChunkConfig.chunks = "async";
214
212
  logger.warn(`splitChunks.chunks = async is not allowed with stream SSR mode, it will auto changed to "async"`);
215
213
  }
216
- if (isDev() && chain.output.get("publicPath") === "auto") {
214
+ if (isDev && chain.output.get("publicPath") === "auto") {
217
215
  var _modernjsConfig_dev, _modernjsConfig_server;
218
216
  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;
219
217
  const publicPath = `http://localhost:${port}/`;
@@ -227,7 +225,7 @@ function patchBundlerConfig(options) {
227
225
  chain.output.chunkFilename(chunkFileName.replace(".js", suffix));
228
226
  }
229
227
  }
230
- if (isDev() && enableSSR && !isServer) {
228
+ if (isDev && enableSSR && !isServer) {
231
229
  chain.resolve.fallback.set("crypto", false).set("stream", false).set("vm", false);
232
230
  }
233
231
  if (((_modernjsConfig_deploy = modernjsConfig.deploy) === null || _modernjsConfig_deploy === void 0 ? void 0 : _modernjsConfig_deploy.microFrontend) && Object.keys(mfConfig.exposes || {}).length) {
@@ -38,7 +38,6 @@ describe("patchMFConfig", async () => {
38
38
  remoteType: "script",
39
39
  runtimePlugins: [
40
40
  require.resolve("@module-federation/modern-js/shared-strategy"),
41
- require.resolve("@module-federation/modern-js/auto-fetch-data"),
42
41
  require.resolve("@module-federation/node/runtimePlugin"),
43
42
  require.resolve("@module-federation/modern-js/inject-node-fetch")
44
43
  ],
@@ -66,8 +65,7 @@ describe("patchMFConfig", async () => {
66
65
  },
67
66
  remoteType: "script",
68
67
  runtimePlugins: [
69
- require.resolve("@module-federation/modern-js/shared-strategy"),
70
- require.resolve("@module-federation/modern-js/auto-fetch-data")
68
+ require.resolve("@module-federation/modern-js/shared-strategy")
71
69
  ],
72
70
  shared: {
73
71
  react: {
@@ -0,0 +1,4 @@
1
+ const isDev = process.env.NODE_ENV === "development";
2
+ export {
3
+ isDev
4
+ };
@@ -4,7 +4,6 @@ import { moduleFederationConfigPlugin } from "./configPlugin";
4
4
  import { moduleFederationSSRPlugin } from "./ssrPlugin";
5
5
  import { isWebTarget } from "./utils";
6
6
  const moduleFederationPlugin = (userConfig = {}) => {
7
- var _userConfig_fetchServerQuery;
8
7
  const internalModernPluginOptions = {
9
8
  csrConfig: void 0,
10
9
  ssrConfig: void 0,
@@ -13,8 +12,7 @@ const moduleFederationPlugin = (userConfig = {}) => {
13
12
  distOutputDir: "",
14
13
  originPluginOptions: userConfig,
15
14
  remoteIpStrategy: userConfig === null || userConfig === void 0 ? void 0 : userConfig.remoteIpStrategy,
16
- userConfig: userConfig || {},
17
- fetchServerQuery: (_userConfig_fetchServerQuery = userConfig.fetchServerQuery) !== null && _userConfig_fetchServerQuery !== void 0 ? _userConfig_fetchServerQuery : void 0
15
+ userConfig: userConfig || {}
18
16
  };
19
17
  return {
20
18
  name: "@modern-js/plugin-module-federation",
@@ -46,6 +44,14 @@ const moduleFederationPlugin = (userConfig = {}) => {
46
44
  }
47
45
  }
48
46
  });
47
+ api._internalServerPlugins(({ plugins }) => {
48
+ plugins.push({
49
+ name: "@module-federation/modern-js/server"
50
+ });
51
+ return {
52
+ plugins
53
+ };
54
+ });
49
55
  },
50
56
  usePlugins: [
51
57
  moduleFederationConfigPlugin(internalModernPluginOptions),
@@ -1,5 +1,5 @@
1
1
  import { createLogger } from "@module-federation/sdk";
2
- import { PLUGIN_IDENTIFIER } from "./constant";
2
+ import { PLUGIN_IDENTIFIER } from "../constant";
3
3
  const logger = createLogger(PLUGIN_IDENTIFIER);
4
4
  var logger_default = logger;
5
5
  export {
@@ -1,5 +1,5 @@
1
1
  import path from "path";
2
- import { fs } from "@modern-js/utils";
2
+ import fs from "fs-extra";
3
3
  function mergeStats(browserStats, nodeStats) {
4
4
  const ssrRemoteEntry = nodeStats.metaData.remoteEntry;
5
5
  browserStats.metaData.ssrRemoteEntry = ssrRemoteEntry;
@@ -1,11 +1,11 @@
1
1
  import path from "path";
2
- import { fs } from "@modern-js/utils";
2
+ import fs from "fs-extra";
3
3
  import { ModuleFederationPlugin } from "@module-federation/enhanced/webpack";
4
4
  import { ModuleFederationPlugin as RspackModuleFederationPlugin } from "@module-federation/enhanced/rspack";
5
5
  import UniverseEntryChunkTrackerPlugin from "@module-federation/node/universe-entry-chunk-tracker-plugin";
6
6
  import { updateStatsAndManifest } from "./manifest";
7
- import logger from "../logger";
8
- import { isDev } from "./utils";
7
+ import { isDev } from "./constant";
8
+ import logger from "./logger";
9
9
  import { isWebTarget, skipByTarget } from "./utils";
10
10
  function setEnv() {
11
11
  process.env["MF_DISABLE_EMIT_STATS"] = "true";
@@ -76,23 +76,15 @@ const moduleFederationSSRPlugin = (pluginOptions) => ({
76
76
  }
77
77
  setEnv();
78
78
  api._internalRuntimePlugins(({ entrypoint, plugins }) => {
79
- const { fetchServerQuery } = pluginOptions;
80
- plugins.push({
81
- name: "injectDataFetchFunction",
82
- path: "@module-federation/modern-js/ssr-inject-data-fetch-function-plugin",
83
- config: {
84
- fetchServerQuery
85
- }
86
- });
87
- if (!isDev()) {
79
+ if (!isDev) {
88
80
  return {
89
81
  entrypoint,
90
82
  plugins
91
83
  };
92
84
  }
93
85
  plugins.push({
94
- name: "mfSSRDev",
95
- path: "@module-federation/modern-js/ssr-dev-plugin",
86
+ name: "mfSSR",
87
+ path: "@module-federation/modern-js/ssr-runtime",
96
88
  config: {}
97
89
  });
98
90
  return {
@@ -100,17 +92,6 @@ const moduleFederationSSRPlugin = (pluginOptions) => ({
100
92
  plugins
101
93
  };
102
94
  });
103
- if (pluginOptions.ssrConfig.remotes) {
104
- api._internalServerPlugins(({ plugins }) => {
105
- plugins.push({
106
- name: "@module-federation/modern-js/data-fetch-server-plugin",
107
- options: {}
108
- });
109
- return {
110
- plugins
111
- };
112
- });
113
- }
114
95
  api.modifyBundlerChain((chain) => {
115
96
  const target = chain.get("target");
116
97
  if (skipByTarget(target)) {
@@ -131,7 +112,7 @@ const moduleFederationSSRPlugin = (pluginOptions) => ({
131
112
  }
132
113
  if (!isWeb) {
133
114
  chain.target("async-node");
134
- if (isDev()) {
115
+ if (isDev) {
135
116
  chain.plugin("UniverseEntryChunkTrackerPlugin").use(UniverseEntryChunkTrackerPlugin);
136
117
  }
137
118
  const userSSRConfig = pluginOptions.userConfig.ssr ? typeof pluginOptions.userConfig.ssr === "object" ? pluginOptions.userConfig.ssr : {} : {};
@@ -140,7 +121,7 @@ const moduleFederationSSRPlugin = (pluginOptions) => ({
140
121
  chain.output.publicPath(`${publicPath}${userSSRConfig.distOutputDir}/`);
141
122
  }
142
123
  }
143
- if (isDev() && isWeb) {
124
+ if (isDev && isWeb) {
144
125
  chain.externals({
145
126
  "@module-federation/node/utils": "NOT_USED_IN_BROWSER"
146
127
  });
@@ -42,12 +42,8 @@ const skipByTarget = (target) => {
42
42
  }
43
43
  return false;
44
44
  };
45
- function isDev() {
46
- return process.env.NODE_ENV === "development";
47
- }
48
45
  export {
49
46
  getIPV4,
50
- isDev,
51
47
  isWebTarget,
52
48
  skipByTarget
53
49
  };
@@ -1,42 +1,6 @@
1
1
  const LOCALHOST = "localhost";
2
2
  const PLUGIN_IDENTIFIER = "[ Modern.js Module Federation ]";
3
- const DATA_FETCH_QUERY = "x-mf-data-fetch";
4
- const DATA_FETCH_ERROR_PREFIX = "caught the following error during dataFetch: ";
5
- const LOAD_REMOTE_ERROR_PREFIX = "caught the following error during loadRemote: ";
6
- const DOWNGRADE_KEY = "_mfSSRDowngrade";
7
- const DATA_FETCH_MAP_KEY = "__MF_DATA_FETCH_MAP__";
8
- const DATA_FETCH_FUNCTION = "_mfDataFetch";
9
- const FS_HREF = "_mfFSHref";
10
- const ERROR_TYPE = {
11
- DATA_FETCH: 1,
12
- LOAD_REMOTE: 2,
13
- UNKNOWN: 3
14
- };
15
- const WRAP_DATA_FETCH_ID_IDENTIFIER = "wrap_dfip_identifier";
16
- var MF_DATA_FETCH_TYPE;
17
- (function(MF_DATA_FETCH_TYPE2) {
18
- MF_DATA_FETCH_TYPE2[MF_DATA_FETCH_TYPE2["FETCH_SERVER"] = 1] = "FETCH_SERVER";
19
- MF_DATA_FETCH_TYPE2[MF_DATA_FETCH_TYPE2["FETCH_CLIENT"] = 2] = "FETCH_CLIENT";
20
- })(MF_DATA_FETCH_TYPE || (MF_DATA_FETCH_TYPE = {}));
21
- var MF_DATA_FETCH_STATUS;
22
- (function(MF_DATA_FETCH_STATUS2) {
23
- MF_DATA_FETCH_STATUS2[MF_DATA_FETCH_STATUS2["LOADED"] = 1] = "LOADED";
24
- MF_DATA_FETCH_STATUS2[MF_DATA_FETCH_STATUS2["LOADING"] = 2] = "LOADING";
25
- MF_DATA_FETCH_STATUS2[MF_DATA_FETCH_STATUS2["AWAIT"] = 0] = "AWAIT";
26
- MF_DATA_FETCH_STATUS2[MF_DATA_FETCH_STATUS2["ERROR"] = 3] = "ERROR";
27
- })(MF_DATA_FETCH_STATUS || (MF_DATA_FETCH_STATUS = {}));
28
3
  export {
29
- DATA_FETCH_ERROR_PREFIX,
30
- DATA_FETCH_FUNCTION,
31
- DATA_FETCH_MAP_KEY,
32
- DATA_FETCH_QUERY,
33
- DOWNGRADE_KEY,
34
- ERROR_TYPE,
35
- FS_HREF,
36
- LOAD_REMOTE_ERROR_PREFIX,
37
4
  LOCALHOST,
38
- MF_DATA_FETCH_STATUS,
39
- MF_DATA_FETCH_TYPE,
40
- PLUGIN_IDENTIFIER,
41
- WRAP_DATA_FETCH_ID_IDENTIFIER
5
+ PLUGIN_IDENTIFIER
42
6
  };