@modern-js/prod-server 2.35.1 → 2.36.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.
- package/dist/cjs/constants.js +33 -27
- package/dist/cjs/index.js +41 -33
- package/dist/cjs/libs/context/context.js +71 -45
- package/dist/cjs/libs/context/index.js +27 -17
- package/dist/cjs/libs/hook-api/base.js +49 -30
- package/dist/cjs/libs/hook-api/index.js +36 -28
- package/dist/cjs/libs/hook-api/index.worker.js +39 -31
- package/dist/cjs/libs/hook-api/route.js +28 -11
- package/dist/cjs/libs/hook-api/template.js +27 -17
- package/dist/cjs/libs/hook-api/templateForStream.js +31 -14
- package/dist/cjs/libs/loadConfig.js +46 -29
- package/dist/cjs/libs/metrics.js +24 -7
- package/dist/cjs/libs/preload/flushServerHeader.js +28 -11
- package/dist/cjs/libs/preload/index.js +22 -5
- package/dist/cjs/libs/preload/parseLinks.js +49 -24
- package/dist/cjs/libs/preload/shouldFlushServerHeader.js +25 -15
- package/dist/cjs/libs/preload/transformLinks2String.js +26 -9
- package/dist/cjs/libs/proxy.js +29 -19
- package/dist/cjs/libs/render/cache/__tests__/cache.fun.test.js +40 -22
- package/dist/cjs/libs/render/cache/__tests__/cache.test.js +26 -29
- package/dist/cjs/libs/render/cache/__tests__/cacheable.js +24 -7
- package/dist/cjs/libs/render/cache/__tests__/error-configuration.js +24 -7
- package/dist/cjs/libs/render/cache/__tests__/matched-cache.js +24 -7
- package/dist/cjs/libs/render/cache/index.js +29 -16
- package/dist/cjs/libs/render/cache/page-caches/index.js +26 -9
- package/dist/cjs/libs/render/cache/page-caches/lru.js +39 -13
- package/dist/cjs/libs/render/cache/spr.js +61 -42
- package/dist/cjs/libs/render/cache/type.js +15 -3
- package/dist/cjs/libs/render/cache/util.js +49 -36
- package/dist/cjs/libs/render/index.js +54 -29
- package/dist/cjs/libs/render/measure.js +27 -17
- package/dist/cjs/libs/render/reader.js +49 -33
- package/dist/cjs/libs/render/ssr.js +52 -26
- package/dist/cjs/libs/render/static.js +44 -18
- package/dist/cjs/libs/render/type.js +24 -7
- package/dist/cjs/libs/render/utils.js +29 -19
- package/dist/cjs/libs/reporter.js +24 -7
- package/dist/cjs/libs/route/index.js +30 -20
- package/dist/cjs/libs/route/matcher.js +35 -18
- package/dist/cjs/libs/route/route.js +34 -17
- package/dist/cjs/libs/serveFile.js +40 -21
- package/dist/cjs/libs/serverTiming.js +27 -10
- package/dist/cjs/renderHtml.js +17 -20
- package/dist/cjs/server/index.js +71 -45
- package/dist/cjs/server/modernServer.js +120 -95
- package/dist/cjs/server/modernServerSplit.js +29 -12
- package/dist/cjs/type.js +15 -3
- package/dist/cjs/utils.js +41 -38
- package/dist/cjs/workerServer.js +44 -34
- package/dist/esm/constants.js +14 -6
- package/dist/esm/index.js +11 -5
- package/dist/esm/libs/context/context.js +4 -1
- package/dist/esm/libs/context/index.js +5 -2
- package/dist/esm/libs/hook-api/base.js +6 -2
- package/dist/esm/libs/hook-api/index.js +11 -5
- package/dist/esm/libs/hook-api/index.worker.js +16 -10
- package/dist/esm/libs/hook-api/route.js +4 -1
- package/dist/esm/libs/hook-api/template.js +6 -2
- package/dist/esm/libs/hook-api/templateForStream.js +4 -1
- package/dist/esm/libs/loadConfig.js +8 -3
- package/dist/esm/libs/metrics.js +3 -1
- package/dist/esm/libs/preload/flushServerHeader.js +6 -3
- package/dist/esm/libs/preload/parseLinks.js +6 -3
- package/dist/esm/libs/preload/shouldFlushServerHeader.js +6 -2
- package/dist/esm/libs/preload/transformLinks2String.js +4 -1
- package/dist/esm/libs/proxy.js +9 -5
- package/dist/esm/libs/render/cache/__tests__/cacheable.js +4 -1
- package/dist/esm/libs/render/cache/__tests__/error-configuration.js +4 -1
- package/dist/esm/libs/render/cache/__tests__/matched-cache.js +4 -1
- package/dist/esm/libs/render/cache/index.js +4 -1
- package/dist/esm/libs/render/cache/page-caches/index.js +5 -2
- package/dist/esm/libs/render/cache/page-caches/lru.js +4 -1
- package/dist/esm/libs/render/cache/spr.js +11 -7
- package/dist/esm/libs/render/cache/type.js +0 -1
- package/dist/esm/libs/render/cache/util.js +18 -8
- package/dist/esm/libs/render/index.js +12 -9
- package/dist/esm/libs/render/measure.js +15 -11
- package/dist/esm/libs/render/reader.js +15 -8
- package/dist/esm/libs/render/ssr.js +11 -8
- package/dist/esm/libs/render/static.js +5 -2
- package/dist/esm/libs/render/type.js +4 -1
- package/dist/esm/libs/render/utils.js +6 -2
- package/dist/esm/libs/reporter.js +4 -1
- package/dist/esm/libs/route/index.js +5 -2
- package/dist/esm/libs/route/matcher.js +4 -1
- package/dist/esm/libs/route/route.js +4 -1
- package/dist/esm/libs/serveFile.js +6 -2
- package/dist/esm/libs/serverTiming.js +4 -1
- package/dist/esm/renderHtml.js +133 -124
- package/dist/esm/server/index.js +9 -6
- package/dist/esm/server/modernServer.js +13 -10
- package/dist/esm/server/modernServerSplit.js +4 -1
- package/dist/esm/type.js +0 -1
- package/dist/esm/utils.js +23 -12
- package/dist/esm/workerServer.js +21 -17
- package/dist/esm-node/constants.js +14 -6
- package/dist/esm-node/index.js +11 -5
- package/dist/esm-node/libs/context/context.js +4 -1
- package/dist/esm-node/libs/context/index.js +5 -2
- package/dist/esm-node/libs/hook-api/base.js +6 -2
- package/dist/esm-node/libs/hook-api/index.js +10 -4
- package/dist/esm-node/libs/hook-api/index.worker.js +10 -4
- package/dist/esm-node/libs/hook-api/route.js +4 -1
- package/dist/esm-node/libs/hook-api/template.js +6 -2
- package/dist/esm-node/libs/hook-api/templateForStream.js +4 -1
- package/dist/esm-node/libs/loadConfig.js +8 -3
- package/dist/esm-node/libs/metrics.js +3 -1
- package/dist/esm-node/libs/preload/flushServerHeader.js +4 -1
- package/dist/esm-node/libs/preload/parseLinks.js +4 -1
- package/dist/esm-node/libs/preload/shouldFlushServerHeader.js +6 -2
- package/dist/esm-node/libs/preload/transformLinks2String.js +4 -1
- package/dist/esm-node/libs/proxy.js +6 -2
- package/dist/esm-node/libs/render/cache/__tests__/cacheable.js +4 -1
- package/dist/esm-node/libs/render/cache/__tests__/error-configuration.js +4 -1
- package/dist/esm-node/libs/render/cache/__tests__/matched-cache.js +4 -1
- package/dist/esm-node/libs/render/cache/index.js +4 -1
- package/dist/esm-node/libs/render/cache/page-caches/index.js +4 -1
- package/dist/esm-node/libs/render/cache/page-caches/lru.js +4 -1
- package/dist/esm-node/libs/render/cache/spr.js +6 -2
- package/dist/esm-node/libs/render/cache/type.js +0 -1
- package/dist/esm-node/libs/render/cache/util.js +18 -8
- package/dist/esm-node/libs/render/index.js +4 -1
- package/dist/esm-node/libs/render/measure.js +6 -2
- package/dist/esm-node/libs/render/reader.js +12 -5
- package/dist/esm-node/libs/render/ssr.js +4 -1
- package/dist/esm-node/libs/render/static.js +4 -1
- package/dist/esm-node/libs/render/type.js +4 -1
- package/dist/esm-node/libs/render/utils.js +6 -2
- package/dist/esm-node/libs/reporter.js +4 -1
- package/dist/esm-node/libs/route/index.js +5 -2
- package/dist/esm-node/libs/route/matcher.js +4 -1
- package/dist/esm-node/libs/route/route.js +4 -1
- package/dist/esm-node/libs/serveFile.js +6 -2
- package/dist/esm-node/libs/serverTiming.js +4 -1
- package/dist/esm-node/renderHtml.js +72 -63
- package/dist/esm-node/server/index.js +6 -3
- package/dist/esm-node/server/modernServer.js +4 -1
- package/dist/esm-node/server/modernServerSplit.js +4 -1
- package/dist/esm-node/type.js +0 -1
- package/dist/esm-node/utils.js +20 -9
- package/dist/esm-node/workerServer.js +8 -4
- package/dist/types/libs/context/context.d.ts +1 -1
- package/dist/types/utils.d.ts +1 -1
- package/package.json +9 -9
|
@@ -1,22 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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) => {
|
|
6
7
|
for (var name in all)
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return transformToRegExp;
|
|
15
|
-
},
|
|
16
|
-
shouldFlushServerHeader: function() {
|
|
17
|
-
return shouldFlushServerHeader;
|
|
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 });
|
|
18
15
|
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var shouldFlushServerHeader_exports = {};
|
|
20
|
+
__export(shouldFlushServerHeader_exports, {
|
|
21
|
+
shouldFlushServerHeader: () => shouldFlushServerHeader,
|
|
22
|
+
transformToRegExp: () => transformToRegExp
|
|
19
23
|
});
|
|
24
|
+
module.exports = __toCommonJS(shouldFlushServerHeader_exports);
|
|
20
25
|
function transformToRegExp(input) {
|
|
21
26
|
if (typeof input === "string") {
|
|
22
27
|
return new RegExp(input);
|
|
@@ -40,3 +45,8 @@ function shouldFlushServerHeader(serverConf, userAgent, disablePreload) {
|
|
|
40
45
|
}
|
|
41
46
|
return false;
|
|
42
47
|
}
|
|
48
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
49
|
+
0 && (module.exports = {
|
|
50
|
+
shouldFlushServerHeader,
|
|
51
|
+
transformToRegExp
|
|
52
|
+
});
|
|
@@ -1,14 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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 });
|
|
9
15
|
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var transformLinks2String_exports = {};
|
|
20
|
+
__export(transformLinks2String_exports, {
|
|
21
|
+
transformLinks2String: () => transformLinks2String
|
|
10
22
|
});
|
|
11
|
-
|
|
23
|
+
module.exports = __toCommonJS(transformLinks2String_exports);
|
|
24
|
+
var import_shouldFlushServerHeader = require("./shouldFlushServerHeader");
|
|
12
25
|
function transformLinks2String(links, preload) {
|
|
13
26
|
if (typeof preload === "boolean") {
|
|
14
27
|
return transformLinkToString(dedup(links));
|
|
@@ -76,7 +89,7 @@ function addInclude(links, include) {
|
|
|
76
89
|
return links.concat(includes);
|
|
77
90
|
}
|
|
78
91
|
function removeExclude(links, exclude) {
|
|
79
|
-
return exclude ? links.filter(({ uri }) => !(0,
|
|
92
|
+
return exclude ? links.filter(({ uri }) => !(0, import_shouldFlushServerHeader.transformToRegExp)(exclude).test(uri)) : links;
|
|
80
93
|
}
|
|
81
94
|
function addAttributes(links, attributes) {
|
|
82
95
|
const parseAttributes = (_attributes) => {
|
|
@@ -131,3 +144,7 @@ function transformLinkToString(links) {
|
|
|
131
144
|
return as ? `<${uri}>; rel=${rel}; as=${as}${rest || ""}` : `<${uri}>; rel=${rel}${rest || ""}`;
|
|
132
145
|
}).join(", ");
|
|
133
146
|
}
|
|
147
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
148
|
+
0 && (module.exports = {
|
|
149
|
+
transformLinks2String
|
|
150
|
+
});
|
package/dist/cjs/libs/proxy.js
CHANGED
|
@@ -1,24 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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) => {
|
|
6
7
|
for (var name in all)
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return formatProxyOptions;
|
|
15
|
-
},
|
|
16
|
-
createProxyHandler: function() {
|
|
17
|
-
return createProxyHandler;
|
|
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 });
|
|
18
15
|
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var proxy_exports = {};
|
|
20
|
+
__export(proxy_exports, {
|
|
21
|
+
createProxyHandler: () => createProxyHandler,
|
|
22
|
+
formatProxyOptions: () => formatProxyOptions
|
|
19
23
|
});
|
|
20
|
-
|
|
21
|
-
|
|
24
|
+
module.exports = __toCommonJS(proxy_exports);
|
|
25
|
+
var import_http_proxy_middleware = require("http-proxy-middleware/dist/http-proxy-middleware");
|
|
26
|
+
var import_utils = require("../utils");
|
|
22
27
|
function formatProxyOptions(proxyOptions) {
|
|
23
28
|
const ret = [];
|
|
24
29
|
if (Array.isArray(proxyOptions)) {
|
|
@@ -51,12 +56,12 @@ function formatProxyOptions(proxyOptions) {
|
|
|
51
56
|
return ret;
|
|
52
57
|
}
|
|
53
58
|
const createProxyHandler = (proxyOptions) => {
|
|
54
|
-
(0,
|
|
59
|
+
(0, import_utils.debug)("createProxyHandler", proxyOptions);
|
|
55
60
|
const formattedOptionsList = formatProxyOptions(proxyOptions);
|
|
56
61
|
const proxies = [];
|
|
57
62
|
const handlers = [];
|
|
58
63
|
for (const opts of formattedOptionsList) {
|
|
59
|
-
const proxy = new
|
|
64
|
+
const proxy = new import_http_proxy_middleware.HttpProxyMiddleware(opts.context, opts);
|
|
60
65
|
const handler = async (ctx, next) => {
|
|
61
66
|
const { req, res } = ctx;
|
|
62
67
|
const bypassUrl = typeof opts.bypass === "function" ? opts.bypass(req, res, opts) : null;
|
|
@@ -87,3 +92,8 @@ const createProxyHandler = (proxyOptions) => {
|
|
|
87
92
|
handleUpgrade
|
|
88
93
|
};
|
|
89
94
|
};
|
|
95
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
96
|
+
0 && (module.exports = {
|
|
97
|
+
createProxyHandler,
|
|
98
|
+
formatProxyOptions
|
|
99
|
+
});
|
|
@@ -1,49 +1,67 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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_url = __toESM(require("url"));
|
|
25
|
+
var import_spr = require("../spr");
|
|
26
|
+
var import_util = require("../util");
|
|
9
27
|
describe("test spr util functions", () => {
|
|
10
28
|
it("should return value correctly", () => {
|
|
11
|
-
expect((0,
|
|
12
|
-
expect((0,
|
|
13
|
-
expect((0,
|
|
29
|
+
expect((0, import_util.connectFactor)("bar", "foo")).toBe("bar-foo");
|
|
30
|
+
expect((0, import_util.fname)(1)).toBe("f1");
|
|
31
|
+
expect((0, import_util.namespaceHash)("modern", "!@#$%^&")).toBe("modern/!@#$%^&");
|
|
14
32
|
});
|
|
15
33
|
it("should create or destroy instance correctly", () => {
|
|
16
|
-
const ins1 = (0,
|
|
17
|
-
const ins2 = (0,
|
|
34
|
+
const ins1 = (0, import_spr.createCache)();
|
|
35
|
+
const ins2 = (0, import_spr.createCache)();
|
|
18
36
|
expect(ins1 === ins2).toBe(true);
|
|
19
|
-
(0,
|
|
20
|
-
const ins3 = (0,
|
|
37
|
+
(0, import_spr.destroyCache)();
|
|
38
|
+
const ins3 = (0, import_spr.createCache)();
|
|
21
39
|
expect(ins1 === ins3).toBe(false);
|
|
22
40
|
expect(ins2 === ins3).toBe(false);
|
|
23
41
|
});
|
|
24
42
|
it("should return function correctly", () => {
|
|
25
|
-
const urlParams = (() => new
|
|
43
|
+
const urlParams = (() => new import_url.default.URLSearchParams())();
|
|
26
44
|
urlParams.set("name", "modern");
|
|
27
|
-
const getParam = (0,
|
|
45
|
+
const getParam = (0, import_util.valueFactory)(urlParams);
|
|
28
46
|
expect(getParam("name")).toBe("modern");
|
|
29
47
|
const headers = {
|
|
30
48
|
age: "12345"
|
|
31
49
|
};
|
|
32
|
-
const getHeader = (0,
|
|
50
|
+
const getHeader = (0, import_util.valueFactory)(headers);
|
|
33
51
|
expect(getHeader("age")).toBe("12345");
|
|
34
52
|
});
|
|
35
53
|
it("should add target html content", () => {
|
|
36
54
|
const contentNoHead = "<div>123</div>";
|
|
37
|
-
const html = (0,
|
|
55
|
+
const html = (0, import_util.cacheAddition)(contentNoHead, Math.random().toString());
|
|
38
56
|
expect(html).toBe(contentNoHead);
|
|
39
57
|
const contentWithHead = "<head></head><div>123</div>";
|
|
40
58
|
const hash = Math.random().toString();
|
|
41
|
-
const htmlWithHead = (0,
|
|
59
|
+
const htmlWithHead = (0, import_util.cacheAddition)(contentWithHead, hash);
|
|
42
60
|
expect(htmlWithHead).toBe(`<head><meta name="x-moden-spr" content="${hash}"></head><div>123</div>`);
|
|
43
61
|
});
|
|
44
62
|
it("should only invoke func one time", async () => {
|
|
45
63
|
let index = 0;
|
|
46
|
-
const fn = (0,
|
|
64
|
+
const fn = (0, import_util.withCoalescedInvoke)(async () => new Promise((resolve) => {
|
|
47
65
|
setTimeout(() => {
|
|
48
66
|
index += 1;
|
|
49
67
|
resolve(index);
|
|
@@ -61,13 +79,13 @@ describe("test spr util functions", () => {
|
|
|
61
79
|
});
|
|
62
80
|
it("should invoke sync or async", async () => {
|
|
63
81
|
const foo = "";
|
|
64
|
-
const async = await (0,
|
|
82
|
+
const async = await (0, import_util.maybeSync)(() => new Promise((resolve) => {
|
|
65
83
|
setTimeout(() => {
|
|
66
84
|
resolve(foo);
|
|
67
85
|
}, 100);
|
|
68
86
|
}))(false);
|
|
69
87
|
expect(async).toBeUndefined();
|
|
70
|
-
const sync = await (0,
|
|
88
|
+
const sync = await (0, import_util.maybeSync)(() => new Promise((resolve) => {
|
|
71
89
|
setTimeout(() => {
|
|
72
90
|
resolve(foo);
|
|
73
91
|
}, 100);
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const _errorconfiguration = require("./error-configuration");
|
|
7
|
-
const _cacheable = require("./cacheable");
|
|
8
|
-
const _matchedcache = require("./matched-cache");
|
|
2
|
+
var import_spr = require("../spr");
|
|
3
|
+
var import_error_configuration = require("./error-configuration");
|
|
4
|
+
var import_cacheable = require("./cacheable");
|
|
5
|
+
var import_matched_cache = require("./matched-cache");
|
|
9
6
|
const createCacheConfig = (config = {}) => ({
|
|
10
7
|
excludes: null,
|
|
11
8
|
includes: null,
|
|
@@ -19,8 +16,8 @@ const createCacheConfig = (config = {}) => ({
|
|
|
19
16
|
jest.setTimeout(6e4);
|
|
20
17
|
describe("cache", () => {
|
|
21
18
|
it("should cache correctly", async () => {
|
|
22
|
-
(0,
|
|
23
|
-
const cache = (0,
|
|
19
|
+
(0, import_spr.destroyCache)();
|
|
20
|
+
const cache = (0, import_spr.createCache)();
|
|
24
21
|
const context = {
|
|
25
22
|
entry: "",
|
|
26
23
|
pathname: "",
|
|
@@ -35,9 +32,9 @@ describe("cache", () => {
|
|
|
35
32
|
expect(cacheResult === null || cacheResult === void 0 ? void 0 : cacheResult.content).toBe("hello");
|
|
36
33
|
});
|
|
37
34
|
it("should ignore cache set when cache config not exist", async () => {
|
|
38
|
-
(0,
|
|
39
|
-
(0,
|
|
40
|
-
const cache = (0,
|
|
35
|
+
(0, import_spr.destroyCache)();
|
|
36
|
+
(0, import_spr.destroyCache)();
|
|
37
|
+
const cache = (0, import_spr.createCache)();
|
|
41
38
|
const context = {
|
|
42
39
|
entry: "",
|
|
43
40
|
pathname: "",
|
|
@@ -49,10 +46,10 @@ describe("cache", () => {
|
|
|
49
46
|
expect(shouldCache).toBe(false);
|
|
50
47
|
});
|
|
51
48
|
it("should calcual cache key error", async () => {
|
|
52
|
-
(0,
|
|
53
|
-
const cache = (0,
|
|
49
|
+
(0, import_spr.destroyCache)();
|
|
50
|
+
const cache = (0, import_spr.createCache)();
|
|
54
51
|
const content = "hello";
|
|
55
|
-
for (const config of
|
|
52
|
+
for (const config of import_error_configuration.errorConfiguration) {
|
|
56
53
|
const cacheConfig = createCacheConfig(config);
|
|
57
54
|
const tmpEntry = Math.random().toString();
|
|
58
55
|
const context = {
|
|
@@ -66,8 +63,8 @@ describe("cache", () => {
|
|
|
66
63
|
}
|
|
67
64
|
});
|
|
68
65
|
it("should get nothing for diff requestKey", async () => {
|
|
69
|
-
(0,
|
|
70
|
-
const cache = (0,
|
|
66
|
+
(0, import_spr.destroyCache)();
|
|
67
|
+
const cache = (0, import_spr.createCache)();
|
|
71
68
|
const context = {
|
|
72
69
|
entry: "",
|
|
73
70
|
pathname: "",
|
|
@@ -94,8 +91,8 @@ describe("cache", () => {
|
|
|
94
91
|
expect(cacheResult).toBe(null);
|
|
95
92
|
});
|
|
96
93
|
it("should get nothing for diff cacheHash", async () => {
|
|
97
|
-
(0,
|
|
98
|
-
const cache = (0,
|
|
94
|
+
(0, import_spr.destroyCache)();
|
|
95
|
+
const cache = (0, import_spr.createCache)();
|
|
99
96
|
const context = {
|
|
100
97
|
entry: "",
|
|
101
98
|
pathname: "",
|
|
@@ -124,9 +121,9 @@ describe("cache", () => {
|
|
|
124
121
|
expect(cacheResult).toBe(null);
|
|
125
122
|
});
|
|
126
123
|
it("should get cache correctly", async () => {
|
|
127
|
-
(0,
|
|
128
|
-
const cache = (0,
|
|
129
|
-
for (const cacheable of
|
|
124
|
+
(0, import_spr.destroyCache)();
|
|
125
|
+
const cache = (0, import_spr.createCache)();
|
|
126
|
+
for (const cacheable of import_cacheable.cacheabelAry) {
|
|
130
127
|
const context = {
|
|
131
128
|
entry: "",
|
|
132
129
|
pathname: cacheable.requestOpt.url,
|
|
@@ -140,9 +137,9 @@ describe("cache", () => {
|
|
|
140
137
|
}
|
|
141
138
|
});
|
|
142
139
|
it("should match cache correctly", async () => {
|
|
143
|
-
(0,
|
|
144
|
-
const cache = (0,
|
|
145
|
-
for (const cacheable of
|
|
140
|
+
(0, import_spr.destroyCache)();
|
|
141
|
+
const cache = (0, import_spr.createCache)();
|
|
142
|
+
for (const cacheable of import_matched_cache.matchedCacheableAry) {
|
|
146
143
|
const [baseCacheable, matchOne, ...other] = cacheable;
|
|
147
144
|
const { requestOpt = {}, cacheConfig, content } = baseCacheable;
|
|
148
145
|
const context = {
|
|
@@ -173,8 +170,8 @@ describe("cache", () => {
|
|
|
173
170
|
}
|
|
174
171
|
});
|
|
175
172
|
it("should stale cache correctly", async () => {
|
|
176
|
-
(0,
|
|
177
|
-
const cache = (0,
|
|
173
|
+
(0, import_spr.destroyCache)();
|
|
174
|
+
const cache = (0, import_spr.createCache)();
|
|
178
175
|
const context = {
|
|
179
176
|
entry: "",
|
|
180
177
|
pathname: "",
|
|
@@ -198,8 +195,8 @@ describe("cache", () => {
|
|
|
198
195
|
expect(staleResult === null || staleResult === void 0 ? void 0 : staleResult.isStale).toBe(true);
|
|
199
196
|
});
|
|
200
197
|
it("should garbage cache correctly", async () => {
|
|
201
|
-
(0,
|
|
202
|
-
const cache = (0,
|
|
198
|
+
(0, import_spr.destroyCache)();
|
|
199
|
+
const cache = (0, import_spr.createCache)();
|
|
203
200
|
const context = {
|
|
204
201
|
entry: "",
|
|
205
202
|
pathname: "",
|
|
@@ -1,13 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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 });
|
|
9
15
|
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var cacheable_exports = {};
|
|
20
|
+
__export(cacheable_exports, {
|
|
21
|
+
cacheabelAry: () => cacheabelAry
|
|
10
22
|
});
|
|
23
|
+
module.exports = __toCommonJS(cacheable_exports);
|
|
11
24
|
const cacheabelAry = [
|
|
12
25
|
{
|
|
13
26
|
requestOpt: {
|
|
@@ -74,3 +87,7 @@ const cacheabelAry = [
|
|
|
74
87
|
content: "level3"
|
|
75
88
|
}
|
|
76
89
|
];
|
|
90
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
91
|
+
0 && (module.exports = {
|
|
92
|
+
cacheabelAry
|
|
93
|
+
});
|
|
@@ -1,13 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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 });
|
|
9
15
|
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var error_configuration_exports = {};
|
|
20
|
+
__export(error_configuration_exports, {
|
|
21
|
+
errorConfiguration: () => errorConfiguration
|
|
10
22
|
});
|
|
23
|
+
module.exports = __toCommonJS(error_configuration_exports);
|
|
11
24
|
const errorConfiguration = [
|
|
12
25
|
{
|
|
13
26
|
level: 1
|
|
@@ -52,3 +65,7 @@ const errorConfiguration = [
|
|
|
52
65
|
}
|
|
53
66
|
}
|
|
54
67
|
];
|
|
68
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
69
|
+
0 && (module.exports = {
|
|
70
|
+
errorConfiguration
|
|
71
|
+
});
|
|
@@ -1,13 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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 });
|
|
9
15
|
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var matched_cache_exports = {};
|
|
20
|
+
__export(matched_cache_exports, {
|
|
21
|
+
matchedCacheableAry: () => matchedCacheableAry
|
|
10
22
|
});
|
|
23
|
+
module.exports = __toCommonJS(matched_cache_exports);
|
|
11
24
|
const matchedCacheableAry = [
|
|
12
25
|
[
|
|
13
26
|
{
|
|
@@ -154,3 +167,7 @@ const matchedCacheableAry = [
|
|
|
154
167
|
}
|
|
155
168
|
]
|
|
156
169
|
];
|
|
170
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
171
|
+
0 && (module.exports = {
|
|
172
|
+
matchedCacheableAry
|
|
173
|
+
});
|
|
@@ -1,19 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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 });
|
|
9
15
|
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var cache_exports = {};
|
|
20
|
+
__export(cache_exports, {
|
|
21
|
+
default: () => cache_default
|
|
10
22
|
});
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
23
|
+
module.exports = __toCommonJS(cache_exports);
|
|
24
|
+
var import_stream = require("stream");
|
|
25
|
+
var import_constants = require("../../../constants");
|
|
26
|
+
var import_spr = require("./spr");
|
|
27
|
+
var import_util = require("./util");
|
|
28
|
+
var cache_default = (renderFn, ctx) => {
|
|
29
|
+
const sprCache = (0, import_spr.createCache)();
|
|
17
30
|
const doRender = async (context) => {
|
|
18
31
|
const cacheContext = {
|
|
19
32
|
entry: context.entryName,
|
|
@@ -29,7 +42,7 @@ const _default = (renderFn, ctx) => {
|
|
|
29
42
|
return source;
|
|
30
43
|
} else {
|
|
31
44
|
let htmlForStream = "";
|
|
32
|
-
const cacheStream = new
|
|
45
|
+
const cacheStream = new import_stream.Transform({
|
|
33
46
|
write(chunk, _, callback) {
|
|
34
47
|
htmlForStream += chunk.toString();
|
|
35
48
|
this.push(chunk);
|
|
@@ -55,7 +68,7 @@ const _default = (renderFn, ctx) => {
|
|
|
55
68
|
const renderResult = await renderFn(context);
|
|
56
69
|
return afterRender(renderResult, saveHtmlIntoCache);
|
|
57
70
|
} else if (cacheFile.isStale) {
|
|
58
|
-
const render = (0,
|
|
71
|
+
const render = (0, import_util.withCoalescedInvoke)(() => renderFn(context)).bind(null, (0, import_util.namespaceHash)("render", cacheFile.hash), []);
|
|
59
72
|
render().then(async (res) => {
|
|
60
73
|
if (res.value && res.isOrigin) {
|
|
61
74
|
const { cacheConfig } = context;
|
|
@@ -69,7 +82,7 @@ const _default = (renderFn, ctx) => {
|
|
|
69
82
|
}
|
|
70
83
|
}).catch((e) => {
|
|
71
84
|
sprCache.del(cacheContext, cacheHash);
|
|
72
|
-
ctx.error(
|
|
85
|
+
ctx.error(import_constants.ERROR_DIGEST.ERENDER, e);
|
|
73
86
|
});
|
|
74
87
|
}
|
|
75
88
|
ctx.res.setHeader("x-modern-spr", "1");
|
|
@@ -1,19 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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 });
|
|
9
15
|
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var page_caches_exports = {};
|
|
20
|
+
__export(page_caches_exports, {
|
|
21
|
+
createPageCaches: () => createPageCaches
|
|
10
22
|
});
|
|
11
|
-
|
|
23
|
+
module.exports = __toCommonJS(page_caches_exports);
|
|
24
|
+
var import_lru = require("./lru");
|
|
12
25
|
async function createPageCaches(max) {
|
|
13
26
|
const constructorOptions = {
|
|
14
27
|
max
|
|
15
28
|
};
|
|
16
|
-
const cacheInstance = new
|
|
29
|
+
const cacheInstance = new import_lru.LRUCaches(constructorOptions);
|
|
17
30
|
await cacheInstance.init();
|
|
18
31
|
return cacheInstance;
|
|
19
32
|
}
|
|
33
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
34
|
+
0 && (module.exports = {
|
|
35
|
+
createPageCaches
|
|
36
|
+
});
|