@module-federation/modern-js 0.0.0-next-20250526074234 → 0.0.0-next-20250527094526
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/cli/configPlugin.js +6 -8
- package/dist/cjs/cli/configPlugin.spec.js +1 -3
- package/dist/cjs/{runtime/wrapNoSSR.js → cli/constant.js} +6 -13
- package/dist/cjs/cli/index.js +9 -3
- package/dist/cjs/{logger.js → cli/logger.js} +1 -1
- package/dist/cjs/cli/manifest.js +3 -3
- package/dist/cjs/cli/ssrPlugin.js +15 -34
- package/dist/cjs/cli/utils.js +0 -5
- package/dist/cjs/constant.js +2 -49
- package/dist/cjs/runtime/createRemoteSSRComponent.js +201 -0
- package/dist/cjs/runtime/index.js +3 -15
- package/dist/cjs/server/fileCache.js +84 -0
- package/dist/cjs/server/fileCache.spec.js +28 -0
- package/dist/cjs/server/index.js +58 -0
- package/dist/cjs/server/staticMiddleware.js +77 -0
- package/dist/cjs/server/staticMiddleware.spec.js +185 -0
- package/dist/cjs/{interfaces/global.js → ssr-runtime/index.js} +8 -2
- package/dist/cjs/ssr-runtime/{devPlugin.js → plugin.js} +6 -9
- package/dist/esm/cli/configPlugin.js +7 -9
- package/dist/esm/cli/configPlugin.spec.js +1 -3
- package/dist/esm/cli/constant.js +4 -0
- package/dist/esm/cli/index.js +10 -3
- package/dist/esm/{logger.js → cli/logger.js} +1 -1
- package/dist/esm/cli/manifest.js +1 -1
- package/dist/esm/cli/ssrPlugin.js +8 -28
- package/dist/esm/cli/utils.js +0 -4
- package/dist/esm/constant.js +1 -37
- package/dist/esm/runtime/createRemoteSSRComponent.js +191 -0
- package/dist/esm/runtime/index.js +3 -13
- package/dist/esm/server/fileCache.js +98 -0
- package/dist/esm/server/fileCache.spec.js +50 -0
- package/dist/esm/server/index.js +36 -0
- package/dist/esm/server/staticMiddleware.js +81 -0
- package/dist/esm/server/staticMiddleware.spec.js +328 -0
- package/dist/esm/ssr-runtime/index.js +1 -0
- package/dist/esm/ssr-runtime/{devPlugin.js → plugin.js} +2 -5
- package/dist/esm-node/cli/configPlugin.js +7 -9
- package/dist/esm-node/cli/configPlugin.spec.js +1 -3
- package/dist/esm-node/cli/constant.js +4 -0
- package/dist/esm-node/cli/index.js +9 -3
- package/dist/esm-node/{logger.js → cli/logger.js} +1 -1
- package/dist/esm-node/cli/manifest.js +1 -1
- package/dist/esm-node/cli/ssrPlugin.js +8 -27
- package/dist/esm-node/cli/utils.js +0 -4
- package/dist/esm-node/constant.js +1 -37
- package/dist/esm-node/runtime/createRemoteSSRComponent.js +166 -0
- package/dist/esm-node/runtime/index.js +3 -13
- package/dist/esm-node/server/fileCache.js +49 -0
- package/dist/esm-node/server/fileCache.spec.js +27 -0
- package/dist/esm-node/server/index.js +34 -0
- package/dist/esm-node/server/staticMiddleware.js +43 -0
- package/dist/esm-node/server/staticMiddleware.spec.js +162 -0
- package/dist/esm-node/ssr-runtime/index.js +1 -0
- package/dist/esm-node/ssr-runtime/{devPlugin.js → plugin.js} +2 -5
- package/dist/types/cli/constant.d.ts +1 -0
- package/dist/types/cli/index.d.ts +0 -1
- package/dist/types/cli/utils.d.ts +0 -1
- package/dist/types/constant.d.ts +0 -23
- package/dist/types/runtime/createRemoteSSRComponent.d.ts +18 -0
- package/dist/types/runtime/index.d.ts +2 -7
- package/dist/types/server/fileCache.d.ts +14 -0
- package/dist/types/server/fileCache.spec.d.ts +1 -0
- package/dist/types/server/index.d.ts +4 -0
- package/dist/types/server/staticMiddleware.d.ts +6 -0
- package/dist/types/server/staticMiddleware.spec.d.ts +1 -0
- package/dist/types/ssr-runtime/index.d.ts +1 -0
- package/dist/types/ssr-runtime/plugin.d.ts +2 -0
- package/dist/types/types/index.d.ts +0 -2
- package/package.json +23 -39
- package/dist/cjs/cli/mfRuntimePlugins/auto-fetch-data.js +0 -98
- package/dist/cjs/cli/server/data-fetch-server-plugin.js +0 -192
- package/dist/cjs/runtime/AwaitDataFetch.js +0 -144
- package/dist/cjs/runtime/createRemoteComponent.js +0 -327
- package/dist/cjs/ssr-runtime/downgrade.js +0 -114
- package/dist/cjs/ssr-runtime/injectDataFetchFunctionPlugin.js +0 -136
- package/dist/cjs/utils/dataFetch.js +0 -211
- package/dist/cjs/utils/index.js +0 -54
- package/dist/esm/cli/mfRuntimePlugins/auto-fetch-data.js +0 -74
- package/dist/esm/cli/server/data-fetch-server-plugin.js +0 -240
- package/dist/esm/interfaces/global.js +0 -0
- package/dist/esm/runtime/AwaitDataFetch.js +0 -131
- package/dist/esm/runtime/createRemoteComponent.js +0 -417
- package/dist/esm/runtime/wrapNoSSR.js +0 -12
- package/dist/esm/ssr-runtime/downgrade.js +0 -150
- package/dist/esm/ssr-runtime/injectDataFetchFunctionPlugin.js +0 -177
- package/dist/esm/utils/dataFetch.js +0 -237
- package/dist/esm/utils/index.js +0 -28
- package/dist/esm-node/cli/mfRuntimePlugins/auto-fetch-data.js +0 -68
- package/dist/esm-node/cli/server/data-fetch-server-plugin.js +0 -162
- package/dist/esm-node/interfaces/global.js +0 -0
- package/dist/esm-node/runtime/AwaitDataFetch.js +0 -109
- package/dist/esm-node/runtime/createRemoteComponent.js +0 -291
- package/dist/esm-node/runtime/wrapNoSSR.js +0 -11
- package/dist/esm-node/ssr-runtime/downgrade.js +0 -88
- package/dist/esm-node/ssr-runtime/injectDataFetchFunctionPlugin.js +0 -101
- package/dist/esm-node/utils/dataFetch.js +0 -166
- package/dist/esm-node/utils/index.js +0 -27
- package/dist/types/cli/mfRuntimePlugins/auto-fetch-data.d.ts +0 -3
- package/dist/types/cli/server/data-fetch-server-plugin.d.ts +0 -3
- package/dist/types/interfaces/global.d.ts +0 -27
- package/dist/types/runtime/AwaitDataFetch.d.ts +0 -19
- package/dist/types/runtime/createRemoteComponent.d.ts +0 -26
- package/dist/types/runtime/wrapNoSSR.d.ts +0 -9
- package/dist/types/ssr-runtime/devPlugin.d.ts +0 -2
- package/dist/types/ssr-runtime/downgrade.d.ts +0 -4
- package/dist/types/ssr-runtime/injectDataFetchFunctionPlugin.d.ts +0 -7
- package/dist/types/utils/dataFetch.d.ts +0 -26
- package/dist/types/utils/index.d.ts +0 -15
- /package/dist/types/{logger.d.ts → cli/logger.d.ts} +0 -0
|
@@ -0,0 +1,84 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,77 @@
|
|
|
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
|
+
});
|
|
@@ -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
|
+
});
|
|
@@ -11,6 +11,12 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
11
11
|
}
|
|
12
12
|
return to;
|
|
13
13
|
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
14
15
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
-
var
|
|
16
|
-
module.exports = __toCommonJS(
|
|
16
|
+
var ssr_runtime_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(ssr_runtime_exports);
|
|
18
|
+
__reExport(ssr_runtime_exports, require("./plugin"), module.exports);
|
|
19
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
20
|
+
0 && (module.exports = {
|
|
21
|
+
...require("./plugin")
|
|
22
|
+
});
|
|
@@ -26,15 +26,14 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var
|
|
30
|
-
__export(
|
|
31
|
-
|
|
29
|
+
var plugin_exports = {};
|
|
30
|
+
__export(plugin_exports, {
|
|
31
|
+
mfSSRPlugin: () => mfSSRPlugin
|
|
32
32
|
});
|
|
33
|
-
module.exports = __toCommonJS(
|
|
33
|
+
module.exports = __toCommonJS(plugin_exports);
|
|
34
34
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
35
35
|
var import_SSRLiveReload = require("./SSRLiveReload");
|
|
36
|
-
|
|
37
|
-
const mfSSRDevPlugin = () => ({
|
|
36
|
+
const mfSSRPlugin = () => ({
|
|
38
37
|
name: "@module-federation/modern-js",
|
|
39
38
|
setup: (api) => {
|
|
40
39
|
api.onBeforeRender(async () => {
|
|
@@ -44,11 +43,9 @@ const mfSSRDevPlugin = () => ({
|
|
|
44
43
|
globalThis.shouldUpdate = false;
|
|
45
44
|
const nodeUtils = await Promise.resolve().then(() => __toESM(require("@module-federation/node/utils")));
|
|
46
45
|
const shouldUpdate = await nodeUtils.revalidate();
|
|
47
|
-
console.log("shouldUpdate: ", shouldUpdate);
|
|
48
46
|
if (shouldUpdate) {
|
|
49
47
|
console.log("should RELOAD", shouldUpdate);
|
|
50
48
|
await nodeUtils.flushChunks();
|
|
51
|
-
(0, import_utils.flushDataFetch)();
|
|
52
49
|
globalThis.shouldUpdate = true;
|
|
53
50
|
}
|
|
54
51
|
});
|
|
@@ -67,5 +64,5 @@ const mfSSRDevPlugin = () => ({
|
|
|
67
64
|
});
|
|
68
65
|
// Annotate the CommonJS export names for ESM import in node:
|
|
69
66
|
0 && (module.exports = {
|
|
70
|
-
|
|
67
|
+
mfSSRPlugin
|
|
71
68
|
});
|
|
@@ -9,10 +9,10 @@ import { getIPV4, isWebTarget, skipByTarget } from "./utils";
|
|
|
9
9
|
import { encodeName } from "@module-federation/sdk";
|
|
10
10
|
import { bundle } from "@modern-js/node-bundle-require";
|
|
11
11
|
import { LOCALHOST, PLUGIN_IDENTIFIER } from "../constant";
|
|
12
|
-
import { autoDeleteSplitChunkCacheGroups
|
|
13
|
-
import logger from "
|
|
14
|
-
import { isDev } from "./utils";
|
|
12
|
+
import { autoDeleteSplitChunkCacheGroups } from "@module-federation/rsbuild-plugin/utils";
|
|
13
|
+
import logger from "./logger";
|
|
15
14
|
var defaultPath = path.resolve(process.cwd(), "module-federation.config.ts");
|
|
15
|
+
var isDev = process.env.NODE_ENV === "development";
|
|
16
16
|
function setEnv(enableSSR) {
|
|
17
17
|
if (enableSSR) {
|
|
18
18
|
process.env["MF_DISABLE_EMIT_STATS"] = "true";
|
|
@@ -128,7 +128,6 @@ var patchDTSConfig = function(mfConfig, isServer) {
|
|
|
128
128
|
};
|
|
129
129
|
var patchMFConfig = function(mfConfig, isServer, remoteIpStrategy) {
|
|
130
130
|
replaceRemoteUrl(mfConfig, remoteIpStrategy);
|
|
131
|
-
addDataFetchExposes(mfConfig.exposes, isServer);
|
|
132
131
|
if (mfConfig.remoteType === void 0) {
|
|
133
132
|
mfConfig.remoteType = "script";
|
|
134
133
|
}
|
|
@@ -138,13 +137,12 @@ var patchMFConfig = function(mfConfig, isServer, remoteIpStrategy) {
|
|
|
138
137
|
var runtimePlugins = _to_consumable_array(mfConfig.runtimePlugins || []);
|
|
139
138
|
patchDTSConfig(mfConfig, isServer);
|
|
140
139
|
injectRuntimePlugins(require.resolve("@module-federation/modern-js/shared-strategy"), runtimePlugins);
|
|
141
|
-
|
|
142
|
-
if (isDev()) {
|
|
140
|
+
if (isDev) {
|
|
143
141
|
injectRuntimePlugins(require.resolve("@module-federation/modern-js/resolve-entry-ipv4"), runtimePlugins);
|
|
144
142
|
}
|
|
145
143
|
if (isServer) {
|
|
146
144
|
injectRuntimePlugins(require.resolve("@module-federation/node/runtimePlugin"), runtimePlugins);
|
|
147
|
-
if (isDev
|
|
145
|
+
if (isDev) {
|
|
148
146
|
injectRuntimePlugins(require.resolve("@module-federation/node/record-dynamic-remote-entry-hash-plugin"), runtimePlugins);
|
|
149
147
|
}
|
|
150
148
|
injectRuntimePlugins(require.resolve("@module-federation/modern-js/inject-node-fetch"), runtimePlugins);
|
|
@@ -242,7 +240,7 @@ function patchBundlerConfig(options) {
|
|
|
242
240
|
splitChunkConfig.chunks = "async";
|
|
243
241
|
logger.warn('splitChunks.chunks = async is not allowed with stream SSR mode, it will auto changed to "async"');
|
|
244
242
|
}
|
|
245
|
-
if (isDev
|
|
243
|
+
if (isDev && chain.output.get("publicPath") === "auto") {
|
|
246
244
|
var _modernjsConfig_dev, _modernjsConfig_server;
|
|
247
245
|
var port = ((_modernjsConfig_dev = modernjsConfig.dev) === null || _modernjsConfig_dev === void 0 ? void 0 : _modernjsConfig_dev.port) || ((_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.port) || 8080;
|
|
248
246
|
var publicPath = "http://localhost:".concat(port, "/");
|
|
@@ -256,7 +254,7 @@ function patchBundlerConfig(options) {
|
|
|
256
254
|
chain.output.chunkFilename(chunkFileName.replace(".js", suffix));
|
|
257
255
|
}
|
|
258
256
|
}
|
|
259
|
-
if (isDev
|
|
257
|
+
if (isDev && enableSSR && !isServer) {
|
|
260
258
|
chain.resolve.fallback.set("crypto", false).set("stream", false).set("vm", false);
|
|
261
259
|
}
|
|
262
260
|
if (((_modernjsConfig_deploy = modernjsConfig.deploy) === null || _modernjsConfig_deploy === void 0 ? void 0 : _modernjsConfig_deploy.microFrontend) && Object.keys(mfConfig.exposes || {}).length) {
|
|
@@ -43,7 +43,6 @@ describe("patchMFConfig", /* @__PURE__ */ _async_to_generator(function() {
|
|
|
43
43
|
remoteType: "script",
|
|
44
44
|
runtimePlugins: [
|
|
45
45
|
require.resolve("@module-federation/modern-js/shared-strategy"),
|
|
46
|
-
require.resolve("@module-federation/modern-js/auto-fetch-data"),
|
|
47
46
|
require.resolve("@module-federation/node/runtimePlugin"),
|
|
48
47
|
require.resolve("@module-federation/modern-js/inject-node-fetch")
|
|
49
48
|
],
|
|
@@ -77,8 +76,7 @@ describe("patchMFConfig", /* @__PURE__ */ _async_to_generator(function() {
|
|
|
77
76
|
},
|
|
78
77
|
remoteType: "script",
|
|
79
78
|
runtimePlugins: [
|
|
80
|
-
require.resolve("@module-federation/modern-js/shared-strategy")
|
|
81
|
-
require.resolve("@module-federation/modern-js/auto-fetch-data")
|
|
79
|
+
require.resolve("@module-federation/modern-js/shared-strategy")
|
|
82
80
|
],
|
|
83
81
|
shared: {
|
|
84
82
|
react: {
|
package/dist/esm/cli/index.js
CHANGED
|
@@ -8,7 +8,6 @@ import { moduleFederationSSRPlugin } from "./ssrPlugin";
|
|
|
8
8
|
import { isWebTarget } from "./utils";
|
|
9
9
|
var moduleFederationPlugin = function() {
|
|
10
10
|
var userConfig = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
11
|
-
var _userConfig_fetchServerQuery;
|
|
12
11
|
var internalModernPluginOptions = {
|
|
13
12
|
csrConfig: void 0,
|
|
14
13
|
ssrConfig: void 0,
|
|
@@ -17,8 +16,7 @@ var moduleFederationPlugin = function() {
|
|
|
17
16
|
distOutputDir: "",
|
|
18
17
|
originPluginOptions: userConfig,
|
|
19
18
|
remoteIpStrategy: userConfig === null || userConfig === void 0 ? void 0 : userConfig.remoteIpStrategy,
|
|
20
|
-
userConfig: userConfig || {}
|
|
21
|
-
fetchServerQuery: (_userConfig_fetchServerQuery = userConfig.fetchServerQuery) !== null && _userConfig_fetchServerQuery !== void 0 ? _userConfig_fetchServerQuery : void 0
|
|
19
|
+
userConfig: userConfig || {}
|
|
22
20
|
};
|
|
23
21
|
return {
|
|
24
22
|
name: "@modern-js/plugin-module-federation",
|
|
@@ -57,6 +55,15 @@ var moduleFederationPlugin = function() {
|
|
|
57
55
|
}
|
|
58
56
|
}
|
|
59
57
|
});
|
|
58
|
+
api._internalServerPlugins(function(param) {
|
|
59
|
+
var plugins = param.plugins;
|
|
60
|
+
plugins.push({
|
|
61
|
+
name: "@module-federation/modern-js/server"
|
|
62
|
+
});
|
|
63
|
+
return {
|
|
64
|
+
plugins
|
|
65
|
+
};
|
|
66
|
+
});
|
|
60
67
|
return [
|
|
61
68
|
2
|
|
62
69
|
];
|
package/dist/esm/cli/manifest.js
CHANGED