@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
|
@@ -4,9 +4,9 @@ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
|
4
4
|
import path from "path";
|
|
5
5
|
import { NESTED_ROUTE_SPEC_FILE, ROUTE_MANIFEST_FILE, ROUTE_SPEC_FILE, fs } from "@modern-js/utils";
|
|
6
6
|
import { parse as htmlParse } from "node-html-parser";
|
|
7
|
-
import { matchRoutes } from "@modern-js/utils/
|
|
8
|
-
import { matchEntry } from "@modern-js/utils/
|
|
9
|
-
|
|
7
|
+
import { matchRoutes } from "@modern-js/runtime-utils/remix-router";
|
|
8
|
+
import { matchEntry } from "@modern-js/runtime-utils/node";
|
|
9
|
+
function parseLinks(_) {
|
|
10
10
|
return _parseLinks.apply(this, arguments);
|
|
11
11
|
}
|
|
12
12
|
function _parseLinks() {
|
|
@@ -69,7 +69,7 @@ function parseLinksFromRoutes(pathname, distDir) {
|
|
|
69
69
|
}
|
|
70
70
|
function _parseLinksFromRoutes() {
|
|
71
71
|
_parseLinksFromRoutes = _async_to_generator(function(pathname, distDir) {
|
|
72
|
-
var noopLinks, nestedRoutesSpec, routesJsonPath, routeManifestPath, routesJson, serverRoutes, entry, _routeAssets_entryName,
|
|
72
|
+
var noopLinks, nestedRoutesSpec, routesJsonPath, routeManifestPath, routesJson, serverRoutes, entry, _routeAssets_entryName, _assets_filter, _assets_filter1, routes, entryName, entryRoutes, routesManifest, routeAssets, matches, entryAssets, assets, cssLinks, scriptLinks;
|
|
73
73
|
return _ts_generator(this, function(_state) {
|
|
74
74
|
switch (_state.label) {
|
|
75
75
|
case 0:
|
|
@@ -125,12 +125,11 @@ function _parseLinksFromRoutes() {
|
|
|
125
125
|
routeAssets = routesManifest.routeAssets;
|
|
126
126
|
matches = matchRoutes(entryRoutes, pathname, entry.urlPath);
|
|
127
127
|
entryAssets = (_routeAssets_entryName = routeAssets[entryName]) === null || _routeAssets_entryName === void 0 ? void 0 : _routeAssets_entryName.assets;
|
|
128
|
-
assets =
|
|
128
|
+
assets = matches === null || matches === void 0 ? void 0 : matches.reduce(function(acc, match) {
|
|
129
129
|
var routeId = match.route.id;
|
|
130
130
|
if (routeId) {
|
|
131
|
-
var _matchedManifest;
|
|
132
131
|
var matchedManifest = routeAssets[routeId];
|
|
133
|
-
var assets2 =
|
|
132
|
+
var assets2 = matchedManifest === null || matchedManifest === void 0 ? void 0 : matchedManifest.assets;
|
|
134
133
|
if (Array.isArray(assets2)) {
|
|
135
134
|
var _acc;
|
|
136
135
|
(_acc = acc).push.apply(_acc, _to_consumable_array(assets2));
|
|
@@ -138,19 +137,19 @@ function _parseLinksFromRoutes() {
|
|
|
138
137
|
}
|
|
139
138
|
return acc;
|
|
140
139
|
}, []).concat(entryAssets || []);
|
|
141
|
-
cssLinks =
|
|
140
|
+
cssLinks = assets === null || assets === void 0 ? void 0 : (_assets_filter = assets.filter(function(asset) {
|
|
142
141
|
return asset.endsWith(".css");
|
|
143
142
|
})) === null || _assets_filter === void 0 ? void 0 : _assets_filter.map(function(uri) {
|
|
144
143
|
return {
|
|
145
|
-
uri
|
|
144
|
+
uri,
|
|
146
145
|
as: "style"
|
|
147
146
|
};
|
|
148
147
|
});
|
|
149
|
-
scriptLinks =
|
|
148
|
+
scriptLinks = assets === null || assets === void 0 ? void 0 : (_assets_filter1 = assets.filter(function(asset) {
|
|
150
149
|
return asset.endsWith(".js");
|
|
151
150
|
})) === null || _assets_filter1 === void 0 ? void 0 : _assets_filter1.map(function(uri) {
|
|
152
151
|
return {
|
|
153
|
-
uri
|
|
152
|
+
uri,
|
|
154
153
|
as: "script"
|
|
155
154
|
};
|
|
156
155
|
});
|
|
@@ -168,3 +167,6 @@ function _parseLinksFromRoutes() {
|
|
|
168
167
|
});
|
|
169
168
|
return _parseLinksFromRoutes.apply(this, arguments);
|
|
170
169
|
}
|
|
170
|
+
export {
|
|
171
|
+
parseLinks
|
|
172
|
+
};
|
|
@@ -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
|
var _ref = serverConf || {}, ssrConf = _ref.ssr;
|
|
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
|
+
};
|
|
@@ -2,7 +2,7 @@ import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
|
2
2
|
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
3
3
|
import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
|
|
4
4
|
import { transformToRegExp } from "./shouldFlushServerHeader";
|
|
5
|
-
|
|
5
|
+
function transformLinks2String(links, preload) {
|
|
6
6
|
if (typeof preload === "boolean") {
|
|
7
7
|
return transformLinkToString(dedup(links));
|
|
8
8
|
}
|
|
@@ -11,7 +11,6 @@ export function transformLinks2String(links, preload) {
|
|
|
11
11
|
return resolveLinks;
|
|
12
12
|
}
|
|
13
13
|
function addInclude(links, include) {
|
|
14
|
-
var _include;
|
|
15
14
|
var images = [
|
|
16
15
|
"gif",
|
|
17
16
|
"jpg",
|
|
@@ -37,7 +36,7 @@ function addInclude(links, include) {
|
|
|
37
36
|
"ttf",
|
|
38
37
|
"otf"
|
|
39
38
|
];
|
|
40
|
-
var includes = (
|
|
39
|
+
var includes = (include === null || include === void 0 ? void 0 : include.map(function(item) {
|
|
41
40
|
if (typeof item === "string") {
|
|
42
41
|
var type = function() {
|
|
43
42
|
if (item.endsWith(".js")) {
|
|
@@ -136,3 +135,6 @@ function transformLinkToString(links) {
|
|
|
136
135
|
return as ? "<".concat(uri, ">; rel=").concat(rel, "; as=").concat(as).concat(rest || "") : "<".concat(uri, ">; rel=").concat(rel).concat(rest || "");
|
|
137
136
|
}).join(", ");
|
|
138
137
|
}
|
|
138
|
+
export {
|
|
139
|
+
transformLinks2String
|
|
140
|
+
};
|
package/dist/esm/libs/proxy.js
CHANGED
|
@@ -4,7 +4,7 @@ import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
|
4
4
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
5
5
|
import { HttpProxyMiddleware } from "http-proxy-middleware/dist/http-proxy-middleware";
|
|
6
6
|
import { debug } from "../utils";
|
|
7
|
-
|
|
7
|
+
function formatProxyOptions(proxyOptions) {
|
|
8
8
|
var ret = [];
|
|
9
9
|
if (Array.isArray(proxyOptions)) {
|
|
10
10
|
var _ret;
|
|
@@ -17,7 +17,7 @@ export function formatProxyOptions(proxyOptions) {
|
|
|
17
17
|
for (var _iterator = Object.entries(proxyOptions)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
18
18
|
var _step_value = _sliced_to_array(_step.value, 2), context = _step_value[0], options = _step_value[1];
|
|
19
19
|
var opts = {
|
|
20
|
-
context
|
|
20
|
+
context,
|
|
21
21
|
changeOrigin: true,
|
|
22
22
|
logLevel: "warn"
|
|
23
23
|
};
|
|
@@ -70,7 +70,7 @@ export function formatProxyOptions(proxyOptions) {
|
|
|
70
70
|
}
|
|
71
71
|
return ret;
|
|
72
72
|
}
|
|
73
|
-
|
|
73
|
+
var createProxyHandler = function(proxyOptions) {
|
|
74
74
|
debug("createProxyHandler", proxyOptions);
|
|
75
75
|
var formattedOptionsList = formatProxyOptions(proxyOptions);
|
|
76
76
|
var proxies = [];
|
|
@@ -150,7 +150,11 @@ export var createProxyHandler = function(proxyOptions) {
|
|
|
150
150
|
}
|
|
151
151
|
};
|
|
152
152
|
return {
|
|
153
|
-
handlers
|
|
154
|
-
handleUpgrade
|
|
153
|
+
handlers,
|
|
154
|
+
handleUpgrade
|
|
155
155
|
};
|
|
156
156
|
};
|
|
157
|
+
export {
|
|
158
|
+
createProxyHandler,
|
|
159
|
+
formatProxyOptions
|
|
160
|
+
};
|
|
@@ -21,7 +21,7 @@ var createCacheConfig = function() {
|
|
|
21
21
|
jest.setTimeout(6e4);
|
|
22
22
|
describe("cache", function() {
|
|
23
23
|
it("should cache correctly", /* @__PURE__ */ _async_to_generator(function() {
|
|
24
|
-
var
|
|
24
|
+
var cache, context, content, cacheConfig, cacheResult;
|
|
25
25
|
return _ts_generator(this, function(_state) {
|
|
26
26
|
switch (_state.label) {
|
|
27
27
|
case 0:
|
|
@@ -48,7 +48,7 @@ describe("cache", function() {
|
|
|
48
48
|
case 2:
|
|
49
49
|
cacheResult = _state.sent();
|
|
50
50
|
expect(cacheResult).not.toBe(null);
|
|
51
|
-
expect(
|
|
51
|
+
expect(cacheResult === null || cacheResult === void 0 ? void 0 : cacheResult.content).toBe("hello");
|
|
52
52
|
return [
|
|
53
53
|
2
|
|
54
54
|
];
|
|
@@ -261,7 +261,7 @@ describe("cache", function() {
|
|
|
261
261
|
});
|
|
262
262
|
}));
|
|
263
263
|
it("should get cache correctly", /* @__PURE__ */ _async_to_generator(function() {
|
|
264
|
-
var cache, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, cacheable,
|
|
264
|
+
var cache, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, cacheable, context, cacheConfig, cacheResult, err;
|
|
265
265
|
return _ts_generator(this, function(_state) {
|
|
266
266
|
switch (_state.label) {
|
|
267
267
|
case 0:
|
|
@@ -304,7 +304,7 @@ describe("cache", function() {
|
|
|
304
304
|
];
|
|
305
305
|
case 4:
|
|
306
306
|
cacheResult = _state.sent();
|
|
307
|
-
expect(
|
|
307
|
+
expect(cacheResult === null || cacheResult === void 0 ? void 0 : cacheResult.content).toBe(cacheable.content);
|
|
308
308
|
_state.label = 5;
|
|
309
309
|
case 5:
|
|
310
310
|
_iteratorNormalCompletion = true;
|
|
@@ -346,7 +346,7 @@ describe("cache", function() {
|
|
|
346
346
|
});
|
|
347
347
|
}));
|
|
348
348
|
it("should match cache correctly", /* @__PURE__ */ _async_to_generator(function() {
|
|
349
|
-
var cache, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, cacheable,
|
|
349
|
+
var cache, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, cacheable, _cacheable, baseCacheable, matchOne, other, _baseCacheable_requestOpt, requestOpt, cacheConfig, content, context, matchContext, cacheResult, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, notMatch, notMatchContext, nothing, err, err;
|
|
350
350
|
return _ts_generator(this, function(_state) {
|
|
351
351
|
switch (_state.label) {
|
|
352
352
|
case 0:
|
|
@@ -396,7 +396,7 @@ describe("cache", function() {
|
|
|
396
396
|
];
|
|
397
397
|
case 4:
|
|
398
398
|
cacheResult = _state.sent();
|
|
399
|
-
expect(
|
|
399
|
+
expect(cacheResult === null || cacheResult === void 0 ? void 0 : cacheResult.content).toBe(content);
|
|
400
400
|
_iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = void 0;
|
|
401
401
|
_state.label = 5;
|
|
402
402
|
case 5:
|
|
@@ -501,7 +501,7 @@ describe("cache", function() {
|
|
|
501
501
|
});
|
|
502
502
|
}));
|
|
503
503
|
it("should stale cache correctly", /* @__PURE__ */ _async_to_generator(function() {
|
|
504
|
-
var
|
|
504
|
+
var cache, context, config, content, shouldCache, freshResult, staleResult;
|
|
505
505
|
return _ts_generator(this, function(_state) {
|
|
506
506
|
switch (_state.label) {
|
|
507
507
|
case 0:
|
|
@@ -530,7 +530,7 @@ describe("cache", function() {
|
|
|
530
530
|
];
|
|
531
531
|
case 2:
|
|
532
532
|
freshResult = _state.sent();
|
|
533
|
-
expect(
|
|
533
|
+
expect(freshResult === null || freshResult === void 0 ? void 0 : freshResult.isStale).toBe(false);
|
|
534
534
|
return [
|
|
535
535
|
4,
|
|
536
536
|
new Promise(function(resolve) {
|
|
@@ -547,7 +547,7 @@ describe("cache", function() {
|
|
|
547
547
|
];
|
|
548
548
|
case 4:
|
|
549
549
|
staleResult = _state.sent();
|
|
550
|
-
expect(
|
|
550
|
+
expect(staleResult === null || staleResult === void 0 ? void 0 : staleResult.isStale).toBe(true);
|
|
551
551
|
return [
|
|
552
552
|
2
|
|
553
553
|
];
|
|
@@ -555,7 +555,7 @@ describe("cache", function() {
|
|
|
555
555
|
});
|
|
556
556
|
}));
|
|
557
557
|
it("should garbage cache correctly", /* @__PURE__ */ _async_to_generator(function() {
|
|
558
|
-
var
|
|
558
|
+
var cache, context, config, content, shouldCache, freshResult, staleResult;
|
|
559
559
|
return _ts_generator(this, function(_state) {
|
|
560
560
|
switch (_state.label) {
|
|
561
561
|
case 0:
|
|
@@ -585,7 +585,7 @@ describe("cache", function() {
|
|
|
585
585
|
];
|
|
586
586
|
case 2:
|
|
587
587
|
freshResult = _state.sent();
|
|
588
|
-
expect(
|
|
588
|
+
expect(freshResult === null || freshResult === void 0 ? void 0 : freshResult.isGarbage).toBe(false);
|
|
589
589
|
return [
|
|
590
590
|
4,
|
|
591
591
|
new Promise(function(resolve) {
|
|
@@ -602,7 +602,7 @@ describe("cache", function() {
|
|
|
602
602
|
];
|
|
603
603
|
case 4:
|
|
604
604
|
staleResult = _state.sent();
|
|
605
|
-
expect(
|
|
605
|
+
expect(staleResult === null || staleResult === void 0 ? void 0 : staleResult.isGarbage).toBe(true);
|
|
606
606
|
return [
|
|
607
607
|
2
|
|
608
608
|
];
|
|
@@ -5,11 +5,11 @@ import { Transform } from "stream";
|
|
|
5
5
|
import { ERROR_DIGEST } from "../../../constants";
|
|
6
6
|
import { createCache } from "./spr";
|
|
7
7
|
import { namespaceHash, withCoalescedInvoke } from "./util";
|
|
8
|
-
|
|
8
|
+
function cache_default(renderFn, ctx) {
|
|
9
9
|
var sprCache = createCache();
|
|
10
10
|
var doRender = function() {
|
|
11
11
|
var _ref = _async_to_generator(function(context) {
|
|
12
|
-
var
|
|
12
|
+
var cacheContext, cacheFile, renderResult, cacheHash, renderResult1, render;
|
|
13
13
|
function afterRender(source, onAfterRender) {
|
|
14
14
|
return _afterRender.apply(this, arguments);
|
|
15
15
|
}
|
|
@@ -124,7 +124,7 @@ export default function(renderFn, ctx) {
|
|
|
124
124
|
afterRender(renderResult, saveHtmlIntoCache)
|
|
125
125
|
];
|
|
126
126
|
case 3:
|
|
127
|
-
cacheHash =
|
|
127
|
+
cacheHash = cacheFile === null || cacheFile === void 0 ? void 0 : cacheFile.hash;
|
|
128
128
|
if (!cacheFile.isGarbage)
|
|
129
129
|
return [
|
|
130
130
|
3,
|
|
@@ -199,3 +199,6 @@ export default function(renderFn, ctx) {
|
|
|
199
199
|
return doRender;
|
|
200
200
|
}
|
|
201
201
|
;
|
|
202
|
+
export {
|
|
203
|
+
cache_default as default
|
|
204
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
2
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
3
3
|
import { LRUCaches } from "./lru";
|
|
4
|
-
|
|
4
|
+
function createPageCaches(max) {
|
|
5
5
|
return _createPageCaches.apply(this, arguments);
|
|
6
6
|
}
|
|
7
7
|
function _createPageCaches() {
|
|
@@ -11,7 +11,7 @@ function _createPageCaches() {
|
|
|
11
11
|
switch (_state.label) {
|
|
12
12
|
case 0:
|
|
13
13
|
constructorOptions = {
|
|
14
|
-
max
|
|
14
|
+
max
|
|
15
15
|
};
|
|
16
16
|
cacheInstance = new LRUCaches(constructorOptions);
|
|
17
17
|
return [
|
|
@@ -29,3 +29,6 @@ function _createPageCaches() {
|
|
|
29
29
|
});
|
|
30
30
|
return _createPageCaches.apply(this, arguments);
|
|
31
31
|
}
|
|
32
|
+
export {
|
|
33
|
+
createPageCaches
|
|
34
|
+
};
|
|
@@ -2,7 +2,7 @@ import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
|
|
|
2
2
|
import { _ as _create_class } from "@swc/helpers/_/_create_class";
|
|
3
3
|
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
4
4
|
import LRU from "lru-cache";
|
|
5
|
-
|
|
5
|
+
var LRUCaches = /* @__PURE__ */ function() {
|
|
6
6
|
"use strict";
|
|
7
7
|
function LRUCaches2(options) {
|
|
8
8
|
_class_call_check(this, LRUCaches2);
|
|
@@ -52,3 +52,6 @@ export var LRUCaches = /* @__PURE__ */ function() {
|
|
|
52
52
|
]);
|
|
53
53
|
return LRUCaches2;
|
|
54
54
|
}();
|
|
55
|
+
export {
|
|
56
|
+
LRUCaches
|
|
57
|
+
};
|
|
@@ -172,7 +172,7 @@ var CacheManager = /* @__PURE__ */ function() {
|
|
|
172
172
|
includes: config.includes || null,
|
|
173
173
|
limit: config.staleLimit,
|
|
174
174
|
matches: config.matches || null,
|
|
175
|
-
caches
|
|
175
|
+
caches
|
|
176
176
|
};
|
|
177
177
|
}
|
|
178
178
|
},
|
|
@@ -213,8 +213,8 @@ var CacheManager = /* @__PURE__ */ function() {
|
|
|
213
213
|
{
|
|
214
214
|
content: html || "",
|
|
215
215
|
contentType: mime.contentType("html"),
|
|
216
|
-
isStale
|
|
217
|
-
isGarbage
|
|
216
|
+
isStale,
|
|
217
|
+
isGarbage,
|
|
218
218
|
hash: cacheHash
|
|
219
219
|
}
|
|
220
220
|
];
|
|
@@ -277,9 +277,9 @@ var CacheManager = /* @__PURE__ */ function() {
|
|
|
277
277
|
next.caches.set(cacheHash, {
|
|
278
278
|
expireTime: Date.now() + cacheConfig.interval * 1e3,
|
|
279
279
|
limitTime: typeof limit === "number" ? Date.now() + limit * 1e3 : null,
|
|
280
|
-
cacheHash
|
|
280
|
+
cacheHash,
|
|
281
281
|
html: storeHTML,
|
|
282
|
-
size
|
|
282
|
+
size
|
|
283
283
|
})
|
|
284
284
|
];
|
|
285
285
|
case 1:
|
|
@@ -311,11 +311,11 @@ var CacheManager = /* @__PURE__ */ function() {
|
|
|
311
311
|
value: function del(context, cacheHash) {
|
|
312
312
|
var _this = this;
|
|
313
313
|
return _async_to_generator(function() {
|
|
314
|
-
var
|
|
314
|
+
var cacheKey, data;
|
|
315
315
|
return _ts_generator(this, function(_state) {
|
|
316
316
|
cacheKey = _this.generateRequestKey(context);
|
|
317
317
|
data = _this.cache.get(cacheKey);
|
|
318
|
-
|
|
318
|
+
data === null || data === void 0 ? void 0 : data.caches.del(cacheHash);
|
|
319
319
|
return [
|
|
320
320
|
2
|
|
321
321
|
];
|
|
@@ -327,7 +327,7 @@ var CacheManager = /* @__PURE__ */ function() {
|
|
|
327
327
|
return CacheManager2;
|
|
328
328
|
}();
|
|
329
329
|
var manager;
|
|
330
|
-
|
|
330
|
+
function createCache() {
|
|
331
331
|
if (manager) {
|
|
332
332
|
return manager;
|
|
333
333
|
}
|
|
@@ -336,6 +336,10 @@ export function createCache() {
|
|
|
336
336
|
});
|
|
337
337
|
return manager;
|
|
338
338
|
}
|
|
339
|
-
|
|
339
|
+
function destroyCache() {
|
|
340
340
|
manager = null;
|
|
341
341
|
}
|
|
342
|
+
export {
|
|
343
|
+
createCache,
|
|
344
|
+
destroyCache
|
|
345
|
+
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -4,19 +4,19 @@ import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
|
|
|
4
4
|
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
5
5
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
6
6
|
import url from "url";
|
|
7
|
-
|
|
7
|
+
function namespaceHash(namespace, hash) {
|
|
8
8
|
return "".concat(namespace, "/").concat(hash);
|
|
9
9
|
}
|
|
10
|
-
|
|
10
|
+
function fname(lv) {
|
|
11
11
|
return "f".concat(lv);
|
|
12
12
|
}
|
|
13
|
-
|
|
13
|
+
function connectFactor() {
|
|
14
14
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
15
15
|
args[_key] = arguments[_key];
|
|
16
16
|
}
|
|
17
17
|
return args.join("-");
|
|
18
18
|
}
|
|
19
|
-
|
|
19
|
+
function valueFactory(obj) {
|
|
20
20
|
if (_instanceof(obj, url.URLSearchParams)) {
|
|
21
21
|
return function(key) {
|
|
22
22
|
return obj.get(key);
|
|
@@ -31,17 +31,17 @@ export function valueFactory(obj) {
|
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
-
|
|
34
|
+
function getTime(param) {
|
|
35
35
|
var _param = _sliced_to_array(param, 2), s = _param[0], ns = _param[1];
|
|
36
36
|
return Math.floor(s * 1e3 + ns / 1e6);
|
|
37
37
|
}
|
|
38
38
|
var RE_START_IN_HEAD = /<head>/;
|
|
39
|
-
|
|
39
|
+
function cacheAddition(html, hash) {
|
|
40
40
|
var additionHtml = html.replace(RE_START_IN_HEAD, '<head><meta name="x-moden-spr" content="'.concat(hash, '">'));
|
|
41
41
|
return additionHtml;
|
|
42
42
|
}
|
|
43
43
|
var globalInvokeCache = /* @__PURE__ */ new Map();
|
|
44
|
-
|
|
44
|
+
function withCoalescedInvoke(func) {
|
|
45
45
|
return function() {
|
|
46
46
|
var _ref = _async_to_generator(function(key, args) {
|
|
47
47
|
var entry, future;
|
|
@@ -83,7 +83,7 @@ export function withCoalescedInvoke(func) {
|
|
|
83
83
|
};
|
|
84
84
|
}();
|
|
85
85
|
}
|
|
86
|
-
|
|
86
|
+
function maybeSync(fn) {
|
|
87
87
|
return function(sync) {
|
|
88
88
|
if (sync) {
|
|
89
89
|
return fn();
|
|
@@ -93,3 +93,13 @@ export function maybeSync(fn) {
|
|
|
93
93
|
}
|
|
94
94
|
};
|
|
95
95
|
}
|
|
96
|
+
export {
|
|
97
|
+
cacheAddition,
|
|
98
|
+
connectFactor,
|
|
99
|
+
fname,
|
|
100
|
+
getTime,
|
|
101
|
+
maybeSync,
|
|
102
|
+
namespaceHash,
|
|
103
|
+
valueFactory,
|
|
104
|
+
withCoalescedInvoke
|
|
105
|
+
};
|
|
@@ -8,7 +8,10 @@ import { handleDirectory } from "./static";
|
|
|
8
8
|
import { readFile } from "./reader";
|
|
9
9
|
import * as ssr from "./ssr";
|
|
10
10
|
import { injectServerData } from "./utils";
|
|
11
|
-
|
|
11
|
+
var calcFallback = function(metaName) {
|
|
12
|
+
return "x-".concat(cutNameByHyphen(metaName), "-ssr-fallback");
|
|
13
|
+
};
|
|
14
|
+
var createRenderHandler = function(param) {
|
|
12
15
|
var distDir = param.distDir, staticGenerate = param.staticGenerate, conf = param.conf, forceCSR = param.forceCSR, nonce = param.nonce, ssrRender = param.ssrRender, _param_metaName = param.metaName, metaName = _param_metaName === void 0 ? "modern-js" : _param_metaName;
|
|
13
16
|
return function() {
|
|
14
17
|
var _render = _async_to_generator(function(param2) {
|
|
@@ -54,7 +57,7 @@ export var createRenderHandler = function(param) {
|
|
|
54
57
|
null
|
|
55
58
|
];
|
|
56
59
|
}
|
|
57
|
-
useCSR = forceCSR && (ctx.query.csr || ctx.headers[
|
|
60
|
+
useCSR = forceCSR && (ctx.query.csr || ctx.headers[calcFallback(metaName)]);
|
|
58
61
|
if (!(route.isSSR && !useCSR))
|
|
59
62
|
return [
|
|
60
63
|
3,
|
|
@@ -83,8 +86,8 @@ export var createRenderHandler = function(param) {
|
|
|
83
86
|
flushServerHeader = _state.sent().flushServerHeader;
|
|
84
87
|
flushServerHeader({
|
|
85
88
|
serverConf: conf.server,
|
|
86
|
-
ctx
|
|
87
|
-
distDir
|
|
89
|
+
ctx,
|
|
90
|
+
distDir,
|
|
88
91
|
template: content.toString(),
|
|
89
92
|
headers: {
|
|
90
93
|
"Content-Type": mime.contentType(path.extname(templatePath))
|
|
@@ -93,24 +96,24 @@ export var createRenderHandler = function(param) {
|
|
|
93
96
|
_state.label = 6;
|
|
94
97
|
case 6:
|
|
95
98
|
ssrRenderOptions = {
|
|
96
|
-
distDir
|
|
99
|
+
distDir,
|
|
97
100
|
entryName: route.entryName,
|
|
98
101
|
urlPath: route.urlPath,
|
|
99
102
|
bundle: route.bundle,
|
|
100
103
|
template: content.toString(),
|
|
101
|
-
staticGenerate
|
|
102
|
-
nonce
|
|
104
|
+
staticGenerate,
|
|
105
|
+
nonce
|
|
103
106
|
};
|
|
104
107
|
return [
|
|
105
108
|
4,
|
|
106
109
|
ssrRender ? ssrRender(ctx, ssrRenderOptions, runner) : ssr.render(ctx, {
|
|
107
|
-
distDir
|
|
110
|
+
distDir,
|
|
108
111
|
entryName: route.entryName,
|
|
109
112
|
urlPath: route.urlPath,
|
|
110
113
|
bundle: route.bundle,
|
|
111
114
|
template: content.toString(),
|
|
112
|
-
staticGenerate
|
|
113
|
-
nonce
|
|
115
|
+
staticGenerate,
|
|
116
|
+
nonce
|
|
114
117
|
}, runner)
|
|
115
118
|
];
|
|
116
119
|
case 7:
|
|
@@ -122,7 +125,7 @@ export var createRenderHandler = function(param) {
|
|
|
122
125
|
case 8:
|
|
123
126
|
err = _state.sent();
|
|
124
127
|
ctx.error(ERROR_DIGEST.ERENDER, err.stack || err.message);
|
|
125
|
-
ctx.res.set(
|
|
128
|
+
ctx.res.set(calcFallback(metaName), "1");
|
|
126
129
|
return [
|
|
127
130
|
3,
|
|
128
131
|
9
|
|
@@ -144,3 +147,6 @@ export var createRenderHandler = function(param) {
|
|
|
144
147
|
return render;
|
|
145
148
|
}();
|
|
146
149
|
};
|
|
150
|
+
export {
|
|
151
|
+
createRenderHandler
|
|
152
|
+
};
|
|
@@ -3,29 +3,29 @@ import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
|
3
3
|
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
4
4
|
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
5
5
|
import { headersWithoutCookie } from "../../utils";
|
|
6
|
-
|
|
6
|
+
var createMetrics = function(context, metrics) {
|
|
7
7
|
var entry = context.entryName, request = context.request;
|
|
8
8
|
var _ref = request || {}, _ref_pathname = _ref.pathname, pathname = _ref_pathname === void 0 ? "" : _ref_pathname;
|
|
9
9
|
var emitTimer = function(name, cost) {
|
|
10
10
|
var tags = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
11
11
|
metrics.emitTimer(name, cost, _object_spread_props(_object_spread({}, tags), {
|
|
12
|
-
pathname
|
|
13
|
-
entry
|
|
12
|
+
pathname,
|
|
13
|
+
entry
|
|
14
14
|
}));
|
|
15
15
|
};
|
|
16
16
|
var emitCounter = function(name, counter) {
|
|
17
17
|
var tags = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
18
18
|
metrics.emitCounter(name, counter, _object_spread_props(_object_spread({}, tags), {
|
|
19
|
-
pathname
|
|
20
|
-
entry
|
|
19
|
+
pathname,
|
|
20
|
+
entry
|
|
21
21
|
}));
|
|
22
22
|
};
|
|
23
23
|
return {
|
|
24
|
-
emitTimer
|
|
25
|
-
emitCounter
|
|
24
|
+
emitTimer,
|
|
25
|
+
emitCounter
|
|
26
26
|
};
|
|
27
27
|
};
|
|
28
|
-
|
|
28
|
+
var createLogger = function(serverContext, logger) {
|
|
29
29
|
var request = serverContext.request || {};
|
|
30
30
|
var _request_headers = request.headers, headers = _request_headers === void 0 ? {} : _request_headers, _request_pathname = request.pathname, pathname = _request_pathname === void 0 ? "" : _request_pathname;
|
|
31
31
|
var debug = function(message) {
|
|
@@ -58,8 +58,12 @@ export var createLogger = function(serverContext, logger) {
|
|
|
58
58
|
logger.error("SSR Error - ".concat(message, ", error = %s, req.url = %s, req.headers = %o"), _instanceof(e, Error) ? e.stack || e.message : e, pathname, headersWithoutCookie(headers));
|
|
59
59
|
};
|
|
60
60
|
return {
|
|
61
|
-
error
|
|
62
|
-
info
|
|
63
|
-
debug
|
|
61
|
+
error,
|
|
62
|
+
info,
|
|
63
|
+
debug
|
|
64
64
|
};
|
|
65
65
|
};
|
|
66
|
+
export {
|
|
67
|
+
createLogger,
|
|
68
|
+
createMetrics
|
|
69
|
+
};
|