@module-federation/modern-js 0.0.0-next-20250616092616 → 0.0.0-next-20250616190501

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 (90) hide show
  1. package/package.json +16 -9
  2. package/dist/LICENSE +0 -21
  3. package/dist/cjs/cli/configPlugin.js +0 -381
  4. package/dist/cjs/cli/configPlugin.spec.js +0 -114
  5. package/dist/cjs/cli/index.js +0 -95
  6. package/dist/cjs/cli/mfRuntimePlugins/inject-node-fetch.js +0 -44
  7. package/dist/cjs/cli/mfRuntimePlugins/resolve-entry-ipv4.js +0 -82
  8. package/dist/cjs/cli/mfRuntimePlugins/shared-strategy.js +0 -43
  9. package/dist/cjs/cli/server/data-fetch-server-plugin.js +0 -188
  10. package/dist/cjs/cli/ssrPlugin.js +0 -236
  11. package/dist/cjs/cli/utils.js +0 -90
  12. package/dist/cjs/constant.js +0 -31
  13. package/dist/cjs/interfaces/bundler.js +0 -16
  14. package/dist/cjs/logger.js +0 -27
  15. package/dist/cjs/runtime/index.js +0 -33
  16. package/dist/cjs/server/fileCache.js +0 -84
  17. package/dist/cjs/server/fileCache.spec.js +0 -28
  18. package/dist/cjs/server/index.js +0 -58
  19. package/dist/cjs/server/staticMiddleware.js +0 -77
  20. package/dist/cjs/server/staticMiddleware.spec.js +0 -185
  21. package/dist/cjs/ssr-runtime/SSRLiveReload.js +0 -43
  22. package/dist/cjs/ssr-runtime/devPlugin.js +0 -71
  23. package/dist/cjs/ssr-runtime/injectDataFetchFunctionPlugin.js +0 -41
  24. package/dist/cjs/types/index.js +0 -16
  25. package/dist/esm/cli/configPlugin.js +0 -388
  26. package/dist/esm/cli/configPlugin.spec.js +0 -110
  27. package/dist/esm/cli/index.js +0 -90
  28. package/dist/esm/cli/mfRuntimePlugins/inject-node-fetch.js +0 -16
  29. package/dist/esm/cli/mfRuntimePlugins/resolve-entry-ipv4.js +0 -74
  30. package/dist/esm/cli/mfRuntimePlugins/shared-strategy.js +0 -25
  31. package/dist/esm/cli/server/data-fetch-server-plugin.js +0 -236
  32. package/dist/esm/cli/ssrPlugin.js +0 -219
  33. package/dist/esm/cli/utils.js +0 -53
  34. package/dist/esm/constant.js +0 -6
  35. package/dist/esm/interfaces/bundler.js +0 -0
  36. package/dist/esm/logger.js +0 -7
  37. package/dist/esm/runtime/index.js +0 -6
  38. package/dist/esm/server/fileCache.js +0 -98
  39. package/dist/esm/server/fileCache.spec.js +0 -50
  40. package/dist/esm/server/index.js +0 -36
  41. package/dist/esm/server/staticMiddleware.js +0 -81
  42. package/dist/esm/server/staticMiddleware.spec.js +0 -328
  43. package/dist/esm/ssr-runtime/SSRLiveReload.js +0 -26
  44. package/dist/esm/ssr-runtime/devPlugin.js +0 -73
  45. package/dist/esm/ssr-runtime/injectDataFetchFunctionPlugin.js +0 -35
  46. package/dist/esm/types/index.js +0 -0
  47. package/dist/esm-node/cli/configPlugin.js +0 -340
  48. package/dist/esm-node/cli/configPlugin.spec.js +0 -91
  49. package/dist/esm-node/cli/index.js +0 -70
  50. package/dist/esm-node/cli/mfRuntimePlugins/inject-node-fetch.js +0 -14
  51. package/dist/esm-node/cli/mfRuntimePlugins/resolve-entry-ipv4.js +0 -62
  52. package/dist/esm-node/cli/mfRuntimePlugins/shared-strategy.js +0 -23
  53. package/dist/esm-node/cli/server/data-fetch-server-plugin.js +0 -158
  54. package/dist/esm-node/cli/ssrPlugin.js +0 -200
  55. package/dist/esm-node/cli/utils.js +0 -53
  56. package/dist/esm-node/constant.js +0 -6
  57. package/dist/esm-node/interfaces/bundler.js +0 -0
  58. package/dist/esm-node/logger.js +0 -7
  59. package/dist/esm-node/runtime/index.js +0 -6
  60. package/dist/esm-node/server/fileCache.js +0 -49
  61. package/dist/esm-node/server/fileCache.spec.js +0 -27
  62. package/dist/esm-node/server/index.js +0 -34
  63. package/dist/esm-node/server/staticMiddleware.js +0 -43
  64. package/dist/esm-node/server/staticMiddleware.spec.js +0 -162
  65. package/dist/esm-node/ssr-runtime/SSRLiveReload.js +0 -19
  66. package/dist/esm-node/ssr-runtime/devPlugin.js +0 -37
  67. package/dist/esm-node/ssr-runtime/injectDataFetchFunctionPlugin.js +0 -17
  68. package/dist/esm-node/types/index.js +0 -0
  69. package/dist/types/cli/configPlugin.d.ts +0 -21
  70. package/dist/types/cli/configPlugin.spec.d.ts +0 -1
  71. package/dist/types/cli/index.d.ts +0 -6
  72. package/dist/types/cli/mfRuntimePlugins/inject-node-fetch.d.ts +0 -3
  73. package/dist/types/cli/mfRuntimePlugins/resolve-entry-ipv4.d.ts +0 -3
  74. package/dist/types/cli/mfRuntimePlugins/shared-strategy.d.ts +0 -3
  75. package/dist/types/cli/server/data-fetch-server-plugin.d.ts +0 -3
  76. package/dist/types/cli/ssrPlugin.d.ts +0 -6
  77. package/dist/types/cli/utils.d.ts +0 -6
  78. package/dist/types/constant.d.ts +0 -2
  79. package/dist/types/interfaces/bundler.d.ts +0 -18
  80. package/dist/types/logger.d.ts +0 -2
  81. package/dist/types/runtime/index.d.ts +0 -3
  82. package/dist/types/server/fileCache.d.ts +0 -14
  83. package/dist/types/server/fileCache.spec.d.ts +0 -1
  84. package/dist/types/server/index.d.ts +0 -4
  85. package/dist/types/server/staticMiddleware.d.ts +0 -6
  86. package/dist/types/server/staticMiddleware.spec.d.ts +0 -1
  87. package/dist/types/ssr-runtime/SSRLiveReload.d.ts +0 -1
  88. package/dist/types/ssr-runtime/devPlugin.d.ts +0 -2
  89. package/dist/types/ssr-runtime/injectDataFetchFunctionPlugin.d.ts +0 -4
  90. package/dist/types/types/index.d.ts +0 -24
@@ -1,98 +0,0 @@
1
- import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
- import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
3
- import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
4
- import fs from "fs-extra";
5
- import { LRUCache } from "lru-cache";
6
- var FileCache = /* @__PURE__ */ function() {
7
- "use strict";
8
- function FileCache2() {
9
- _class_call_check(this, FileCache2);
10
- this.cache = new LRUCache({
11
- maxSize: 200 * 1024 * 1024
12
- });
13
- }
14
- var _proto = FileCache2.prototype;
15
- _proto.getFile = function getFile(filepath) {
16
- var _this = this;
17
- return _async_to_generator(function() {
18
- var stat, currentModified, cachedEntry, content, newEntry, err;
19
- return _ts_generator(this, function(_state) {
20
- switch (_state.label) {
21
- case 0:
22
- return [
23
- 4,
24
- fs.pathExists(filepath)
25
- ];
26
- case 1:
27
- if (!_state.sent()) {
28
- return [
29
- 2,
30
- null
31
- ];
32
- }
33
- _state.label = 2;
34
- case 2:
35
- _state.trys.push([
36
- 2,
37
- 5,
38
- ,
39
- 6
40
- ]);
41
- return [
42
- 4,
43
- fs.lstat(filepath)
44
- ];
45
- case 3:
46
- stat = _state.sent();
47
- currentModified = stat.mtimeMs;
48
- cachedEntry = _this.cache.get(filepath);
49
- if (cachedEntry && currentModified <= cachedEntry.lastModified) {
50
- return [
51
- 2,
52
- {
53
- content: cachedEntry.content,
54
- lastModified: cachedEntry.lastModified
55
- }
56
- ];
57
- }
58
- return [
59
- 4,
60
- fs.readFile(filepath, "utf-8")
61
- ];
62
- case 4:
63
- content = _state.sent();
64
- newEntry = {
65
- content,
66
- lastModified: currentModified
67
- };
68
- _this.cache.set(filepath, newEntry, {
69
- size: stat.size || content.length
70
- });
71
- return [
72
- 2,
73
- {
74
- content,
75
- lastModified: currentModified
76
- }
77
- ];
78
- case 5:
79
- err = _state.sent();
80
- return [
81
- 2,
82
- null
83
- ];
84
- case 6:
85
- return [
86
- 2
87
- ];
88
- }
89
- });
90
- })();
91
- };
92
- return FileCache2;
93
- }();
94
- var fileCache = new FileCache();
95
- export {
96
- FileCache,
97
- fileCache
98
- };
@@ -1,50 +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, beforeAll } from "vitest";
4
- import { FileCache } from "./fileCache";
5
- beforeAll(function() {
6
- vi.mock("fs-extra", function() {
7
- return {
8
- default: {
9
- pathExists: function() {
10
- return true;
11
- },
12
- lstat: function() {
13
- return {
14
- mtimeMs: Date.now(),
15
- size: 4
16
- };
17
- },
18
- readFile: function() {
19
- return "test";
20
- }
21
- }
22
- };
23
- });
24
- });
25
- describe("modern serve static file cache", /* @__PURE__ */ _async_to_generator(function() {
26
- return _ts_generator(this, function(_state) {
27
- it("should cache file", /* @__PURE__ */ _async_to_generator(function() {
28
- var cache, result;
29
- return _ts_generator(this, function(_state2) {
30
- switch (_state2.label) {
31
- case 0:
32
- cache = new FileCache();
33
- return [
34
- 4,
35
- cache.getFile("test.txt")
36
- ];
37
- case 1:
38
- result = _state2.sent();
39
- expect(result === null || result === void 0 ? void 0 : result.content).toBe("test");
40
- return [
41
- 2
42
- ];
43
- }
44
- });
45
- }));
46
- return [
47
- 2
48
- ];
49
- });
50
- }));
@@ -1,36 +0,0 @@
1
- import { createStaticMiddleware } from "./staticMiddleware";
2
- var staticServePlugin = function() {
3
- return {
4
- name: "@modern-js/module-federation/server",
5
- setup: function(api) {
6
- api.onPrepare(function() {
7
- var _config_output, _config_server;
8
- console.log(process.env.NODE_ENV);
9
- if (process.env.NODE_ENV === "development") {
10
- return;
11
- }
12
- var middlewares = api.getServerContext().middlewares;
13
- var config = api.getServerConfig();
14
- var assetPrefix = ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.assetPrefix) || "";
15
- if (!((_config_server = config.server) === null || _config_server === void 0 ? void 0 : _config_server.ssr)) {
16
- return;
17
- }
18
- var context = api.getServerContext();
19
- var pwd = context.distDirectory;
20
- var serverStaticMiddleware = createStaticMiddleware({
21
- assetPrefix,
22
- pwd
23
- });
24
- middlewares.push({
25
- name: "module-federation-serve-manifest",
26
- handler: serverStaticMiddleware
27
- });
28
- });
29
- }
30
- };
31
- };
32
- var server_default = staticServePlugin;
33
- export {
34
- server_default as default,
35
- staticServePlugin
36
- };
@@ -1,81 +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
- export {
80
- createStaticMiddleware
81
- };
@@ -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/data-fetch-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
- };