@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,26 +1,47 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.
|
|
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 __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
9
17
|
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var parseLinks_exports = {};
|
|
30
|
+
__export(parseLinks_exports, {
|
|
31
|
+
parseLinks: () => parseLinks
|
|
10
32
|
});
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const _runtimenode = require("@modern-js/utils/runtime-node");
|
|
33
|
+
module.exports = __toCommonJS(parseLinks_exports);
|
|
34
|
+
var import_path = __toESM(require("path"));
|
|
35
|
+
var import_utils = require("@modern-js/utils");
|
|
36
|
+
var import_node_html_parser = require("node-html-parser");
|
|
37
|
+
var import_remix_router = require("@modern-js/runtime-utils/remix-router");
|
|
38
|
+
var import_node = require("@modern-js/runtime-utils/node");
|
|
18
39
|
async function parseLinks({ pathname, distDir, template }) {
|
|
19
40
|
const links = await parseLinksFromRoutes(pathname, distDir);
|
|
20
41
|
return links.concat(parseLinksFromHtml(template));
|
|
21
42
|
}
|
|
22
43
|
function parseLinksFromHtml(html) {
|
|
23
|
-
const root = (0,
|
|
44
|
+
const root = (0, import_node_html_parser.parse)(html);
|
|
24
45
|
const scripts = root.querySelectorAll("script").filter((elem) => Boolean(elem.getAttribute("src")));
|
|
25
46
|
const css = root.querySelectorAll("link").filter((elem) => {
|
|
26
47
|
const href = elem.getAttribute("href");
|
|
@@ -50,18 +71,18 @@ function parseLinksFromHtml(html) {
|
|
|
50
71
|
}
|
|
51
72
|
async function parseLinksFromRoutes(pathname, distDir) {
|
|
52
73
|
const noopLinks = [];
|
|
53
|
-
const nestedRoutesSpec =
|
|
54
|
-
const routesJsonPath =
|
|
55
|
-
const routeManifestPath =
|
|
56
|
-
if (!
|
|
74
|
+
const nestedRoutesSpec = import_path.default.join(distDir, import_utils.NESTED_ROUTE_SPEC_FILE);
|
|
75
|
+
const routesJsonPath = import_path.default.join(distDir, import_utils.ROUTE_SPEC_FILE);
|
|
76
|
+
const routeManifestPath = import_path.default.join(distDir, import_utils.ROUTE_MANIFEST_FILE);
|
|
77
|
+
if (!import_utils.fs.existsSync(nestedRoutesSpec) || !import_utils.fs.existsSync(routesJsonPath) || !import_utils.fs.existsSync(routeManifestPath)) {
|
|
57
78
|
return noopLinks;
|
|
58
79
|
}
|
|
59
|
-
const routesJson = await Promise.resolve(
|
|
80
|
+
const routesJson = await Promise.resolve().then(() => __toESM(require(routesJsonPath)));
|
|
60
81
|
const serverRoutes = routesJson.routes;
|
|
61
|
-
const entry = (0,
|
|
82
|
+
const entry = (0, import_node.matchEntry)(pathname, serverRoutes);
|
|
62
83
|
if (entry) {
|
|
63
|
-
var _routeAssets_entryName,
|
|
64
|
-
const routes = await Promise.resolve(
|
|
84
|
+
var _routeAssets_entryName, _assets_filter, _assets_filter1;
|
|
85
|
+
const routes = await Promise.resolve().then(() => __toESM(require(nestedRoutesSpec)));
|
|
65
86
|
const { entryName } = entry;
|
|
66
87
|
if (!entryName) {
|
|
67
88
|
return noopLinks;
|
|
@@ -70,27 +91,26 @@ async function parseLinksFromRoutes(pathname, distDir) {
|
|
|
70
91
|
if (!entryRoutes) {
|
|
71
92
|
return noopLinks;
|
|
72
93
|
}
|
|
73
|
-
const routesManifest = await Promise.resolve(
|
|
94
|
+
const routesManifest = await Promise.resolve().then(() => __toESM(require(routeManifestPath)));
|
|
74
95
|
const { routeAssets } = routesManifest;
|
|
75
|
-
const matches = (0,
|
|
96
|
+
const matches = (0, import_remix_router.matchRoutes)(entryRoutes, pathname, entry.urlPath);
|
|
76
97
|
const entryAssets = (_routeAssets_entryName = routeAssets[entryName]) === null || _routeAssets_entryName === void 0 ? void 0 : _routeAssets_entryName.assets;
|
|
77
|
-
const assets =
|
|
98
|
+
const assets = matches === null || matches === void 0 ? void 0 : matches.reduce((acc, match) => {
|
|
78
99
|
const routeId = match.route.id;
|
|
79
100
|
if (routeId) {
|
|
80
|
-
var _matchedManifest;
|
|
81
101
|
const matchedManifest = routeAssets[routeId];
|
|
82
|
-
const assets2 =
|
|
102
|
+
const assets2 = matchedManifest === null || matchedManifest === void 0 ? void 0 : matchedManifest.assets;
|
|
83
103
|
if (Array.isArray(assets2)) {
|
|
84
104
|
acc.push(...assets2);
|
|
85
105
|
}
|
|
86
106
|
}
|
|
87
107
|
return acc;
|
|
88
108
|
}, []).concat(entryAssets || []);
|
|
89
|
-
const cssLinks =
|
|
109
|
+
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) => ({
|
|
90
110
|
uri,
|
|
91
111
|
as: "style"
|
|
92
112
|
}));
|
|
93
|
-
const scriptLinks =
|
|
113
|
+
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) => ({
|
|
94
114
|
uri,
|
|
95
115
|
as: "script"
|
|
96
116
|
}));
|
|
@@ -98,3 +118,7 @@ async function parseLinksFromRoutes(pathname, distDir) {
|
|
|
98
118
|
}
|
|
99
119
|
return noopLinks;
|
|
100
120
|
}
|
|
121
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
122
|
+
0 && (module.exports = {
|
|
123
|
+
parseLinks
|
|
124
|
+
});
|
|
@@ -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));
|
|
@@ -18,7 +31,6 @@ function transformLinks2String(links, preload) {
|
|
|
18
31
|
return resolveLinks;
|
|
19
32
|
}
|
|
20
33
|
function addInclude(links, include) {
|
|
21
|
-
var _include;
|
|
22
34
|
const images = [
|
|
23
35
|
"gif",
|
|
24
36
|
"jpg",
|
|
@@ -44,7 +56,7 @@ function addInclude(links, include) {
|
|
|
44
56
|
"ttf",
|
|
45
57
|
"otf"
|
|
46
58
|
];
|
|
47
|
-
const includes = (
|
|
59
|
+
const includes = (include === null || include === void 0 ? void 0 : include.map((item) => {
|
|
48
60
|
if (typeof item === "string") {
|
|
49
61
|
const type = (() => {
|
|
50
62
|
if (item.endsWith(".js")) {
|
|
@@ -77,7 +89,7 @@ function addInclude(links, include) {
|
|
|
77
89
|
return links.concat(includes);
|
|
78
90
|
}
|
|
79
91
|
function removeExclude(links, exclude) {
|
|
80
|
-
return exclude ? links.filter(({ uri }) => !(0,
|
|
92
|
+
return exclude ? links.filter(({ uri }) => !(0, import_shouldFlushServerHeader.transformToRegExp)(exclude).test(uri)) : links;
|
|
81
93
|
}
|
|
82
94
|
function addAttributes(links, attributes) {
|
|
83
95
|
const parseAttributes = (_attributes) => {
|
|
@@ -132,3 +144,7 @@ function transformLinkToString(links) {
|
|
|
132
144
|
return as ? `<${uri}>; rel=${rel}; as=${as}${rest || ""}` : `<${uri}>; rel=${rel}${rest || ""}`;
|
|
133
145
|
}).join(", ");
|
|
134
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,9 +16,8 @@ const createCacheConfig = (config = {}) => ({
|
|
|
19
16
|
jest.setTimeout(6e4);
|
|
20
17
|
describe("cache", () => {
|
|
21
18
|
it("should cache correctly", async () => {
|
|
22
|
-
|
|
23
|
-
(0,
|
|
24
|
-
const cache = (0, _spr.createCache)();
|
|
19
|
+
(0, import_spr.destroyCache)();
|
|
20
|
+
const cache = (0, import_spr.createCache)();
|
|
25
21
|
const context = {
|
|
26
22
|
entry: "",
|
|
27
23
|
pathname: "",
|
|
@@ -33,12 +29,12 @@ describe("cache", () => {
|
|
|
33
29
|
await cache.set(context, content, cacheConfig, true);
|
|
34
30
|
const cacheResult = await cache.get(context);
|
|
35
31
|
expect(cacheResult).not.toBe(null);
|
|
36
|
-
expect(
|
|
32
|
+
expect(cacheResult === null || cacheResult === void 0 ? void 0 : cacheResult.content).toBe("hello");
|
|
37
33
|
});
|
|
38
34
|
it("should ignore cache set when cache config not exist", async () => {
|
|
39
|
-
(0,
|
|
40
|
-
(0,
|
|
41
|
-
const cache = (0,
|
|
35
|
+
(0, import_spr.destroyCache)();
|
|
36
|
+
(0, import_spr.destroyCache)();
|
|
37
|
+
const cache = (0, import_spr.createCache)();
|
|
42
38
|
const context = {
|
|
43
39
|
entry: "",
|
|
44
40
|
pathname: "",
|
|
@@ -50,10 +46,10 @@ describe("cache", () => {
|
|
|
50
46
|
expect(shouldCache).toBe(false);
|
|
51
47
|
});
|
|
52
48
|
it("should calcual cache key error", async () => {
|
|
53
|
-
(0,
|
|
54
|
-
const cache = (0,
|
|
49
|
+
(0, import_spr.destroyCache)();
|
|
50
|
+
const cache = (0, import_spr.createCache)();
|
|
55
51
|
const content = "hello";
|
|
56
|
-
for (const config of
|
|
52
|
+
for (const config of import_error_configuration.errorConfiguration) {
|
|
57
53
|
const cacheConfig = createCacheConfig(config);
|
|
58
54
|
const tmpEntry = Math.random().toString();
|
|
59
55
|
const context = {
|
|
@@ -67,8 +63,8 @@ describe("cache", () => {
|
|
|
67
63
|
}
|
|
68
64
|
});
|
|
69
65
|
it("should get nothing for diff requestKey", async () => {
|
|
70
|
-
(0,
|
|
71
|
-
const cache = (0,
|
|
66
|
+
(0, import_spr.destroyCache)();
|
|
67
|
+
const cache = (0, import_spr.createCache)();
|
|
72
68
|
const context = {
|
|
73
69
|
entry: "",
|
|
74
70
|
pathname: "",
|
|
@@ -95,8 +91,8 @@ describe("cache", () => {
|
|
|
95
91
|
expect(cacheResult).toBe(null);
|
|
96
92
|
});
|
|
97
93
|
it("should get nothing for diff cacheHash", async () => {
|
|
98
|
-
(0,
|
|
99
|
-
const cache = (0,
|
|
94
|
+
(0, import_spr.destroyCache)();
|
|
95
|
+
const cache = (0, import_spr.createCache)();
|
|
100
96
|
const context = {
|
|
101
97
|
entry: "",
|
|
102
98
|
pathname: "",
|
|
@@ -125,10 +121,9 @@ describe("cache", () => {
|
|
|
125
121
|
expect(cacheResult).toBe(null);
|
|
126
122
|
});
|
|
127
123
|
it("should get cache correctly", async () => {
|
|
128
|
-
(0,
|
|
129
|
-
const cache = (0,
|
|
130
|
-
for (const cacheable of
|
|
131
|
-
var _cacheResult;
|
|
124
|
+
(0, import_spr.destroyCache)();
|
|
125
|
+
const cache = (0, import_spr.createCache)();
|
|
126
|
+
for (const cacheable of import_cacheable.cacheabelAry) {
|
|
132
127
|
const context = {
|
|
133
128
|
entry: "",
|
|
134
129
|
pathname: cacheable.requestOpt.url,
|
|
@@ -138,14 +133,13 @@ describe("cache", () => {
|
|
|
138
133
|
const cacheConfig = createCacheConfig(cacheable.cacheConfig || {});
|
|
139
134
|
await cache.set(context, cacheable.content, cacheConfig, true);
|
|
140
135
|
const cacheResult = await cache.get(context);
|
|
141
|
-
expect(
|
|
136
|
+
expect(cacheResult === null || cacheResult === void 0 ? void 0 : cacheResult.content).toBe(cacheable.content);
|
|
142
137
|
}
|
|
143
138
|
});
|
|
144
139
|
it("should match cache correctly", async () => {
|
|
145
|
-
(0,
|
|
146
|
-
const cache = (0,
|
|
147
|
-
for (const cacheable of
|
|
148
|
-
var _cacheResult;
|
|
140
|
+
(0, import_spr.destroyCache)();
|
|
141
|
+
const cache = (0, import_spr.createCache)();
|
|
142
|
+
for (const cacheable of import_matched_cache.matchedCacheableAry) {
|
|
149
143
|
const [baseCacheable, matchOne, ...other] = cacheable;
|
|
150
144
|
const { requestOpt = {}, cacheConfig, content } = baseCacheable;
|
|
151
145
|
const context = {
|
|
@@ -162,7 +156,7 @@ describe("cache", () => {
|
|
|
162
156
|
headers: matchOne.headers
|
|
163
157
|
};
|
|
164
158
|
const cacheResult = await cache.get(matchContext);
|
|
165
|
-
expect(
|
|
159
|
+
expect(cacheResult === null || cacheResult === void 0 ? void 0 : cacheResult.content).toBe(content);
|
|
166
160
|
for (const notMatch of other) {
|
|
167
161
|
const notMatchContext = {
|
|
168
162
|
entry: "",
|
|
@@ -176,9 +170,8 @@ describe("cache", () => {
|
|
|
176
170
|
}
|
|
177
171
|
});
|
|
178
172
|
it("should stale cache correctly", async () => {
|
|
179
|
-
|
|
180
|
-
(0,
|
|
181
|
-
const cache = (0, _spr.createCache)();
|
|
173
|
+
(0, import_spr.destroyCache)();
|
|
174
|
+
const cache = (0, import_spr.createCache)();
|
|
182
175
|
const context = {
|
|
183
176
|
entry: "",
|
|
184
177
|
pathname: "",
|
|
@@ -192,19 +185,18 @@ describe("cache", () => {
|
|
|
192
185
|
const shouldCache = await cache.set(context, content, config, true);
|
|
193
186
|
expect(shouldCache.value).toBe(true);
|
|
194
187
|
const freshResult = await cache.get(context);
|
|
195
|
-
expect(
|
|
188
|
+
expect(freshResult === null || freshResult === void 0 ? void 0 : freshResult.isStale).toBe(false);
|
|
196
189
|
await new Promise((resolve) => {
|
|
197
190
|
setTimeout(() => {
|
|
198
191
|
resolve();
|
|
199
192
|
}, 6e3);
|
|
200
193
|
});
|
|
201
194
|
const staleResult = await cache.get(context);
|
|
202
|
-
expect(
|
|
195
|
+
expect(staleResult === null || staleResult === void 0 ? void 0 : staleResult.isStale).toBe(true);
|
|
203
196
|
});
|
|
204
197
|
it("should garbage cache correctly", async () => {
|
|
205
|
-
|
|
206
|
-
(0,
|
|
207
|
-
const cache = (0, _spr.createCache)();
|
|
198
|
+
(0, import_spr.destroyCache)();
|
|
199
|
+
const cache = (0, import_spr.createCache)();
|
|
208
200
|
const context = {
|
|
209
201
|
entry: "",
|
|
210
202
|
pathname: "",
|
|
@@ -219,13 +211,13 @@ describe("cache", () => {
|
|
|
219
211
|
const shouldCache = await cache.set(context, content, config, true);
|
|
220
212
|
expect(shouldCache.value).toBe(true);
|
|
221
213
|
const freshResult = await cache.get(context);
|
|
222
|
-
expect(
|
|
214
|
+
expect(freshResult === null || freshResult === void 0 ? void 0 : freshResult.isGarbage).toBe(false);
|
|
223
215
|
await new Promise((resolve) => {
|
|
224
216
|
setTimeout(() => {
|
|
225
217
|
resolve();
|
|
226
218
|
}, 1e4);
|
|
227
219
|
});
|
|
228
220
|
const staleResult = await cache.get(context);
|
|
229
|
-
expect(
|
|
221
|
+
expect(staleResult === null || staleResult === void 0 ? void 0 : staleResult.isGarbage).toBe(true);
|
|
230
222
|
});
|
|
231
223
|
});
|
|
@@ -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
|
+
});
|