@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,31 +0,0 @@
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 constant_exports = {};
20
- __export(constant_exports, {
21
- LOCALHOST: () => LOCALHOST,
22
- PLUGIN_IDENTIFIER: () => PLUGIN_IDENTIFIER
23
- });
24
- module.exports = __toCommonJS(constant_exports);
25
- const LOCALHOST = "localhost";
26
- const PLUGIN_IDENTIFIER = "[ Modern.js Module Federation ]";
27
- // Annotate the CommonJS export names for ESM import in node:
28
- 0 && (module.exports = {
29
- LOCALHOST,
30
- PLUGIN_IDENTIFIER
31
- });
@@ -1,16 +0,0 @@
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 bundler_exports = {};
16
- module.exports = __toCommonJS(bundler_exports);
@@ -1,27 +0,0 @@
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 logger_exports = {};
20
- __export(logger_exports, {
21
- default: () => logger_default
22
- });
23
- module.exports = __toCommonJS(logger_exports);
24
- var import_sdk = require("@module-federation/sdk");
25
- var import_constant = require("./constant");
26
- const logger = (0, import_sdk.createLogger)(import_constant.PLUGIN_IDENTIFIER);
27
- var logger_default = logger;
@@ -1,33 +0,0 @@
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 __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
19
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
- var runtime_exports = {};
21
- __export(runtime_exports, {
22
- ERROR_TYPE: () => import_bridge_react.ERROR_TYPE,
23
- kit: () => import_bridge_react.kit
24
- });
25
- module.exports = __toCommonJS(runtime_exports);
26
- __reExport(runtime_exports, require("@module-federation/enhanced/runtime"), module.exports);
27
- var import_bridge_react = require("@module-federation/bridge-react");
28
- // Annotate the CommonJS export names for ESM import in node:
29
- 0 && (module.exports = {
30
- ERROR_TYPE,
31
- kit,
32
- ...require("@module-federation/enhanced/runtime")
33
- });
@@ -1,84 +0,0 @@
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 fileCache_exports = {};
30
- __export(fileCache_exports, {
31
- FileCache: () => FileCache,
32
- fileCache: () => fileCache
33
- });
34
- module.exports = __toCommonJS(fileCache_exports);
35
- var import_fs_extra = __toESM(require("fs-extra"));
36
- var import_lru_cache = require("lru-cache");
37
- class FileCache {
38
- /**
39
- * Check if file exists and return file info
40
- * @param filepath Path to the file
41
- * @returns FileResult or null if file doesn't exist
42
- */
43
- async getFile(filepath) {
44
- if (!await import_fs_extra.default.pathExists(filepath)) {
45
- return null;
46
- }
47
- try {
48
- const stat = await import_fs_extra.default.lstat(filepath);
49
- const currentModified = stat.mtimeMs;
50
- const cachedEntry = this.cache.get(filepath);
51
- if (cachedEntry && currentModified <= cachedEntry.lastModified) {
52
- return {
53
- content: cachedEntry.content,
54
- lastModified: cachedEntry.lastModified
55
- };
56
- }
57
- const content = await import_fs_extra.default.readFile(filepath, "utf-8");
58
- const newEntry = {
59
- content,
60
- lastModified: currentModified
61
- };
62
- this.cache.set(filepath, newEntry, {
63
- size: stat.size || content.length
64
- });
65
- return {
66
- content,
67
- lastModified: currentModified
68
- };
69
- } catch (err) {
70
- return null;
71
- }
72
- }
73
- constructor() {
74
- this.cache = new import_lru_cache.LRUCache({
75
- maxSize: 200 * 1024 * 1024
76
- });
77
- }
78
- }
79
- const fileCache = new FileCache();
80
- // Annotate the CommonJS export names for ESM import in node:
81
- 0 && (module.exports = {
82
- FileCache,
83
- fileCache
84
- });
@@ -1,28 +0,0 @@
1
- "use strict";
2
- var import_vitest = require("vitest");
3
- var import_fileCache = require("./fileCache");
4
- (0, import_vitest.beforeAll)(() => {
5
- import_vitest.vi.mock("fs-extra", () => ({
6
- default: {
7
- pathExists: () => {
8
- return true;
9
- },
10
- lstat: () => {
11
- return {
12
- mtimeMs: Date.now(),
13
- size: 4
14
- };
15
- },
16
- readFile: () => {
17
- return "test";
18
- }
19
- }
20
- }));
21
- });
22
- (0, import_vitest.describe)("modern serve static file cache", async () => {
23
- (0, import_vitest.it)("should cache file", async () => {
24
- const cache = new import_fileCache.FileCache();
25
- const result = await cache.getFile("test.txt");
26
- (0, import_vitest.expect)(result === null || result === void 0 ? void 0 : result.content).toBe("test");
27
- });
28
- });
@@ -1,58 +0,0 @@
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 server_exports = {};
20
- __export(server_exports, {
21
- default: () => server_default,
22
- staticServePlugin: () => staticServePlugin
23
- });
24
- module.exports = __toCommonJS(server_exports);
25
- var import_staticMiddleware = require("./staticMiddleware");
26
- const staticServePlugin = () => ({
27
- name: "@modern-js/module-federation/server",
28
- setup: (api) => {
29
- api.onPrepare(() => {
30
- var _config_output, _config_server;
31
- console.log(process.env.NODE_ENV);
32
- if (process.env.NODE_ENV === "development") {
33
- return;
34
- }
35
- const { middlewares } = api.getServerContext();
36
- const config = api.getServerConfig();
37
- const assetPrefix = ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.assetPrefix) || "";
38
- if (!((_config_server = config.server) === null || _config_server === void 0 ? void 0 : _config_server.ssr)) {
39
- return;
40
- }
41
- const context = api.getServerContext();
42
- const pwd = context.distDirectory;
43
- const serverStaticMiddleware = (0, import_staticMiddleware.createStaticMiddleware)({
44
- assetPrefix,
45
- pwd
46
- });
47
- middlewares.push({
48
- name: "module-federation-serve-manifest",
49
- handler: serverStaticMiddleware
50
- });
51
- });
52
- }
53
- });
54
- var server_default = staticServePlugin;
55
- // Annotate the CommonJS export names for ESM import in node:
56
- 0 && (module.exports = {
57
- staticServePlugin
58
- });
@@ -1,77 +0,0 @@
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 staticMiddleware_exports = {};
30
- __export(staticMiddleware_exports, {
31
- createStaticMiddleware: () => createStaticMiddleware
32
- });
33
- module.exports = __toCommonJS(staticMiddleware_exports);
34
- var import_fs_extra = __toESM(require("fs-extra"));
35
- var import_node_path = __toESM(require("node:path"));
36
- var import_fileCache = require("./fileCache");
37
- const bundlesAssetPrefix = "/bundles";
38
- const removeHost = (url) => {
39
- try {
40
- const hasProtocol = url.includes("://");
41
- const hasDomain = hasProtocol || url.startsWith("//");
42
- const pathname = hasDomain ? new URL(hasProtocol ? url : `http:${url}`).pathname : url;
43
- return pathname;
44
- } catch (e) {
45
- return url;
46
- }
47
- };
48
- const createStaticMiddleware = (options) => {
49
- const { assetPrefix, pwd } = options;
50
- return async (c, next) => {
51
- const pathname = c.req.path;
52
- if (import_node_path.default.extname(pathname) !== ".js") {
53
- return next();
54
- }
55
- const prefixWithoutHost = removeHost(assetPrefix);
56
- const prefixWithBundle = import_node_path.default.join(prefixWithoutHost, bundlesAssetPrefix);
57
- if (!pathname.startsWith(prefixWithBundle)) {
58
- return next();
59
- }
60
- const pathnameWithoutPrefix = pathname.replace(prefixWithBundle, "");
61
- const filepath = import_node_path.default.join(pwd, bundlesAssetPrefix, pathnameWithoutPrefix);
62
- if (!await import_fs_extra.default.pathExists(filepath)) {
63
- return next();
64
- }
65
- const fileResult = await import_fileCache.fileCache.getFile(filepath);
66
- if (!fileResult) {
67
- return next();
68
- }
69
- c.header("Content-Type", "application/javascript");
70
- c.header("Content-Length", String(fileResult.content.length));
71
- return c.body(fileResult.content, 200);
72
- };
73
- };
74
- // Annotate the CommonJS export names for ESM import in node:
75
- 0 && (module.exports = {
76
- createStaticMiddleware
77
- });
@@ -1,185 +0,0 @@
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
- });
@@ -1,43 +0,0 @@
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
- });
@@ -1,71 +0,0 @@
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_data_fetch_utils = require("@module-federation/bridge-react/data-fetch-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_data_fetch_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
- });