@module-federation/modern-js 0.14.2 → 0.15.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 (122) hide show
  1. package/dist/LICENSE +21 -0
  2. package/dist/cjs/cli/configPlugin.js +381 -0
  3. package/dist/cjs/cli/configPlugin.spec.js +114 -0
  4. package/dist/cjs/cli/index.js +95 -0
  5. package/dist/cjs/cli/mfRuntimePlugins/auto-fetch-data.js +98 -0
  6. package/dist/cjs/cli/mfRuntimePlugins/inject-node-fetch.js +44 -0
  7. package/dist/cjs/cli/mfRuntimePlugins/resolve-entry-ipv4.js +82 -0
  8. package/dist/cjs/cli/mfRuntimePlugins/shared-strategy.js +43 -0
  9. package/dist/cjs/cli/server/data-fetch-server-plugin.js +189 -0
  10. package/dist/cjs/cli/ssrPlugin.js +236 -0
  11. package/dist/cjs/cli/utils.js +90 -0
  12. package/dist/cjs/constant.js +78 -0
  13. package/dist/cjs/interfaces/bundler.js +16 -0
  14. package/dist/cjs/interfaces/global.js +16 -0
  15. package/dist/cjs/logger.js +27 -0
  16. package/dist/cjs/runtime/AwaitDataFetch.js +144 -0
  17. package/dist/cjs/runtime/createRemoteComponent.js +327 -0
  18. package/dist/cjs/runtime/index.js +50 -0
  19. package/dist/cjs/runtime/wrapNoSSR.js +35 -0
  20. package/dist/cjs/server/fileCache.js +84 -0
  21. package/dist/cjs/server/fileCache.spec.js +28 -0
  22. package/dist/cjs/server/index.js +58 -0
  23. package/dist/cjs/server/staticMiddleware.js +77 -0
  24. package/dist/cjs/server/staticMiddleware.spec.js +185 -0
  25. package/dist/cjs/ssr-runtime/SSRLiveReload.js +43 -0
  26. package/dist/cjs/ssr-runtime/devPlugin.js +71 -0
  27. package/dist/cjs/ssr-runtime/downgrade.js +114 -0
  28. package/dist/cjs/ssr-runtime/injectDataFetchFunctionPlugin.js +136 -0
  29. package/dist/cjs/types/index.js +16 -0
  30. package/dist/cjs/utils/dataFetch.js +211 -0
  31. package/dist/cjs/utils/index.js +54 -0
  32. package/dist/esm/cli/configPlugin.js +388 -0
  33. package/dist/esm/cli/configPlugin.spec.js +110 -0
  34. package/dist/esm/cli/index.js +90 -0
  35. package/dist/esm/cli/mfRuntimePlugins/auto-fetch-data.js +74 -0
  36. package/dist/esm/cli/mfRuntimePlugins/inject-node-fetch.js +16 -0
  37. package/dist/esm/cli/mfRuntimePlugins/resolve-entry-ipv4.js +74 -0
  38. package/dist/esm/cli/mfRuntimePlugins/shared-strategy.js +25 -0
  39. package/dist/esm/cli/server/data-fetch-server-plugin.js +237 -0
  40. package/dist/esm/cli/ssrPlugin.js +219 -0
  41. package/dist/esm/cli/utils.js +53 -0
  42. package/dist/esm/constant.js +42 -0
  43. package/dist/esm/interfaces/bundler.js +0 -0
  44. package/dist/esm/interfaces/global.js +0 -0
  45. package/dist/esm/logger.js +7 -0
  46. package/dist/esm/runtime/AwaitDataFetch.js +131 -0
  47. package/dist/esm/runtime/createRemoteComponent.js +417 -0
  48. package/dist/esm/runtime/index.js +22 -0
  49. package/dist/esm/runtime/wrapNoSSR.js +12 -0
  50. package/dist/esm/server/fileCache.js +98 -0
  51. package/dist/esm/server/fileCache.spec.js +50 -0
  52. package/dist/esm/server/index.js +36 -0
  53. package/dist/esm/server/staticMiddleware.js +81 -0
  54. package/dist/esm/server/staticMiddleware.spec.js +328 -0
  55. package/dist/esm/ssr-runtime/SSRLiveReload.js +26 -0
  56. package/dist/esm/ssr-runtime/devPlugin.js +73 -0
  57. package/dist/esm/ssr-runtime/downgrade.js +150 -0
  58. package/dist/esm/ssr-runtime/injectDataFetchFunctionPlugin.js +177 -0
  59. package/dist/esm/types/index.js +0 -0
  60. package/dist/esm/utils/dataFetch.js +237 -0
  61. package/dist/esm/utils/index.js +28 -0
  62. package/dist/esm-node/cli/configPlugin.js +340 -0
  63. package/dist/esm-node/cli/configPlugin.spec.js +91 -0
  64. package/dist/esm-node/cli/index.js +70 -0
  65. package/dist/esm-node/cli/mfRuntimePlugins/auto-fetch-data.js +68 -0
  66. package/dist/esm-node/cli/mfRuntimePlugins/inject-node-fetch.js +14 -0
  67. package/dist/esm-node/cli/mfRuntimePlugins/resolve-entry-ipv4.js +62 -0
  68. package/dist/esm-node/cli/mfRuntimePlugins/shared-strategy.js +23 -0
  69. package/dist/esm-node/cli/server/data-fetch-server-plugin.js +159 -0
  70. package/dist/esm-node/cli/ssrPlugin.js +200 -0
  71. package/dist/esm-node/cli/utils.js +53 -0
  72. package/dist/esm-node/constant.js +42 -0
  73. package/dist/esm-node/interfaces/bundler.js +0 -0
  74. package/dist/esm-node/interfaces/global.js +0 -0
  75. package/dist/esm-node/logger.js +7 -0
  76. package/dist/esm-node/runtime/AwaitDataFetch.js +109 -0
  77. package/dist/esm-node/runtime/createRemoteComponent.js +291 -0
  78. package/dist/esm-node/runtime/index.js +22 -0
  79. package/dist/esm-node/runtime/wrapNoSSR.js +11 -0
  80. package/dist/esm-node/server/fileCache.js +49 -0
  81. package/dist/esm-node/server/fileCache.spec.js +27 -0
  82. package/dist/esm-node/server/index.js +34 -0
  83. package/dist/esm-node/server/staticMiddleware.js +43 -0
  84. package/dist/esm-node/server/staticMiddleware.spec.js +162 -0
  85. package/dist/esm-node/ssr-runtime/SSRLiveReload.js +19 -0
  86. package/dist/esm-node/ssr-runtime/devPlugin.js +37 -0
  87. package/dist/esm-node/ssr-runtime/downgrade.js +88 -0
  88. package/dist/esm-node/ssr-runtime/injectDataFetchFunctionPlugin.js +101 -0
  89. package/dist/esm-node/types/index.js +0 -0
  90. package/dist/esm-node/utils/dataFetch.js +166 -0
  91. package/dist/esm-node/utils/index.js +27 -0
  92. package/dist/types/cli/configPlugin.d.ts +21 -0
  93. package/dist/types/cli/configPlugin.spec.d.ts +1 -0
  94. package/dist/types/cli/index.d.ts +6 -0
  95. package/dist/types/cli/mfRuntimePlugins/auto-fetch-data.d.ts +3 -0
  96. package/dist/types/cli/mfRuntimePlugins/inject-node-fetch.d.ts +3 -0
  97. package/dist/types/cli/mfRuntimePlugins/resolve-entry-ipv4.d.ts +3 -0
  98. package/dist/types/cli/mfRuntimePlugins/shared-strategy.d.ts +3 -0
  99. package/dist/types/cli/server/data-fetch-server-plugin.d.ts +3 -0
  100. package/dist/types/cli/ssrPlugin.d.ts +6 -0
  101. package/dist/types/cli/utils.d.ts +6 -0
  102. package/dist/types/constant.d.ts +25 -0
  103. package/dist/types/interfaces/bundler.d.ts +18 -0
  104. package/dist/types/interfaces/global.d.ts +27 -0
  105. package/dist/types/logger.d.ts +2 -0
  106. package/dist/types/runtime/AwaitDataFetch.d.ts +19 -0
  107. package/dist/types/runtime/createRemoteComponent.d.ts +26 -0
  108. package/dist/types/runtime/index.d.ts +10 -0
  109. package/dist/types/runtime/wrapNoSSR.d.ts +9 -0
  110. package/dist/types/server/fileCache.d.ts +14 -0
  111. package/dist/types/server/fileCache.spec.d.ts +1 -0
  112. package/dist/types/server/index.d.ts +4 -0
  113. package/dist/types/server/staticMiddleware.d.ts +6 -0
  114. package/dist/types/server/staticMiddleware.spec.d.ts +1 -0
  115. package/dist/types/ssr-runtime/SSRLiveReload.d.ts +1 -0
  116. package/dist/types/ssr-runtime/devPlugin.d.ts +2 -0
  117. package/dist/types/ssr-runtime/downgrade.d.ts +4 -0
  118. package/dist/types/ssr-runtime/injectDataFetchFunctionPlugin.d.ts +7 -0
  119. package/dist/types/types/index.d.ts +24 -0
  120. package/dist/types/utils/dataFetch.d.ts +26 -0
  121. package/dist/types/utils/index.d.ts +15 -0
  122. package/package.json +37 -12
@@ -0,0 +1,185 @@
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 __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (let key of __getOwnPropNames(from))
11
+ if (!__hasOwnProp.call(to, key) && key !== except)
12
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
+ }
14
+ return to;
15
+ };
16
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
17
+ // If the importer is in node compatibility mode or this is not an ESM
18
+ // file that has been converted to a CommonJS file using a Babel-
19
+ // compatible transform (i.e. "__esModule" has not been set), then set
20
+ // "default" to the CommonJS "module.exports" for node compatibility.
21
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
+ mod
23
+ ));
24
+ var import_vitest = require("vitest");
25
+ var import_staticMiddleware = require("./staticMiddleware");
26
+ var import_fs_extra = __toESM(require("fs-extra"));
27
+ var import_fileCache = require("./fileCache");
28
+ import_vitest.vi.mock("fs-extra", () => ({
29
+ default: {
30
+ pathExists: import_vitest.vi.fn()
31
+ }
32
+ }));
33
+ import_vitest.vi.mock("./fileCache", () => ({
34
+ fileCache: {
35
+ getFile: import_vitest.vi.fn()
36
+ }
37
+ }));
38
+ (0, import_vitest.describe)("staticMiddleware", () => {
39
+ let middleware;
40
+ let mockContext;
41
+ let nextSpy;
42
+ (0, import_vitest.beforeEach)(() => {
43
+ import_vitest.vi.clearAllMocks();
44
+ middleware = (0, import_staticMiddleware.createStaticMiddleware)({
45
+ assetPrefix: "",
46
+ pwd: "/test/path"
47
+ });
48
+ nextSpy = import_vitest.vi.fn();
49
+ mockContext = {
50
+ req: {
51
+ path: ""
52
+ },
53
+ header: import_vitest.vi.fn(),
54
+ body: import_vitest.vi.fn()
55
+ };
56
+ });
57
+ (0, import_vitest.describe)("file extension filtering", () => {
58
+ (0, import_vitest.it)("should call next() for non-js files", async () => {
59
+ mockContext.req.path = "/bundles/test.css";
60
+ await middleware(mockContext, nextSpy);
61
+ (0, import_vitest.expect)(nextSpy).toHaveBeenCalledOnce();
62
+ (0, import_vitest.expect)(mockContext.header).not.toHaveBeenCalled();
63
+ (0, import_vitest.expect)(mockContext.body).not.toHaveBeenCalled();
64
+ });
65
+ (0, import_vitest.it)("should call next() for files without extension", async () => {
66
+ mockContext.req.path = "/bundles/test";
67
+ await middleware(mockContext, nextSpy);
68
+ (0, import_vitest.expect)(nextSpy).toHaveBeenCalledOnce();
69
+ (0, import_vitest.expect)(mockContext.header).not.toHaveBeenCalled();
70
+ (0, import_vitest.expect)(mockContext.body).not.toHaveBeenCalled();
71
+ });
72
+ (0, import_vitest.it)("should process .js files", async () => {
73
+ mockContext.req.path = "/bundles/test.js";
74
+ import_fs_extra.default.pathExists.mockResolvedValue(false);
75
+ await middleware(mockContext, nextSpy);
76
+ (0, import_vitest.expect)(import_fs_extra.default.pathExists).toHaveBeenCalled();
77
+ });
78
+ });
79
+ (0, import_vitest.describe)("asset prefix filtering", () => {
80
+ (0, import_vitest.it)("should call next() for paths not starting with /bundles", async () => {
81
+ mockContext.req.path = "/assets/test.js";
82
+ await middleware(mockContext, nextSpy);
83
+ (0, import_vitest.expect)(nextSpy).toHaveBeenCalledOnce();
84
+ (0, import_vitest.expect)(import_fs_extra.default.pathExists).not.toHaveBeenCalled();
85
+ (0, import_vitest.expect)(mockContext.header).not.toHaveBeenCalled();
86
+ (0, import_vitest.expect)(mockContext.body).not.toHaveBeenCalled();
87
+ });
88
+ (0, import_vitest.it)("should call next() for root path", async () => {
89
+ mockContext.req.path = "/test.js";
90
+ await middleware(mockContext, nextSpy);
91
+ (0, import_vitest.expect)(nextSpy).toHaveBeenCalledOnce();
92
+ (0, import_vitest.expect)(import_fs_extra.default.pathExists).not.toHaveBeenCalled();
93
+ });
94
+ (0, import_vitest.it)("should process paths starting with /bundles", async () => {
95
+ mockContext.req.path = "/bundles/test.js";
96
+ import_fs_extra.default.pathExists.mockResolvedValue(false);
97
+ await middleware(mockContext, nextSpy);
98
+ (0, import_vitest.expect)(import_fs_extra.default.pathExists).toHaveBeenCalledWith("/test/path/bundles/test.js");
99
+ });
100
+ });
101
+ (0, import_vitest.describe)("file existence check", () => {
102
+ (0, import_vitest.it)("should call next() when file does not exist", async () => {
103
+ mockContext.req.path = "/bundles/nonexistent.js";
104
+ import_fs_extra.default.pathExists.mockResolvedValue(false);
105
+ await middleware(mockContext, nextSpy);
106
+ (0, import_vitest.expect)(import_fs_extra.default.pathExists).toHaveBeenCalledWith("/test/path/bundles/nonexistent.js");
107
+ (0, import_vitest.expect)(nextSpy).toHaveBeenCalledOnce();
108
+ (0, import_vitest.expect)(import_fileCache.fileCache.getFile).not.toHaveBeenCalled();
109
+ (0, import_vitest.expect)(mockContext.header).not.toHaveBeenCalled();
110
+ (0, import_vitest.expect)(mockContext.body).not.toHaveBeenCalled();
111
+ });
112
+ (0, import_vitest.it)("should proceed to file cache when file exists", async () => {
113
+ mockContext.req.path = "/bundles/existing.js";
114
+ import_fs_extra.default.pathExists.mockResolvedValue(true);
115
+ import_fileCache.fileCache.getFile.mockResolvedValue(null);
116
+ await middleware(mockContext, nextSpy);
117
+ (0, import_vitest.expect)(import_fs_extra.default.pathExists).toHaveBeenCalledWith("/test/path/bundles/existing.js");
118
+ (0, import_vitest.expect)(import_fileCache.fileCache.getFile).toHaveBeenCalledWith("/test/path/bundles/existing.js");
119
+ });
120
+ });
121
+ (0, import_vitest.describe)("successful file serving", () => {
122
+ (0, import_vitest.it)("should serve file content with correct headers", async () => {
123
+ const mockFileContent = 'console.log("test");';
124
+ const mockFileResult = {
125
+ content: mockFileContent,
126
+ lastModified: Date.now()
127
+ };
128
+ mockContext.req.path = "/bundles/app.js";
129
+ import_fs_extra.default.pathExists.mockResolvedValue(true);
130
+ import_fileCache.fileCache.getFile.mockResolvedValue(mockFileResult);
131
+ mockContext.body.mockReturnValue("response");
132
+ const result = await middleware(mockContext, nextSpy);
133
+ (0, import_vitest.expect)(import_fs_extra.default.pathExists).toHaveBeenCalledWith("/test/path/bundles/app.js");
134
+ (0, import_vitest.expect)(import_fileCache.fileCache.getFile).toHaveBeenCalledWith("/test/path/bundles/app.js");
135
+ (0, import_vitest.expect)(nextSpy).not.toHaveBeenCalled();
136
+ (0, import_vitest.expect)(mockContext.header).toHaveBeenCalledWith("Content-Type", "application/javascript");
137
+ (0, import_vitest.expect)(mockContext.header).toHaveBeenCalledWith("Content-Length", String(mockFileResult.content.length));
138
+ (0, import_vitest.expect)(mockContext.body).toHaveBeenCalledWith(mockFileResult.content, 200);
139
+ (0, import_vitest.expect)(result).toBe("response");
140
+ });
141
+ (0, import_vitest.it)("should handle empty file content", async () => {
142
+ const mockFileResult = {
143
+ content: "",
144
+ lastModified: Date.now()
145
+ };
146
+ mockContext.req.path = "/bundles/empty.js";
147
+ import_fs_extra.default.pathExists.mockResolvedValue(true);
148
+ import_fileCache.fileCache.getFile.mockResolvedValue(mockFileResult);
149
+ mockContext.body.mockReturnValue("empty-response");
150
+ const result = await middleware(mockContext, nextSpy);
151
+ (0, import_vitest.expect)(mockContext.header).toHaveBeenCalledWith("Content-Length", "0");
152
+ (0, import_vitest.expect)(mockContext.body).toHaveBeenCalledWith(mockFileResult.content, 200);
153
+ (0, import_vitest.expect)(result).toBe("empty-response");
154
+ (0, import_vitest.expect)(nextSpy).not.toHaveBeenCalled();
155
+ });
156
+ });
157
+ (0, import_vitest.describe)("asset prefix handling", () => {
158
+ (0, import_vitest.it)("should handle custom asset prefix correctly", async () => {
159
+ const customMiddleware = (0, import_staticMiddleware.createStaticMiddleware)({
160
+ assetPrefix: "/custom-prefix",
161
+ pwd: "/test/path"
162
+ });
163
+ mockContext.req.path = "/bundles/test.js";
164
+ await customMiddleware(mockContext, nextSpy);
165
+ (0, import_vitest.expect)(nextSpy).toHaveBeenCalledOnce();
166
+ (0, import_vitest.expect)(mockContext.header).not.toHaveBeenCalled();
167
+ (0, import_vitest.expect)(mockContext.body).not.toHaveBeenCalled();
168
+ });
169
+ (0, import_vitest.it)("should handle asset prefix removal correctly", async () => {
170
+ const customMiddleware = (0, import_staticMiddleware.createStaticMiddleware)({
171
+ assetPrefix: "/prefix",
172
+ pwd: "/test/path"
173
+ });
174
+ const mockFileResult = {
175
+ content: "test content",
176
+ lastModified: Date.now()
177
+ };
178
+ mockContext.req.path = "/prefix/bundles/test.js";
179
+ import_fs_extra.default.pathExists.mockResolvedValue(true);
180
+ import_fileCache.fileCache.getFile.mockResolvedValue(mockFileResult);
181
+ await customMiddleware(mockContext, nextSpy);
182
+ (0, import_vitest.expect)(import_fs_extra.default.pathExists).toHaveBeenCalledWith("/test/path/bundles/test.js");
183
+ });
184
+ });
185
+ });
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var SSRLiveReload_exports = {};
20
+ __export(SSRLiveReload_exports, {
21
+ SSRLiveReload: () => SSRLiveReload
22
+ });
23
+ module.exports = __toCommonJS(SSRLiveReload_exports);
24
+ var import_jsx_runtime = require("react/jsx-runtime");
25
+ function SSRLiveReload() {
26
+ if (process.env.NODE_ENV !== "development") {
27
+ return null;
28
+ }
29
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("script", {
30
+ suppressHydrationWarning: true,
31
+ dangerouslySetInnerHTML: {
32
+ __html: String.raw`
33
+ if(${globalThis.shouldUpdate}){
34
+ location.reload();
35
+ }
36
+ `
37
+ }
38
+ });
39
+ }
40
+ // Annotate the CommonJS export names for ESM import in node:
41
+ 0 && (module.exports = {
42
+ SSRLiveReload
43
+ });
@@ -0,0 +1,71 @@
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 devPlugin_exports = {};
30
+ __export(devPlugin_exports, {
31
+ mfSSRDevPlugin: () => mfSSRDevPlugin
32
+ });
33
+ module.exports = __toCommonJS(devPlugin_exports);
34
+ var import_jsx_runtime = require("react/jsx-runtime");
35
+ var import_SSRLiveReload = require("./SSRLiveReload");
36
+ var import_utils = require("../utils");
37
+ const mfSSRDevPlugin = () => ({
38
+ name: "@module-federation/modern-js",
39
+ setup: (api) => {
40
+ api.onBeforeRender(async () => {
41
+ if (typeof window !== "undefined") {
42
+ return;
43
+ }
44
+ globalThis.shouldUpdate = false;
45
+ const nodeUtils = await Promise.resolve().then(() => __toESM(require("@module-federation/node/utils")));
46
+ const shouldUpdate = await nodeUtils.revalidate();
47
+ console.log("shouldUpdate: ", shouldUpdate);
48
+ if (shouldUpdate) {
49
+ console.log("should RELOAD", shouldUpdate);
50
+ await nodeUtils.flushChunks();
51
+ (0, import_utils.flushDataFetch)();
52
+ globalThis.shouldUpdate = true;
53
+ }
54
+ });
55
+ api.wrapRoot((App) => {
56
+ const AppWrapper = (props) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
57
+ children: [
58
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_SSRLiveReload.SSRLiveReload, {}),
59
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, {
60
+ ...props
61
+ })
62
+ ]
63
+ });
64
+ return AppWrapper;
65
+ });
66
+ }
67
+ });
68
+ // Annotate the CommonJS export names for ESM import in node:
69
+ 0 && (module.exports = {
70
+ mfSSRDevPlugin
71
+ });
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var downgrade_exports = {};
20
+ __export(downgrade_exports, {
21
+ callAllDowngrade: () => callAllDowngrade,
22
+ callDowngrade: () => callDowngrade,
23
+ getDowngradeTag: () => getDowngradeTag
24
+ });
25
+ module.exports = __toCommonJS(downgrade_exports);
26
+ var import_constant = require("../constant");
27
+ var import_constant2 = require("../constant");
28
+ var import_utils = require("../utils");
29
+ function getDowngradeTag() {
30
+ return globalThis[import_constant.DOWNGRADE_KEY];
31
+ }
32
+ function callAllDowngrade() {
33
+ const dataFetchMap = (0, import_utils.getDataFetchMap)();
34
+ if (!dataFetchMap) {
35
+ return;
36
+ }
37
+ Object.keys(dataFetchMap).forEach((key) => {
38
+ callDowngrade(key);
39
+ });
40
+ }
41
+ async function callDowngrade(id, params, remoteInfo) {
42
+ const dataFetchMap = (0, import_utils.getDataFetchMap)();
43
+ if (!dataFetchMap) {
44
+ return;
45
+ }
46
+ const mfDataFetch = dataFetchMap[id];
47
+ if ((mfDataFetch === null || mfDataFetch === void 0 ? void 0 : mfDataFetch[2]) === import_constant2.MF_DATA_FETCH_STATUS.AWAIT) {
48
+ mfDataFetch[2] = import_constant2.MF_DATA_FETCH_STATUS.LOADING;
49
+ let promise, res, rej;
50
+ if (mfDataFetch[1]) {
51
+ promise = mfDataFetch[1][0];
52
+ res = mfDataFetch[1][1];
53
+ rej = mfDataFetch[1][2];
54
+ } else {
55
+ promise = new Promise((resolve, reject) => {
56
+ res = resolve;
57
+ rej = reject;
58
+ });
59
+ mfDataFetch[1] = [
60
+ promise,
61
+ res,
62
+ rej
63
+ ];
64
+ }
65
+ const dataFetchType = mfDataFetch[0][1];
66
+ if (dataFetchType === import_constant2.MF_DATA_FETCH_TYPE.FETCH_CLIENT) {
67
+ try {
68
+ mfDataFetch[0][0]().then((getDataFetchFn) => {
69
+ return getDataFetchFn({
70
+ ...params,
71
+ isDowngrade: true
72
+ }).then((data) => {
73
+ mfDataFetch[2] = import_constant2.MF_DATA_FETCH_STATUS.LOADED;
74
+ res(data);
75
+ });
76
+ });
77
+ } catch (e) {
78
+ mfDataFetch[2] = import_constant2.MF_DATA_FETCH_STATUS.ERROR;
79
+ rej(e);
80
+ }
81
+ } else if (dataFetchType === import_constant2.MF_DATA_FETCH_TYPE.FETCH_SERVER) {
82
+ try {
83
+ const currentUrl = new URL(window.location.href);
84
+ currentUrl.searchParams.set(import_constant.DATA_FETCH_QUERY, encodeURIComponent(id));
85
+ if (params) {
86
+ currentUrl.searchParams.set("params", encodeURIComponent(JSON.stringify(params)));
87
+ }
88
+ if (remoteInfo) {
89
+ currentUrl.searchParams.set("remoteInfo", encodeURIComponent(JSON.stringify(remoteInfo)));
90
+ }
91
+ const fetchServerQuery = globalThis.FEDERATION_SERVER_QUERY;
92
+ if (fetchServerQuery && typeof fetchServerQuery === "object") {
93
+ Object.keys(fetchServerQuery).forEach((key) => {
94
+ currentUrl.searchParams.set(key, JSON.stringify(fetchServerQuery[key]));
95
+ });
96
+ }
97
+ const fetchUrl = currentUrl.toString();
98
+ const data = await fetch(fetchUrl).then((res2) => res2.json());
99
+ mfDataFetch[2] = import_constant2.MF_DATA_FETCH_STATUS.LOADED;
100
+ res(data);
101
+ } catch (e) {
102
+ mfDataFetch[2] = import_constant2.MF_DATA_FETCH_STATUS.ERROR;
103
+ rej(e);
104
+ }
105
+ }
106
+ return promise;
107
+ }
108
+ }
109
+ // Annotate the CommonJS export names for ESM import in node:
110
+ 0 && (module.exports = {
111
+ callAllDowngrade,
112
+ callDowngrade,
113
+ getDowngradeTag
114
+ });
@@ -0,0 +1,136 @@
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 injectDataFetchFunctionPlugin_exports = {};
30
+ __export(injectDataFetchFunctionPlugin_exports, {
31
+ injectDataFetchFunctionPlugin: () => injectDataFetchFunctionPlugin,
32
+ setSSREnv: () => setSSREnv
33
+ });
34
+ module.exports = __toCommonJS(injectDataFetchFunctionPlugin_exports);
35
+ var import_constant = require("../constant");
36
+ var import_logger = __toESM(require("../logger"));
37
+ var import_utils = require("../utils");
38
+ var import_downgrade = require("./downgrade");
39
+ function setSSREnv({ fetchServerQuery }) {
40
+ globalThis.FEDERATION_SSR = true;
41
+ globalThis.FEDERATION_SERVER_QUERY = fetchServerQuery;
42
+ }
43
+ const injectDataFetchFunctionPlugin = ({ fetchServerQuery }) => ({
44
+ name: "@module-federation/inject-data-fetch-function-plugin",
45
+ setup: (api) => {
46
+ api.onBeforeRender(async () => {
47
+ var _globalThis, _DATA_FETCH_FUNCTION;
48
+ setSSREnv({
49
+ fetchServerQuery
50
+ });
51
+ if (typeof window === "undefined") {
52
+ return;
53
+ }
54
+ const dataFetchFunction = async function(options) {
55
+ const [id, data, downgrade] = options;
56
+ import_logger.default.debug("==========call data fetch function!");
57
+ if (data) {
58
+ if (!id) {
59
+ throw new Error("id is required!");
60
+ }
61
+ if (!(0, import_utils.getDataFetchMap)()) {
62
+ (0, import_utils.initDataFetchMap)();
63
+ }
64
+ const dataFetchItem = (0, import_utils.getDataFetchItem)(id);
65
+ if (dataFetchItem) {
66
+ var _dataFetchItem__, _dataFetchItem_;
67
+ (_dataFetchItem_ = dataFetchItem[1]) === null || _dataFetchItem_ === void 0 ? void 0 : (_dataFetchItem__ = _dataFetchItem_[1]) === null || _dataFetchItem__ === void 0 ? void 0 : _dataFetchItem__.call(_dataFetchItem_, data);
68
+ dataFetchItem[2] = import_constant.MF_DATA_FETCH_STATUS.LOADED;
69
+ return;
70
+ }
71
+ if (!dataFetchItem) {
72
+ const dataFetchMap = (0, import_utils.getDataFetchMap)();
73
+ let res;
74
+ let rej;
75
+ const p = new Promise((resolve, reject) => {
76
+ res = resolve;
77
+ rej = reject;
78
+ });
79
+ dataFetchMap[id] = [
80
+ [
81
+ async () => async () => {
82
+ return "";
83
+ },
84
+ import_constant.MF_DATA_FETCH_TYPE.FETCH_SERVER
85
+ ],
86
+ [
87
+ p,
88
+ res,
89
+ rej
90
+ ],
91
+ import_constant.MF_DATA_FETCH_STATUS.LOADED
92
+ ];
93
+ res(data);
94
+ return;
95
+ }
96
+ }
97
+ if (downgrade) {
98
+ const mfDowngrade2 = (0, import_downgrade.getDowngradeTag)();
99
+ if (!mfDowngrade2) {
100
+ globalThis[import_constant.DOWNGRADE_KEY] = id ? [
101
+ id
102
+ ] : true;
103
+ } else if (Array.isArray(mfDowngrade2) && id && !mfDowngrade2.includes(id)) {
104
+ mfDowngrade2.push(id);
105
+ }
106
+ }
107
+ const mfDowngrade = (0, import_downgrade.getDowngradeTag)();
108
+ if (typeof mfDowngrade === "boolean") {
109
+ return (0, import_downgrade.callAllDowngrade)();
110
+ }
111
+ if (Array.isArray(mfDowngrade)) {
112
+ if (!id) {
113
+ globalThis[import_constant.DOWNGRADE_KEY] = true;
114
+ return (0, import_downgrade.callAllDowngrade)();
115
+ }
116
+ if (!mfDowngrade.includes(id)) {
117
+ mfDowngrade.push(id);
118
+ }
119
+ return (0, import_downgrade.callDowngrade)(id);
120
+ }
121
+ };
122
+ globalThis[import_constant.FS_HREF] = window.location.href;
123
+ (_globalThis = globalThis)[_DATA_FETCH_FUNCTION = import_constant.DATA_FETCH_FUNCTION] || (_globalThis[_DATA_FETCH_FUNCTION] = []);
124
+ const dataFetch = globalThis[import_constant.DATA_FETCH_FUNCTION];
125
+ await Promise.all(dataFetch.map(async (options) => {
126
+ await dataFetchFunction(options);
127
+ }));
128
+ dataFetch.push = dataFetchFunction;
129
+ });
130
+ }
131
+ });
132
+ // Annotate the CommonJS export names for ESM import in node:
133
+ 0 && (module.exports = {
134
+ injectDataFetchFunctionPlugin,
135
+ setSSREnv
136
+ });
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var types_exports = {};
16
+ module.exports = __toCommonJS(types_exports);