@module-federation/modern-js 0.21.5 → 0.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/dist/cjs/cli/configPlugin.js +301 -357
  2. package/dist/cjs/cli/index.js +103 -93
  3. package/dist/cjs/cli/mfRuntimePlugins/inject-node-fetch.js +51 -41
  4. package/dist/cjs/cli/mfRuntimePlugins/resolve-entry-ipv4.js +73 -75
  5. package/dist/cjs/cli/mfRuntimePlugins/shared-strategy.js +50 -40
  6. package/dist/cjs/cli/server/data-fetch-server-plugin.js +55 -44
  7. package/dist/cjs/cli/ssrPlugin.js +266 -298
  8. package/dist/cjs/cli/utils.js +84 -81
  9. package/dist/cjs/constant.js +37 -28
  10. package/dist/cjs/interfaces/bundler.js +17 -15
  11. package/dist/cjs/logger.js +37 -25
  12. package/dist/cjs/react/index.js +55 -19
  13. package/dist/cjs/react/plugin.js +62 -37
  14. package/dist/cjs/react/v18.js +55 -19
  15. package/dist/cjs/react/v19.js +55 -19
  16. package/dist/cjs/runtime/index.js +55 -19
  17. package/dist/cjs/server/fileCache.js +76 -76
  18. package/dist/cjs/server/index.js +65 -57
  19. package/dist/cjs/server/staticMiddleware.js +84 -84
  20. package/dist/cjs/ssr-runtime/SSRLiveReload.js +40 -34
  21. package/dist/cjs/ssr-runtime/devPlugin.js +63 -67
  22. package/dist/cjs/ssr-runtime/injectDataFetchFunctionPlugin.js +44 -36
  23. package/dist/cjs/types/index.js +17 -15
  24. package/dist/esm/cli/configPlugin.mjs +305 -0
  25. package/dist/esm/cli/index.mjs +83 -0
  26. package/dist/esm/cli/mfRuntimePlugins/inject-node-fetch.mjs +12 -0
  27. package/dist/esm/cli/mfRuntimePlugins/resolve-entry-ipv4.mjs +58 -0
  28. package/dist/esm/cli/mfRuntimePlugins/shared-strategy.mjs +21 -0
  29. package/dist/esm/cli/server/data-fetch-server-plugin.mjs +17 -0
  30. package/dist/esm/cli/ssrPlugin.mjs +254 -0
  31. package/dist/esm/cli/utils.mjs +40 -0
  32. package/dist/esm/constant.mjs +3 -0
  33. package/dist/esm/logger.mjs +5 -0
  34. package/dist/esm/react/plugin.mjs +3 -0
  35. package/dist/esm/server/fileCache.mjs +90 -0
  36. package/dist/esm/server/index.mjs +36 -0
  37. package/dist/esm/server/staticMiddleware.mjs +87 -0
  38. package/dist/esm/ssr-runtime/SSRLiveReload.mjs +22 -0
  39. package/dist/esm/ssr-runtime/devPlugin.mjs +70 -0
  40. package/dist/esm/ssr-runtime/injectDataFetchFunctionPlugin.mjs +34 -0
  41. package/dist/esm-node/cli/configPlugin.mjs +263 -0
  42. package/dist/esm-node/cli/index.mjs +67 -0
  43. package/dist/esm-node/cli/mfRuntimePlugins/inject-node-fetch.mjs +10 -0
  44. package/dist/esm-node/cli/mfRuntimePlugins/resolve-entry-ipv4.mjs +46 -0
  45. package/dist/esm-node/cli/mfRuntimePlugins/shared-strategy.mjs +19 -0
  46. package/dist/esm-node/cli/server/data-fetch-server-plugin.mjs +15 -0
  47. package/dist/esm-node/cli/ssrPlugin.mjs +228 -0
  48. package/dist/esm-node/cli/utils.mjs +40 -0
  49. package/dist/esm-node/constant.mjs +3 -0
  50. package/dist/esm-node/logger.mjs +5 -0
  51. package/dist/esm-node/react/plugin.mjs +3 -0
  52. package/dist/esm-node/server/fileCache.mjs +37 -0
  53. package/dist/esm-node/server/index.mjs +34 -0
  54. package/dist/esm-node/server/staticMiddleware.mjs +42 -0
  55. package/dist/esm-node/ssr-runtime/SSRLiveReload.mjs +15 -0
  56. package/dist/esm-node/ssr-runtime/devPlugin.mjs +33 -0
  57. package/dist/esm-node/ssr-runtime/injectDataFetchFunctionPlugin.mjs +14 -0
  58. package/package.json +32 -31
  59. package/dist/cjs/cli/configPlugin.spec.js +0 -112
  60. package/dist/cjs/server/fileCache.spec.js +0 -28
  61. package/dist/cjs/server/staticMiddleware.spec.js +0 -185
  62. package/dist/esm/cli/configPlugin.js +0 -395
  63. package/dist/esm/cli/configPlugin.spec.js +0 -108
  64. package/dist/esm/cli/index.js +0 -92
  65. package/dist/esm/cli/mfRuntimePlugins/inject-node-fetch.js +0 -16
  66. package/dist/esm/cli/mfRuntimePlugins/resolve-entry-ipv4.js +0 -74
  67. package/dist/esm/cli/mfRuntimePlugins/shared-strategy.js +0 -25
  68. package/dist/esm/cli/server/data-fetch-server-plugin.js +0 -20
  69. package/dist/esm/cli/ssrPlugin.js +0 -305
  70. package/dist/esm/cli/utils.js +0 -53
  71. package/dist/esm/constant.js +0 -6
  72. package/dist/esm/logger.js +0 -7
  73. package/dist/esm/react/plugin.js +0 -5
  74. package/dist/esm/server/fileCache.js +0 -98
  75. package/dist/esm/server/fileCache.spec.js +0 -50
  76. package/dist/esm/server/index.js +0 -41
  77. package/dist/esm/server/staticMiddleware.js +0 -104
  78. package/dist/esm/server/staticMiddleware.spec.js +0 -328
  79. package/dist/esm/ssr-runtime/SSRLiveReload.js +0 -26
  80. package/dist/esm/ssr-runtime/devPlugin.js +0 -73
  81. package/dist/esm/ssr-runtime/injectDataFetchFunctionPlugin.js +0 -34
  82. package/dist/esm-node/cli/configPlugin.js +0 -347
  83. package/dist/esm-node/cli/configPlugin.spec.js +0 -89
  84. package/dist/esm-node/cli/index.js +0 -72
  85. package/dist/esm-node/cli/mfRuntimePlugins/inject-node-fetch.js +0 -14
  86. package/dist/esm-node/cli/mfRuntimePlugins/resolve-entry-ipv4.js +0 -62
  87. package/dist/esm-node/cli/mfRuntimePlugins/shared-strategy.js +0 -23
  88. package/dist/esm-node/cli/server/data-fetch-server-plugin.js +0 -18
  89. package/dist/esm-node/cli/ssrPlugin.js +0 -280
  90. package/dist/esm-node/cli/utils.js +0 -53
  91. package/dist/esm-node/constant.js +0 -6
  92. package/dist/esm-node/logger.js +0 -7
  93. package/dist/esm-node/react/plugin.js +0 -5
  94. package/dist/esm-node/server/fileCache.js +0 -49
  95. package/dist/esm-node/server/fileCache.spec.js +0 -27
  96. package/dist/esm-node/server/index.js +0 -39
  97. package/dist/esm-node/server/staticMiddleware.js +0 -55
  98. package/dist/esm-node/server/staticMiddleware.spec.js +0 -162
  99. package/dist/esm-node/ssr-runtime/SSRLiveReload.js +0 -19
  100. package/dist/esm-node/ssr-runtime/devPlugin.js +0 -37
  101. package/dist/esm-node/ssr-runtime/injectDataFetchFunctionPlugin.js +0 -16
  102. /package/dist/esm/interfaces/{bundler.js → bundler.mjs} +0 -0
  103. /package/dist/esm/react/{index.js → index.mjs} +0 -0
  104. /package/dist/esm/react/{v18.js → v18.mjs} +0 -0
  105. /package/dist/esm/react/{v19.js → v19.mjs} +0 -0
  106. /package/dist/esm/runtime/{index.js → index.mjs} +0 -0
  107. /package/dist/esm/types/{index.js → index.mjs} +0 -0
  108. /package/dist/esm-node/interfaces/{bundler.js → bundler.mjs} +0 -0
  109. /package/dist/esm-node/react/{index.js → index.mjs} +0 -0
  110. /package/dist/esm-node/react/{v18.js → v18.mjs} +0 -0
  111. /package/dist/esm-node/react/{v19.js → v19.mjs} +0 -0
  112. /package/dist/esm-node/runtime/{index.js → index.mjs} +0 -0
  113. /package/dist/esm-node/types/{index.js → index.mjs} +0 -0
@@ -1,104 +0,0 @@
1
- import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
- import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
- import fs from "fs-extra";
4
- import path from "node:path";
5
- import { fileCache } from "./fileCache";
6
- var bundlesAssetPrefix = "/bundles";
7
- var removeHost = function(url) {
8
- try {
9
- var hasProtocol = url.includes("://");
10
- var hasDomain = hasProtocol || url.startsWith("//");
11
- var pathname = hasDomain ? new URL(hasProtocol ? url : "http:".concat(url)).pathname : url;
12
- return pathname;
13
- } catch (e) {
14
- return url;
15
- }
16
- };
17
- var createStaticMiddleware = function(options) {
18
- var assetPrefix = options.assetPrefix, pwd = options.pwd;
19
- return function() {
20
- var _ref = _async_to_generator(function(c, next) {
21
- var pathname, prefixWithoutHost, prefixWithBundle, pathnameWithoutPrefix, filepath, fileResult;
22
- return _ts_generator(this, function(_state) {
23
- switch (_state.label) {
24
- case 0:
25
- pathname = c.req.path;
26
- if (path.extname(pathname) !== ".js") {
27
- return [
28
- 2,
29
- next()
30
- ];
31
- }
32
- prefixWithoutHost = removeHost(assetPrefix);
33
- prefixWithBundle = path.join(prefixWithoutHost, bundlesAssetPrefix);
34
- if (!pathname.startsWith(prefixWithBundle)) {
35
- return [
36
- 2,
37
- next()
38
- ];
39
- }
40
- pathnameWithoutPrefix = pathname.replace(prefixWithBundle, "");
41
- filepath = path.join(pwd, bundlesAssetPrefix, pathnameWithoutPrefix);
42
- return [
43
- 4,
44
- fs.pathExists(filepath)
45
- ];
46
- case 1:
47
- if (!_state.sent()) {
48
- return [
49
- 2,
50
- next()
51
- ];
52
- }
53
- return [
54
- 4,
55
- fileCache.getFile(filepath)
56
- ];
57
- case 2:
58
- fileResult = _state.sent();
59
- if (!fileResult) {
60
- return [
61
- 2,
62
- next()
63
- ];
64
- }
65
- c.header("Content-Type", "application/javascript");
66
- c.header("Content-Length", String(fileResult.content.length));
67
- return [
68
- 2,
69
- c.body(fileResult.content, 200)
70
- ];
71
- }
72
- });
73
- });
74
- return function(c, next) {
75
- return _ref.apply(this, arguments);
76
- };
77
- }();
78
- };
79
- var createCorsMiddleware = function() {
80
- return function() {
81
- var _ref = _async_to_generator(function(c, next) {
82
- var pathname;
83
- return _ts_generator(this, function(_state) {
84
- pathname = c.req.path;
85
- if (path.extname(pathname)) {
86
- c.header("Access-Control-Allow-Origin", "*");
87
- c.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, PATCH, OPTIONS");
88
- c.header("Access-Control-Allow-Headers", "*");
89
- }
90
- return [
91
- 2,
92
- next()
93
- ];
94
- });
95
- });
96
- return function(c, next) {
97
- return _ref.apply(this, arguments);
98
- };
99
- }();
100
- };
101
- export {
102
- createCorsMiddleware,
103
- createStaticMiddleware
104
- };
@@ -1,328 +0,0 @@
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
- });
@@ -1,26 +0,0 @@
1
- import { _ as _tagged_template_literal } from "@swc/helpers/_/_tagged_template_literal";
2
- function _templateObject() {
3
- var data = _tagged_template_literal([
4
- "\n if(",
5
- "){\n location.reload();\n }\n "
6
- ]);
7
- _templateObject = function _templateObject2() {
8
- return data;
9
- };
10
- return data;
11
- }
12
- import { jsx as _jsx } from "react/jsx-runtime";
13
- function SSRLiveReload() {
14
- if (process.env.NODE_ENV !== "development") {
15
- return null;
16
- }
17
- return /* @__PURE__ */ _jsx("script", {
18
- suppressHydrationWarning: true,
19
- dangerouslySetInnerHTML: {
20
- __html: String.raw(_templateObject(), globalThis.shouldUpdate)
21
- }
22
- });
23
- }
24
- export {
25
- SSRLiveReload
26
- };
@@ -1,73 +0,0 @@
1
- import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
- import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
3
- import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
4
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
5
- import { SSRLiveReload } from "./SSRLiveReload";
6
- import { flushDataFetch } from "@module-federation/bridge-react/lazy-utils";
7
- var mfSSRDevPlugin = function() {
8
- return {
9
- name: "@module-federation/modern-js",
10
- setup: function(api) {
11
- api.onBeforeRender(/* @__PURE__ */ _async_to_generator(function() {
12
- var nodeUtils, shouldUpdate;
13
- return _ts_generator(this, function(_state) {
14
- switch (_state.label) {
15
- case 0:
16
- if (typeof window !== "undefined") {
17
- return [
18
- 2
19
- ];
20
- }
21
- globalThis.shouldUpdate = false;
22
- return [
23
- 4,
24
- import("@module-federation/node/utils")
25
- ];
26
- case 1:
27
- nodeUtils = _state.sent();
28
- return [
29
- 4,
30
- nodeUtils.revalidate()
31
- ];
32
- case 2:
33
- shouldUpdate = _state.sent();
34
- console.log("shouldUpdate: ", shouldUpdate);
35
- if (!shouldUpdate)
36
- return [
37
- 3,
38
- 4
39
- ];
40
- console.log("should RELOAD", shouldUpdate);
41
- return [
42
- 4,
43
- nodeUtils.flushChunks()
44
- ];
45
- case 3:
46
- _state.sent();
47
- flushDataFetch();
48
- globalThis.shouldUpdate = true;
49
- _state.label = 4;
50
- case 4:
51
- return [
52
- 2
53
- ];
54
- }
55
- });
56
- }));
57
- api.wrapRoot(function(App) {
58
- var AppWrapper = function(props) {
59
- return /* @__PURE__ */ _jsxs(_Fragment, {
60
- children: [
61
- /* @__PURE__ */ _jsx(SSRLiveReload, {}),
62
- /* @__PURE__ */ _jsx(App, _object_spread({}, props))
63
- ]
64
- });
65
- };
66
- return AppWrapper;
67
- });
68
- }
69
- };
70
- };
71
- export {
72
- mfSSRDevPlugin
73
- };
@@ -1,34 +0,0 @@
1
- import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
- import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
- import { callDataFetch } from "@module-federation/bridge-react/data-fetch-utils";
4
- import { setSSREnv } from "@module-federation/bridge-react/lazy-utils";
5
- var injectDataFetchFunctionPlugin = function(param) {
6
- var fetchServerQuery = param.fetchServerQuery;
7
- return {
8
- name: "@module-federation/inject-data-fetch-function-plugin",
9
- setup: function(api) {
10
- api.onBeforeRender(/* @__PURE__ */ _async_to_generator(function() {
11
- return _ts_generator(this, function(_state) {
12
- switch (_state.label) {
13
- case 0:
14
- setSSREnv({
15
- fetchServerQuery
16
- });
17
- return [
18
- 4,
19
- callDataFetch()
20
- ];
21
- case 1:
22
- _state.sent();
23
- return [
24
- 2
25
- ];
26
- }
27
- });
28
- }));
29
- }
30
- };
31
- };
32
- export {
33
- injectDataFetchFunctionPlugin
34
- };