@modern-js/prod-server 2.35.0 → 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 +86 -36
- 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 +30 -13
- package/dist/cjs/libs/preload/index.js +22 -5
- package/dist/cjs/libs/preload/parseLinks.js +54 -30
- package/dist/cjs/libs/preload/shouldFlushServerHeader.js +25 -15
- package/dist/cjs/libs/preload/transformLinks2String.js +27 -11
- 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 +33 -41
- 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 +30 -18
- 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 +62 -44
- 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 +56 -30
- package/dist/cjs/libs/render/measure.js +27 -17
- package/dist/cjs/libs/render/reader.js +50 -35
- 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 +37 -20
- 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 +74 -50
- package/dist/cjs/server/modernServer.js +136 -113
- 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 +48 -39
- package/dist/esm/constants.js +14 -6
- package/dist/esm/index.js +11 -5
- package/dist/esm/libs/context/context.js +33 -6
- 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 +9 -6
- package/dist/esm/libs/preload/parseLinks.js +13 -11
- package/dist/esm/libs/preload/shouldFlushServerHeader.js +6 -2
- package/dist/esm/libs/preload/transformLinks2String.js +5 -3
- package/dist/esm/libs/proxy.js +9 -5
- package/dist/esm/libs/render/cache/__tests__/cache.test.js +12 -12
- 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 +6 -3
- 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 +13 -9
- 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 +17 -11
- package/dist/esm/libs/render/measure.js +15 -11
- package/dist/esm/libs/render/reader.js +17 -10
- 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 +6 -3
- 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 +14 -13
- package/dist/esm/server/modernServer.js +39 -47
- 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 +25 -22
- package/dist/esm-node/constants.js +14 -6
- package/dist/esm-node/index.js +11 -5
- package/dist/esm-node/libs/context/context.js +33 -6
- 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 +6 -3
- package/dist/esm-node/libs/preload/parseLinks.js +11 -9
- package/dist/esm-node/libs/preload/shouldFlushServerHeader.js +6 -2
- package/dist/esm-node/libs/preload/transformLinks2String.js +5 -3
- package/dist/esm-node/libs/proxy.js +6 -2
- package/dist/esm-node/libs/render/cache/__tests__/cache.test.js +7 -12
- 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 +5 -3
- 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 +7 -4
- 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 +7 -3
- package/dist/esm-node/libs/render/measure.js +6 -2
- package/dist/esm-node/libs/render/reader.js +13 -7
- 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 +6 -3
- 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 +11 -10
- package/dist/esm-node/server/modernServer.js +29 -28
- 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 +12 -9
- package/dist/types/libs/context/context.d.ts +2 -1
- package/dist/types/type.d.ts +1 -0
- package/dist/types/utils.d.ts +1 -1
- package/package.json +9 -8
- package/dist/cjs/libs/logger.js +0 -123
- package/dist/esm/libs/logger.js +0 -125
- package/dist/esm-node/libs/logger.js +0 -106
- package/dist/types/libs/logger.d.ts +0 -61
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
2
2
|
import cookie from "cookie";
|
|
3
|
-
|
|
3
|
+
class BaseResponse {
|
|
4
4
|
get(key) {
|
|
5
5
|
return this.res.getHeader(key);
|
|
6
6
|
}
|
|
@@ -41,7 +41,7 @@ export class BaseResponse {
|
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
-
|
|
44
|
+
class BaseRequest {
|
|
45
45
|
getCookie(key) {
|
|
46
46
|
return this._cookie[key];
|
|
47
47
|
}
|
|
@@ -66,3 +66,7 @@ export class BaseRequest {
|
|
|
66
66
|
};
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
|
+
export {
|
|
70
|
+
BaseRequest,
|
|
71
|
+
BaseResponse
|
|
72
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { RouteAPI } from "./route";
|
|
2
2
|
import { TemplateAPI } from "./template";
|
|
3
3
|
import { BaseRequest, BaseResponse } from "./base";
|
|
4
|
-
|
|
4
|
+
const base = (context) => {
|
|
5
5
|
const { res, reporter } = context;
|
|
6
6
|
return {
|
|
7
7
|
response: new BaseResponse(res),
|
|
@@ -11,21 +11,21 @@ export const base = (context) => {
|
|
|
11
11
|
metrics: context.metrics
|
|
12
12
|
};
|
|
13
13
|
};
|
|
14
|
-
|
|
14
|
+
const createAfterMatchContext = (context, entryName) => {
|
|
15
15
|
const baseContext = base(context);
|
|
16
16
|
return {
|
|
17
17
|
...baseContext,
|
|
18
18
|
router: new RouteAPI(entryName)
|
|
19
19
|
};
|
|
20
20
|
};
|
|
21
|
-
|
|
21
|
+
const createAfterRenderContext = (context, content) => {
|
|
22
22
|
const baseContext = base(context);
|
|
23
23
|
return {
|
|
24
24
|
...baseContext,
|
|
25
25
|
template: new TemplateAPI(content)
|
|
26
26
|
};
|
|
27
27
|
};
|
|
28
|
-
|
|
28
|
+
const createMiddlewareContext = (context) => {
|
|
29
29
|
const baseContext = base(context);
|
|
30
30
|
baseContext.response.locals = context.res.locals || {};
|
|
31
31
|
return {
|
|
@@ -37,3 +37,9 @@ export const createMiddlewareContext = (context) => {
|
|
|
37
37
|
}
|
|
38
38
|
};
|
|
39
39
|
};
|
|
40
|
+
export {
|
|
41
|
+
base,
|
|
42
|
+
createAfterMatchContext,
|
|
43
|
+
createAfterRenderContext,
|
|
44
|
+
createMiddlewareContext
|
|
45
|
+
};
|
|
@@ -30,7 +30,7 @@ class ServerResponse {
|
|
|
30
30
|
this.locals = res.locals;
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
|
|
33
|
+
const base = (context) => {
|
|
34
34
|
const { req, res, logger, metrics, reporter } = context;
|
|
35
35
|
const serverResponse = new ServerResponse(res);
|
|
36
36
|
const { host, pathname, searchParams } = new URL(req.url);
|
|
@@ -53,21 +53,21 @@ export const base = (context) => {
|
|
|
53
53
|
metrics
|
|
54
54
|
};
|
|
55
55
|
};
|
|
56
|
-
|
|
56
|
+
const createAfterMatchContext = (context, entryName) => {
|
|
57
57
|
const baseContext = base(context);
|
|
58
58
|
return {
|
|
59
59
|
...baseContext,
|
|
60
60
|
router: new RouteAPI(entryName)
|
|
61
61
|
};
|
|
62
62
|
};
|
|
63
|
-
|
|
63
|
+
const createAfterRenderContext = (context, content) => {
|
|
64
64
|
const baseContext = base(context);
|
|
65
65
|
return {
|
|
66
66
|
...baseContext,
|
|
67
67
|
template: new TemplateAPI(content)
|
|
68
68
|
};
|
|
69
69
|
};
|
|
70
|
-
|
|
70
|
+
const createMiddlewareContext = (context) => {
|
|
71
71
|
const baseContext = base(context);
|
|
72
72
|
baseContext.response.locals = context.res.locals;
|
|
73
73
|
const { url, headers } = context.req;
|
|
@@ -83,3 +83,9 @@ export const createMiddlewareContext = (context) => {
|
|
|
83
83
|
}
|
|
84
84
|
};
|
|
85
85
|
};
|
|
86
|
+
export {
|
|
87
|
+
base,
|
|
88
|
+
createAfterMatchContext,
|
|
89
|
+
createAfterRenderContext,
|
|
90
|
+
createMiddlewareContext
|
|
91
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
2
|
-
|
|
2
|
+
class RouteAPI {
|
|
3
3
|
redirect(url, status = 302) {
|
|
4
4
|
this.url = url;
|
|
5
5
|
this.status = status;
|
|
@@ -19,3 +19,6 @@ export class RouteAPI {
|
|
|
19
19
|
this.url = "";
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
+
export {
|
|
23
|
+
RouteAPI
|
|
24
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
2
|
-
|
|
2
|
+
const RegList = {
|
|
3
3
|
before: {
|
|
4
4
|
head: "<head>",
|
|
5
5
|
body: "<body>"
|
|
@@ -9,7 +9,7 @@ export const RegList = {
|
|
|
9
9
|
body: "</body>"
|
|
10
10
|
}
|
|
11
11
|
};
|
|
12
|
-
|
|
12
|
+
class TemplateAPI {
|
|
13
13
|
get() {
|
|
14
14
|
return this.content;
|
|
15
15
|
}
|
|
@@ -40,3 +40,7 @@ export class TemplateAPI {
|
|
|
40
40
|
this.content = content;
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
+
export {
|
|
44
|
+
RegList,
|
|
45
|
+
TemplateAPI
|
|
46
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Transform } from "stream";
|
|
2
2
|
import { RegList } from "./template";
|
|
3
|
-
|
|
3
|
+
const templateInjectableStream = ({ prependHead, appendHead, prependBody, appendBody }) => new Transform({
|
|
4
4
|
write(chunk, _, callback) {
|
|
5
5
|
let chunk_str = chunk.toString();
|
|
6
6
|
if (prependHead) {
|
|
@@ -23,3 +23,6 @@ export const templateInjectableStream = ({ prependHead, appendHead, prependBody,
|
|
|
23
23
|
callback();
|
|
24
24
|
}
|
|
25
25
|
});
|
|
26
|
+
export {
|
|
27
|
+
templateInjectableStream
|
|
28
|
+
};
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import * as path from "path";
|
|
2
2
|
import { compatRequire, fs, DEFAULT_SERVER_CONFIG } from "@modern-js/utils";
|
|
3
3
|
import mergeDeep from "merge-deep";
|
|
4
|
-
|
|
4
|
+
const getServerConfigPath = (distDirectory, serverConfigFile = DEFAULT_SERVER_CONFIG) => {
|
|
5
5
|
const serverConfigPath = path.join(distDirectory, serverConfigFile);
|
|
6
6
|
return `${serverConfigPath}.js`;
|
|
7
7
|
};
|
|
8
|
-
|
|
8
|
+
const requireConfig = (serverConfigPath) => {
|
|
9
9
|
if (fs.pathExistsSync(serverConfigPath)) {
|
|
10
10
|
return compatRequire(serverConfigPath);
|
|
11
11
|
}
|
|
12
12
|
return {};
|
|
13
13
|
};
|
|
14
|
-
|
|
14
|
+
const loadConfig = ({ cliConfig, serverConfig, resolvedConfigPath }) => {
|
|
15
15
|
let config = null;
|
|
16
16
|
if (process.env.NODE_ENV === "production") {
|
|
17
17
|
const resolvedConfig = requireConfig(resolvedConfigPath);
|
|
@@ -27,3 +27,8 @@ export const loadConfig = ({ cliConfig, serverConfig, resolvedConfigPath }) => {
|
|
|
27
27
|
}
|
|
28
28
|
return config;
|
|
29
29
|
};
|
|
30
|
+
export {
|
|
31
|
+
getServerConfigPath,
|
|
32
|
+
loadConfig,
|
|
33
|
+
requireConfig
|
|
34
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { parseLinks } from "./parseLinks";
|
|
2
2
|
import { transformLinks2String } from "./transformLinks2String";
|
|
3
|
-
|
|
3
|
+
async function flushServerHeader({ serverConf, ctx, distDir, template, headers }) {
|
|
4
4
|
const { ssr: ssrConf } = serverConf || {};
|
|
5
5
|
if (typeof ssrConf !== "object") {
|
|
6
6
|
return;
|
|
@@ -14,9 +14,12 @@ export async function flushServerHeader({ serverConf, ctx, distDir, template, he
|
|
|
14
14
|
const link = transformLinks2String(links, ssrConf.preload);
|
|
15
15
|
res.set("link", link);
|
|
16
16
|
for (const key in headers || {}) {
|
|
17
|
-
|
|
18
|
-
const value = (_headers = headers) === null || _headers === void 0 ? void 0 : _headers[key];
|
|
17
|
+
const value = headers === null || headers === void 0 ? void 0 : headers[key];
|
|
19
18
|
value && res.set(key, value);
|
|
20
19
|
}
|
|
21
20
|
res.flushHeaders();
|
|
21
|
+
res.modernFlushedHeaders = true;
|
|
22
22
|
}
|
|
23
|
+
export {
|
|
24
|
+
flushServerHeader
|
|
25
|
+
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import { NESTED_ROUTE_SPEC_FILE, ROUTE_MANIFEST_FILE, ROUTE_SPEC_FILE, fs } from "@modern-js/utils";
|
|
3
3
|
import { parse as htmlParse } from "node-html-parser";
|
|
4
|
-
import { matchRoutes } from "@modern-js/utils/
|
|
5
|
-
import { matchEntry } from "@modern-js/utils/
|
|
6
|
-
|
|
4
|
+
import { matchRoutes } from "@modern-js/runtime-utils/remix-router";
|
|
5
|
+
import { matchEntry } from "@modern-js/runtime-utils/node";
|
|
6
|
+
async function parseLinks({ pathname, distDir, template }) {
|
|
7
7
|
const links = await parseLinksFromRoutes(pathname, distDir);
|
|
8
8
|
return links.concat(parseLinksFromHtml(template));
|
|
9
9
|
}
|
|
@@ -48,7 +48,7 @@ async function parseLinksFromRoutes(pathname, distDir) {
|
|
|
48
48
|
const serverRoutes = routesJson.routes;
|
|
49
49
|
const entry = matchEntry(pathname, serverRoutes);
|
|
50
50
|
if (entry) {
|
|
51
|
-
var _routeAssets_entryName,
|
|
51
|
+
var _routeAssets_entryName, _assets_filter, _assets_filter1;
|
|
52
52
|
const routes = await import(nestedRoutesSpec);
|
|
53
53
|
const { entryName } = entry;
|
|
54
54
|
if (!entryName) {
|
|
@@ -62,23 +62,22 @@ async function parseLinksFromRoutes(pathname, distDir) {
|
|
|
62
62
|
const { routeAssets } = routesManifest;
|
|
63
63
|
const matches = matchRoutes(entryRoutes, pathname, entry.urlPath);
|
|
64
64
|
const entryAssets = (_routeAssets_entryName = routeAssets[entryName]) === null || _routeAssets_entryName === void 0 ? void 0 : _routeAssets_entryName.assets;
|
|
65
|
-
const assets =
|
|
65
|
+
const assets = matches === null || matches === void 0 ? void 0 : matches.reduce((acc, match) => {
|
|
66
66
|
const routeId = match.route.id;
|
|
67
67
|
if (routeId) {
|
|
68
|
-
var _matchedManifest;
|
|
69
68
|
const matchedManifest = routeAssets[routeId];
|
|
70
|
-
const assets2 =
|
|
69
|
+
const assets2 = matchedManifest === null || matchedManifest === void 0 ? void 0 : matchedManifest.assets;
|
|
71
70
|
if (Array.isArray(assets2)) {
|
|
72
71
|
acc.push(...assets2);
|
|
73
72
|
}
|
|
74
73
|
}
|
|
75
74
|
return acc;
|
|
76
75
|
}, []).concat(entryAssets || []);
|
|
77
|
-
const cssLinks =
|
|
76
|
+
const cssLinks = assets === null || assets === void 0 ? void 0 : (_assets_filter = assets.filter((asset) => asset.endsWith(".css"))) === null || _assets_filter === void 0 ? void 0 : _assets_filter.map((uri) => ({
|
|
78
77
|
uri,
|
|
79
78
|
as: "style"
|
|
80
79
|
}));
|
|
81
|
-
const scriptLinks =
|
|
80
|
+
const scriptLinks = assets === null || assets === void 0 ? void 0 : (_assets_filter1 = assets.filter((asset) => asset.endsWith(".js"))) === null || _assets_filter1 === void 0 ? void 0 : _assets_filter1.map((uri) => ({
|
|
82
81
|
uri,
|
|
83
82
|
as: "script"
|
|
84
83
|
}));
|
|
@@ -86,3 +85,6 @@ async function parseLinksFromRoutes(pathname, distDir) {
|
|
|
86
85
|
}
|
|
87
86
|
return noopLinks;
|
|
88
87
|
}
|
|
88
|
+
export {
|
|
89
|
+
parseLinks
|
|
90
|
+
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
function transformToRegExp(input) {
|
|
2
2
|
if (typeof input === "string") {
|
|
3
3
|
return new RegExp(input);
|
|
4
4
|
}
|
|
5
5
|
return input;
|
|
6
6
|
}
|
|
7
|
-
|
|
7
|
+
function shouldFlushServerHeader(serverConf, userAgent, disablePreload) {
|
|
8
8
|
const { ssr: ssrConf } = serverConf || {};
|
|
9
9
|
if (disablePreload) {
|
|
10
10
|
return false;
|
|
@@ -21,3 +21,7 @@ export function shouldFlushServerHeader(serverConf, userAgent, disablePreload) {
|
|
|
21
21
|
}
|
|
22
22
|
return false;
|
|
23
23
|
}
|
|
24
|
+
export {
|
|
25
|
+
shouldFlushServerHeader,
|
|
26
|
+
transformToRegExp
|
|
27
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { transformToRegExp } from "./shouldFlushServerHeader";
|
|
2
|
-
|
|
2
|
+
function transformLinks2String(links, preload) {
|
|
3
3
|
if (typeof preload === "boolean") {
|
|
4
4
|
return transformLinkToString(dedup(links));
|
|
5
5
|
}
|
|
@@ -8,7 +8,6 @@ export function transformLinks2String(links, preload) {
|
|
|
8
8
|
return resolveLinks;
|
|
9
9
|
}
|
|
10
10
|
function addInclude(links, include) {
|
|
11
|
-
var _include;
|
|
12
11
|
const images = [
|
|
13
12
|
"gif",
|
|
14
13
|
"jpg",
|
|
@@ -34,7 +33,7 @@ function addInclude(links, include) {
|
|
|
34
33
|
"ttf",
|
|
35
34
|
"otf"
|
|
36
35
|
];
|
|
37
|
-
const includes = (
|
|
36
|
+
const includes = (include === null || include === void 0 ? void 0 : include.map((item) => {
|
|
38
37
|
if (typeof item === "string") {
|
|
39
38
|
const type = (() => {
|
|
40
39
|
if (item.endsWith(".js")) {
|
|
@@ -122,3 +121,6 @@ function transformLinkToString(links) {
|
|
|
122
121
|
return as ? `<${uri}>; rel=${rel}; as=${as}${rest || ""}` : `<${uri}>; rel=${rel}${rest || ""}`;
|
|
123
122
|
}).join(", ");
|
|
124
123
|
}
|
|
124
|
+
export {
|
|
125
|
+
transformLinks2String
|
|
126
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { HttpProxyMiddleware } from "http-proxy-middleware/dist/http-proxy-middleware";
|
|
2
2
|
import { debug } from "../utils";
|
|
3
|
-
|
|
3
|
+
function formatProxyOptions(proxyOptions) {
|
|
4
4
|
const ret = [];
|
|
5
5
|
if (Array.isArray(proxyOptions)) {
|
|
6
6
|
ret.push(...proxyOptions);
|
|
@@ -31,7 +31,7 @@ export function formatProxyOptions(proxyOptions) {
|
|
|
31
31
|
}
|
|
32
32
|
return ret;
|
|
33
33
|
}
|
|
34
|
-
|
|
34
|
+
const createProxyHandler = (proxyOptions) => {
|
|
35
35
|
debug("createProxyHandler", proxyOptions);
|
|
36
36
|
const formattedOptionsList = formatProxyOptions(proxyOptions);
|
|
37
37
|
const proxies = [];
|
|
@@ -68,3 +68,7 @@ export const createProxyHandler = (proxyOptions) => {
|
|
|
68
68
|
handleUpgrade
|
|
69
69
|
};
|
|
70
70
|
};
|
|
71
|
+
export {
|
|
72
|
+
createProxyHandler,
|
|
73
|
+
formatProxyOptions
|
|
74
|
+
};
|
|
@@ -15,7 +15,6 @@ const createCacheConfig = (config = {}) => ({
|
|
|
15
15
|
jest.setTimeout(6e4);
|
|
16
16
|
describe("cache", () => {
|
|
17
17
|
it("should cache correctly", async () => {
|
|
18
|
-
var _cacheResult;
|
|
19
18
|
destroyCache();
|
|
20
19
|
const cache = createCache();
|
|
21
20
|
const context = {
|
|
@@ -29,7 +28,7 @@ describe("cache", () => {
|
|
|
29
28
|
await cache.set(context, content, cacheConfig, true);
|
|
30
29
|
const cacheResult = await cache.get(context);
|
|
31
30
|
expect(cacheResult).not.toBe(null);
|
|
32
|
-
expect(
|
|
31
|
+
expect(cacheResult === null || cacheResult === void 0 ? void 0 : cacheResult.content).toBe("hello");
|
|
33
32
|
});
|
|
34
33
|
it("should ignore cache set when cache config not exist", async () => {
|
|
35
34
|
destroyCache();
|
|
@@ -124,7 +123,6 @@ describe("cache", () => {
|
|
|
124
123
|
destroyCache();
|
|
125
124
|
const cache = createCache();
|
|
126
125
|
for (const cacheable of cacheabelAry) {
|
|
127
|
-
var _cacheResult;
|
|
128
126
|
const context = {
|
|
129
127
|
entry: "",
|
|
130
128
|
pathname: cacheable.requestOpt.url,
|
|
@@ -134,14 +132,13 @@ describe("cache", () => {
|
|
|
134
132
|
const cacheConfig = createCacheConfig(cacheable.cacheConfig || {});
|
|
135
133
|
await cache.set(context, cacheable.content, cacheConfig, true);
|
|
136
134
|
const cacheResult = await cache.get(context);
|
|
137
|
-
expect(
|
|
135
|
+
expect(cacheResult === null || cacheResult === void 0 ? void 0 : cacheResult.content).toBe(cacheable.content);
|
|
138
136
|
}
|
|
139
137
|
});
|
|
140
138
|
it("should match cache correctly", async () => {
|
|
141
139
|
destroyCache();
|
|
142
140
|
const cache = createCache();
|
|
143
141
|
for (const cacheable of matchedCacheableAry) {
|
|
144
|
-
var _cacheResult;
|
|
145
142
|
const [baseCacheable, matchOne, ...other] = cacheable;
|
|
146
143
|
const { requestOpt = {}, cacheConfig, content } = baseCacheable;
|
|
147
144
|
const context = {
|
|
@@ -158,7 +155,7 @@ describe("cache", () => {
|
|
|
158
155
|
headers: matchOne.headers
|
|
159
156
|
};
|
|
160
157
|
const cacheResult = await cache.get(matchContext);
|
|
161
|
-
expect(
|
|
158
|
+
expect(cacheResult === null || cacheResult === void 0 ? void 0 : cacheResult.content).toBe(content);
|
|
162
159
|
for (const notMatch of other) {
|
|
163
160
|
const notMatchContext = {
|
|
164
161
|
entry: "",
|
|
@@ -172,7 +169,6 @@ describe("cache", () => {
|
|
|
172
169
|
}
|
|
173
170
|
});
|
|
174
171
|
it("should stale cache correctly", async () => {
|
|
175
|
-
var _freshResult, _staleResult;
|
|
176
172
|
destroyCache();
|
|
177
173
|
const cache = createCache();
|
|
178
174
|
const context = {
|
|
@@ -188,17 +184,16 @@ describe("cache", () => {
|
|
|
188
184
|
const shouldCache = await cache.set(context, content, config, true);
|
|
189
185
|
expect(shouldCache.value).toBe(true);
|
|
190
186
|
const freshResult = await cache.get(context);
|
|
191
|
-
expect(
|
|
187
|
+
expect(freshResult === null || freshResult === void 0 ? void 0 : freshResult.isStale).toBe(false);
|
|
192
188
|
await new Promise((resolve) => {
|
|
193
189
|
setTimeout(() => {
|
|
194
190
|
resolve();
|
|
195
191
|
}, 6e3);
|
|
196
192
|
});
|
|
197
193
|
const staleResult = await cache.get(context);
|
|
198
|
-
expect(
|
|
194
|
+
expect(staleResult === null || staleResult === void 0 ? void 0 : staleResult.isStale).toBe(true);
|
|
199
195
|
});
|
|
200
196
|
it("should garbage cache correctly", async () => {
|
|
201
|
-
var _freshResult, _staleResult;
|
|
202
197
|
destroyCache();
|
|
203
198
|
const cache = createCache();
|
|
204
199
|
const context = {
|
|
@@ -215,13 +210,13 @@ describe("cache", () => {
|
|
|
215
210
|
const shouldCache = await cache.set(context, content, config, true);
|
|
216
211
|
expect(shouldCache.value).toBe(true);
|
|
217
212
|
const freshResult = await cache.get(context);
|
|
218
|
-
expect(
|
|
213
|
+
expect(freshResult === null || freshResult === void 0 ? void 0 : freshResult.isGarbage).toBe(false);
|
|
219
214
|
await new Promise((resolve) => {
|
|
220
215
|
setTimeout(() => {
|
|
221
216
|
resolve();
|
|
222
217
|
}, 1e4);
|
|
223
218
|
});
|
|
224
219
|
const staleResult = await cache.get(context);
|
|
225
|
-
expect(
|
|
220
|
+
expect(staleResult === null || staleResult === void 0 ? void 0 : staleResult.isGarbage).toBe(true);
|
|
226
221
|
});
|
|
227
222
|
});
|
|
@@ -2,10 +2,9 @@ import { Transform } from "stream";
|
|
|
2
2
|
import { ERROR_DIGEST } from "../../../constants";
|
|
3
3
|
import { createCache } from "./spr";
|
|
4
4
|
import { namespaceHash, withCoalescedInvoke } from "./util";
|
|
5
|
-
|
|
5
|
+
var cache_default = (renderFn, ctx) => {
|
|
6
6
|
const sprCache = createCache();
|
|
7
7
|
const doRender = async (context) => {
|
|
8
|
-
var _cacheFile;
|
|
9
8
|
const cacheContext = {
|
|
10
9
|
entry: context.entryName,
|
|
11
10
|
...context.request
|
|
@@ -41,7 +40,7 @@ export default (renderFn, ctx) => {
|
|
|
41
40
|
const renderResult = await renderFn(context);
|
|
42
41
|
return afterRender(renderResult, saveHtmlIntoCache);
|
|
43
42
|
}
|
|
44
|
-
const cacheHash =
|
|
43
|
+
const cacheHash = cacheFile === null || cacheFile === void 0 ? void 0 : cacheFile.hash;
|
|
45
44
|
if (cacheFile.isGarbage) {
|
|
46
45
|
const renderResult = await renderFn(context);
|
|
47
46
|
return afterRender(renderResult, saveHtmlIntoCache);
|
|
@@ -68,3 +67,6 @@ export default (renderFn, ctx) => {
|
|
|
68
67
|
};
|
|
69
68
|
return doRender;
|
|
70
69
|
};
|
|
70
|
+
export {
|
|
71
|
+
cache_default as default
|
|
72
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LRUCaches } from "./lru";
|
|
2
|
-
|
|
2
|
+
async function createPageCaches(max) {
|
|
3
3
|
const constructorOptions = {
|
|
4
4
|
max
|
|
5
5
|
};
|
|
@@ -7,3 +7,6 @@ export async function createPageCaches(max) {
|
|
|
7
7
|
await cacheInstance.init();
|
|
8
8
|
return cacheInstance;
|
|
9
9
|
}
|
|
10
|
+
export {
|
|
11
|
+
createPageCaches
|
|
12
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
2
2
|
import LRU from "lru-cache";
|
|
3
|
-
|
|
3
|
+
class LRUCaches {
|
|
4
4
|
init() {
|
|
5
5
|
return Promise.resolve();
|
|
6
6
|
}
|
|
@@ -27,3 +27,6 @@ export class LRUCaches {
|
|
|
27
27
|
this.caches = new LRU(this.max);
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
+
export {
|
|
31
|
+
LRUCaches
|
|
32
|
+
};
|
|
@@ -141,10 +141,9 @@ class CacheManager {
|
|
|
141
141
|
return maybeSync(doCache)(sync);
|
|
142
142
|
}
|
|
143
143
|
async del(context, cacheHash) {
|
|
144
|
-
var _data;
|
|
145
144
|
const cacheKey = this.generateRequestKey(context);
|
|
146
145
|
const data = this.cache.get(cacheKey);
|
|
147
|
-
|
|
146
|
+
data === null || data === void 0 ? void 0 : data.caches.del(cacheHash);
|
|
148
147
|
}
|
|
149
148
|
constructor(cacheOptions) {
|
|
150
149
|
_define_property(this, "cache", void 0);
|
|
@@ -195,7 +194,7 @@ class CacheManager {
|
|
|
195
194
|
}
|
|
196
195
|
}
|
|
197
196
|
let manager;
|
|
198
|
-
|
|
197
|
+
function createCache() {
|
|
199
198
|
if (manager) {
|
|
200
199
|
return manager;
|
|
201
200
|
}
|
|
@@ -204,6 +203,10 @@ export function createCache() {
|
|
|
204
203
|
});
|
|
205
204
|
return manager;
|
|
206
205
|
}
|
|
207
|
-
|
|
206
|
+
function destroyCache() {
|
|
208
207
|
manager = null;
|
|
209
208
|
}
|
|
209
|
+
export {
|
|
210
|
+
createCache,
|
|
211
|
+
destroyCache
|
|
212
|
+
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import url from "url";
|
|
2
|
-
|
|
2
|
+
function namespaceHash(namespace, hash) {
|
|
3
3
|
return `${namespace}/${hash}`;
|
|
4
4
|
}
|
|
5
|
-
|
|
5
|
+
function fname(lv) {
|
|
6
6
|
return `f${lv}`;
|
|
7
7
|
}
|
|
8
|
-
|
|
8
|
+
function connectFactor(...args) {
|
|
9
9
|
return args.join("-");
|
|
10
10
|
}
|
|
11
|
-
|
|
11
|
+
function valueFactory(obj) {
|
|
12
12
|
if (obj instanceof url.URLSearchParams) {
|
|
13
13
|
return function(key) {
|
|
14
14
|
return obj.get(key);
|
|
@@ -23,16 +23,16 @@ export function valueFactory(obj) {
|
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
-
|
|
26
|
+
function getTime([s, ns]) {
|
|
27
27
|
return Math.floor(s * 1e3 + ns / 1e6);
|
|
28
28
|
}
|
|
29
29
|
const RE_START_IN_HEAD = /<head>/;
|
|
30
|
-
|
|
30
|
+
function cacheAddition(html, hash) {
|
|
31
31
|
const additionHtml = html.replace(RE_START_IN_HEAD, `<head><meta name="x-moden-spr" content="${hash}">`);
|
|
32
32
|
return additionHtml;
|
|
33
33
|
}
|
|
34
34
|
const globalInvokeCache = /* @__PURE__ */ new Map();
|
|
35
|
-
|
|
35
|
+
function withCoalescedInvoke(func) {
|
|
36
36
|
return async function(key, args) {
|
|
37
37
|
const entry = globalInvokeCache.get(key);
|
|
38
38
|
if (entry) {
|
|
@@ -58,7 +58,7 @@ export function withCoalescedInvoke(func) {
|
|
|
58
58
|
return future;
|
|
59
59
|
};
|
|
60
60
|
}
|
|
61
|
-
|
|
61
|
+
function maybeSync(fn) {
|
|
62
62
|
return (sync) => {
|
|
63
63
|
if (sync) {
|
|
64
64
|
return fn();
|
|
@@ -68,3 +68,13 @@ export function maybeSync(fn) {
|
|
|
68
68
|
}
|
|
69
69
|
};
|
|
70
70
|
}
|
|
71
|
+
export {
|
|
72
|
+
cacheAddition,
|
|
73
|
+
connectFactor,
|
|
74
|
+
fname,
|
|
75
|
+
getTime,
|
|
76
|
+
maybeSync,
|
|
77
|
+
namespaceHash,
|
|
78
|
+
valueFactory,
|
|
79
|
+
withCoalescedInvoke
|
|
80
|
+
};
|