@modern-js/prod-server 2.9.1-alpha.0 → 2.10.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/CHANGELOG.md +25 -0
- package/dist/cjs/libs/hook-api/index.js +7 -26
- package/dist/cjs/libs/render/index.js +2 -1
- package/dist/cjs/libs/render/ssr.js +3 -2
- package/dist/{js/node/libs/metrics.js → cjs/libs/render/utils.js} +25 -12
- package/dist/cjs/server/index.js +1 -1
- package/dist/cjs/server/modernServer.js +75 -80
- package/dist/esm/libs/hook-api/index.js +9 -37
- package/dist/esm/libs/render/index.js +2 -1
- package/dist/esm/libs/render/ssr.js +3 -2
- package/dist/esm/libs/render/utils.js +12 -0
- package/dist/esm/server/index.js +2 -2
- package/dist/esm/server/modernServer.js +108 -103
- package/dist/esm-node/libs/hook-api/index.js +7 -26
- package/dist/esm-node/libs/render/index.js +2 -1
- package/dist/esm-node/libs/render/ssr.js +3 -2
- package/dist/esm-node/libs/render/utils.js +23 -0
- package/dist/esm-node/server/index.js +1 -1
- package/dist/esm-node/server/modernServer.js +75 -80
- package/dist/types/libs/context/context.d.ts +1 -1
- package/dist/types/libs/render/utils.d.ts +5 -0
- package/dist/types/server/index.d.ts +2 -1
- package/dist/types/server/modernServer.d.ts +4 -4
- package/dist/types/type.d.ts +1 -1
- package/dist/types/utils.d.ts +1 -1
- package/package.json +9 -7
- package/dist/js/modern/constants.js +0 -35
- package/dist/js/modern/index.js +0 -18
- package/dist/js/modern/libs/context/context.js +0 -160
- package/dist/js/modern/libs/context/index.js +0 -6
- package/dist/js/modern/libs/hook-api/index.js +0 -134
- package/dist/js/modern/libs/hook-api/route.js +0 -20
- package/dist/js/modern/libs/hook-api/template.js +0 -73
- package/dist/js/modern/libs/loadConfig.js +0 -62
- package/dist/js/modern/libs/logger.js +0 -111
- package/dist/js/modern/libs/metrics.js +0 -11
- package/dist/js/modern/libs/proxy.js +0 -92
- package/dist/js/modern/libs/render/cache/__tests__/cache.fun.test.js +0 -114
- package/dist/js/modern/libs/render/cache/__tests__/cache.test.js +0 -254
- package/dist/js/modern/libs/render/cache/__tests__/cacheable.js +0 -47
- package/dist/js/modern/libs/render/cache/__tests__/error-configuration.js +0 -37
- package/dist/js/modern/libs/render/cache/__tests__/matched-cache.js +0 -91
- package/dist/js/modern/libs/render/cache/index.js +0 -115
- package/dist/js/modern/libs/render/cache/page-caches/index.js +0 -32
- package/dist/js/modern/libs/render/cache/page-caches/lru.js +0 -29
- package/dist/js/modern/libs/render/cache/spr.js +0 -248
- package/dist/js/modern/libs/render/cache/type.js +0 -0
- package/dist/js/modern/libs/render/cache/util.js +0 -102
- package/dist/js/modern/libs/render/index.js +0 -86
- package/dist/js/modern/libs/render/measure.js +0 -68
- package/dist/js/modern/libs/render/reader.js +0 -107
- package/dist/js/modern/libs/render/ssr.js +0 -100
- package/dist/js/modern/libs/render/static.js +0 -60
- package/dist/js/modern/libs/render/type.js +0 -9
- package/dist/js/modern/libs/route/index.js +0 -54
- package/dist/js/modern/libs/route/matcher.js +0 -87
- package/dist/js/modern/libs/route/route.js +0 -16
- package/dist/js/modern/libs/serve-file.js +0 -67
- package/dist/js/modern/server/index.js +0 -208
- package/dist/js/modern/server/modern-server-split.js +0 -74
- package/dist/js/modern/server/modern-server.js +0 -554
- package/dist/js/modern/type.js +0 -0
- package/dist/js/modern/utils.js +0 -136
- package/dist/js/modern/worker-server.js +0 -89
- package/dist/js/node/constants.js +0 -62
- package/dist/js/node/index.js +0 -44
- package/dist/js/node/libs/context/context.js +0 -189
- package/dist/js/node/libs/context/index.js +0 -30
- package/dist/js/node/libs/hook-api/index.js +0 -164
- package/dist/js/node/libs/hook-api/route.js +0 -43
- package/dist/js/node/libs/hook-api/template.js +0 -97
- package/dist/js/node/libs/loadConfig.js +0 -91
- package/dist/js/node/libs/logger.js +0 -133
- package/dist/js/node/libs/proxy.js +0 -114
- package/dist/js/node/libs/render/cache/__tests__/cache.fun.test.js +0 -115
- package/dist/js/node/libs/render/cache/__tests__/cache.test.js +0 -245
- package/dist/js/node/libs/render/cache/__tests__/cacheable.js +0 -70
- package/dist/js/node/libs/render/cache/__tests__/error-configuration.js +0 -60
- package/dist/js/node/libs/render/cache/__tests__/matched-cache.js +0 -114
- package/dist/js/node/libs/render/cache/index.js +0 -134
- package/dist/js/node/libs/render/cache/page-caches/index.js +0 -55
- package/dist/js/node/libs/render/cache/page-caches/lru.js +0 -58
- package/dist/js/node/libs/render/cache/spr.js +0 -270
- package/dist/js/node/libs/render/cache/type.js +0 -15
- package/dist/js/node/libs/render/cache/util.js +0 -138
- package/dist/js/node/libs/render/index.js +0 -115
- package/dist/js/node/libs/render/measure.js +0 -90
- package/dist/js/node/libs/render/reader.js +0 -140
- package/dist/js/node/libs/render/ssr.js +0 -123
- package/dist/js/node/libs/render/static.js +0 -89
- package/dist/js/node/libs/render/type.js +0 -32
- package/dist/js/node/libs/route/index.js +0 -78
- package/dist/js/node/libs/route/matcher.js +0 -106
- package/dist/js/node/libs/route/route.js +0 -39
- package/dist/js/node/libs/serve-file.js +0 -97
- package/dist/js/node/server/index.js +0 -219
- package/dist/js/node/server/modern-server-split.js +0 -97
- package/dist/js/node/server/modern-server.js +0 -559
- package/dist/js/node/type.js +0 -15
- package/dist/js/node/utils.js +0 -166
- package/dist/js/node/worker-server.js +0 -113
- package/dist/js/treeshaking/constants.js +0 -29
- package/dist/js/treeshaking/index.js +0 -13
- package/dist/js/treeshaking/libs/context/context.js +0 -274
- package/dist/js/treeshaking/libs/context/index.js +0 -5
- package/dist/js/treeshaking/libs/hook-api/index.js +0 -281
- package/dist/js/treeshaking/libs/hook-api/route.js +0 -68
- package/dist/js/treeshaking/libs/hook-api/template.js +0 -127
- package/dist/js/treeshaking/libs/loadConfig.js +0 -82
- package/dist/js/treeshaking/libs/logger.js +0 -205
- package/dist/js/treeshaking/libs/metrics.js +0 -6
- package/dist/js/treeshaking/libs/proxy.js +0 -244
- package/dist/js/treeshaking/libs/render/cache/__tests__/cache.fun.test.js +0 -291
- package/dist/js/treeshaking/libs/render/cache/__tests__/cache.test.js +0 -781
- package/dist/js/treeshaking/libs/render/cache/__tests__/cacheable.js +0 -67
- package/dist/js/treeshaking/libs/render/cache/__tests__/error-configuration.js +0 -45
- package/dist/js/treeshaking/libs/render/cache/__tests__/matched-cache.js +0 -147
- package/dist/js/treeshaking/libs/render/cache/index.js +0 -346
- package/dist/js/treeshaking/libs/render/cache/page-caches/index.js +0 -154
- package/dist/js/treeshaking/libs/render/cache/page-caches/lru.js +0 -84
- package/dist/js/treeshaking/libs/render/cache/spr.js +0 -492
- package/dist/js/treeshaking/libs/render/cache/type.js +0 -1
- package/dist/js/treeshaking/libs/render/cache/util.js +0 -280
- package/dist/js/treeshaking/libs/render/index.js +0 -234
- package/dist/js/treeshaking/libs/render/measure.js +0 -146
- package/dist/js/treeshaking/libs/render/reader.js +0 -339
- package/dist/js/treeshaking/libs/render/ssr.js +0 -223
- package/dist/js/treeshaking/libs/render/static.js +0 -216
- package/dist/js/treeshaking/libs/render/type.js +0 -7
- package/dist/js/treeshaking/libs/route/index.js +0 -130
- package/dist/js/treeshaking/libs/route/matcher.js +0 -143
- package/dist/js/treeshaking/libs/route/route.js +0 -40
- package/dist/js/treeshaking/libs/serve-file.js +0 -184
- package/dist/js/treeshaking/server/index.js +0 -505
- package/dist/js/treeshaking/server/modern-server-split.js +0 -360
- package/dist/js/treeshaking/server/modern-server.js +0 -1089
- package/dist/js/treeshaking/type.js +0 -1
- package/dist/js/treeshaking/utils.js +0 -147
- package/dist/js/treeshaking/worker-server.js +0 -233
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defProps = Object.defineProperties;
|
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
12
|
-
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
17
|
-
return a;
|
|
18
|
-
};
|
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
import cookie from "cookie";
|
|
21
|
-
import { RouteAPI } from "./route";
|
|
22
|
-
import { TemplateAPI } from "./template";
|
|
23
|
-
class Response {
|
|
24
|
-
constructor(res) {
|
|
25
|
-
this.res = res;
|
|
26
|
-
this._cookie = cookie.parse(res.getHeader("set-cookie") || "");
|
|
27
|
-
this.cookies = {
|
|
28
|
-
get: this.getCookie.bind(this),
|
|
29
|
-
set: this.setCookie.bind(this),
|
|
30
|
-
delete: this.deleteCookie.bind(this),
|
|
31
|
-
clear: this.clearCookie.bind(this),
|
|
32
|
-
apply: this.applyCookie.bind(this)
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
get(key) {
|
|
36
|
-
return this.res.getHeader(key);
|
|
37
|
-
}
|
|
38
|
-
set(key, value) {
|
|
39
|
-
return this.res.setHeader(key, value);
|
|
40
|
-
}
|
|
41
|
-
status(code) {
|
|
42
|
-
this.res.statusCode = code;
|
|
43
|
-
}
|
|
44
|
-
getCookie(key) {
|
|
45
|
-
return this._cookie[key];
|
|
46
|
-
}
|
|
47
|
-
setCookie(key, value) {
|
|
48
|
-
this._cookie[key] = value;
|
|
49
|
-
}
|
|
50
|
-
deleteCookie(key) {
|
|
51
|
-
if (this._cookie[key]) {
|
|
52
|
-
delete this._cookie[key];
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
clearCookie() {
|
|
56
|
-
this._cookie = {};
|
|
57
|
-
}
|
|
58
|
-
applyCookie() {
|
|
59
|
-
const str = Object.entries(this._cookie).map(([key, value]) => {
|
|
60
|
-
return cookie.serialize(key, value);
|
|
61
|
-
}).join("; ");
|
|
62
|
-
if (str) {
|
|
63
|
-
this.res.setHeader("set-cookie", str);
|
|
64
|
-
} else {
|
|
65
|
-
this.res.removeHeader("set-cookie");
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
raw(body, options) {
|
|
69
|
-
const { status, headers = {} } = options || {};
|
|
70
|
-
Object.entries(headers).forEach(([key, value]) => {
|
|
71
|
-
this.res.setHeader(key, value);
|
|
72
|
-
});
|
|
73
|
-
if (status) {
|
|
74
|
-
this.res.statusCode = status;
|
|
75
|
-
}
|
|
76
|
-
this.res.end(body);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
class Request {
|
|
80
|
-
constructor(ctx) {
|
|
81
|
-
this.url = ctx.url;
|
|
82
|
-
this.host = ctx.host;
|
|
83
|
-
this.pathname = ctx.path;
|
|
84
|
-
this.query = ctx.query;
|
|
85
|
-
this.headers = ctx.headers;
|
|
86
|
-
this.cookie = ctx.headers.cookie || "";
|
|
87
|
-
this._cookie = cookie.parse(this.cookie);
|
|
88
|
-
this.cookies = {
|
|
89
|
-
get: this.getCookie.bind(this)
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
getCookie(key) {
|
|
93
|
-
return this._cookie[key];
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
const base = (context) => {
|
|
97
|
-
const { res } = context;
|
|
98
|
-
return {
|
|
99
|
-
response: new Response(res),
|
|
100
|
-
request: new Request(context),
|
|
101
|
-
logger: context.logger,
|
|
102
|
-
metrics: context.metrics
|
|
103
|
-
};
|
|
104
|
-
};
|
|
105
|
-
const createAfterMatchContext = (context, entryName) => {
|
|
106
|
-
const baseContext = base(context);
|
|
107
|
-
return __spreadProps(__spreadValues({}, baseContext), {
|
|
108
|
-
router: new RouteAPI(entryName)
|
|
109
|
-
});
|
|
110
|
-
};
|
|
111
|
-
const createAfterRenderContext = (context, content) => {
|
|
112
|
-
const baseContext = base(context);
|
|
113
|
-
return __spreadProps(__spreadValues({}, baseContext), {
|
|
114
|
-
template: new TemplateAPI(content)
|
|
115
|
-
});
|
|
116
|
-
};
|
|
117
|
-
const createMiddlewareContext = (context) => {
|
|
118
|
-
const baseContext = base(context);
|
|
119
|
-
return __spreadProps(__spreadValues({}, baseContext), {
|
|
120
|
-
response: __spreadProps(__spreadValues({}, baseContext.response), {
|
|
121
|
-
locals: context.res.locals || {}
|
|
122
|
-
}),
|
|
123
|
-
source: {
|
|
124
|
-
req: context.req,
|
|
125
|
-
res: context.res
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
};
|
|
129
|
-
export {
|
|
130
|
-
base,
|
|
131
|
-
createAfterMatchContext,
|
|
132
|
-
createAfterRenderContext,
|
|
133
|
-
createMiddlewareContext
|
|
134
|
-
};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
class RouteAPI {
|
|
2
|
-
constructor(entryName) {
|
|
3
|
-
this.current = entryName;
|
|
4
|
-
this.status = 200;
|
|
5
|
-
this.url = "";
|
|
6
|
-
}
|
|
7
|
-
redirect(url, status = 302) {
|
|
8
|
-
this.url = url;
|
|
9
|
-
this.status = status;
|
|
10
|
-
}
|
|
11
|
-
rewrite(entryName) {
|
|
12
|
-
this.current = entryName;
|
|
13
|
-
}
|
|
14
|
-
use(entryName) {
|
|
15
|
-
this.rewrite(entryName);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
export {
|
|
19
|
-
RouteAPI
|
|
20
|
-
};
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { Transform } from "stream";
|
|
2
|
-
const RegList = {
|
|
3
|
-
before: {
|
|
4
|
-
head: "<head>",
|
|
5
|
-
body: "<body>"
|
|
6
|
-
},
|
|
7
|
-
after: {
|
|
8
|
-
head: "</head>",
|
|
9
|
-
body: "</body>"
|
|
10
|
-
}
|
|
11
|
-
};
|
|
12
|
-
class TemplateAPI {
|
|
13
|
-
constructor(content) {
|
|
14
|
-
this.content = content;
|
|
15
|
-
}
|
|
16
|
-
get() {
|
|
17
|
-
return this.content;
|
|
18
|
-
}
|
|
19
|
-
set(content) {
|
|
20
|
-
this.content = content;
|
|
21
|
-
}
|
|
22
|
-
prependHead(fragment) {
|
|
23
|
-
const { head } = RegList.before;
|
|
24
|
-
return this.replace(head, `${head}${fragment}`);
|
|
25
|
-
}
|
|
26
|
-
appendHead(fragment) {
|
|
27
|
-
const { head } = RegList.after;
|
|
28
|
-
return this.replace(head, `${fragment}${head}`);
|
|
29
|
-
}
|
|
30
|
-
prependBody(fragment) {
|
|
31
|
-
const { body } = RegList.before;
|
|
32
|
-
return this.replace(body, `${body}${fragment}`);
|
|
33
|
-
}
|
|
34
|
-
appendBody(fragment) {
|
|
35
|
-
const { body } = RegList.after;
|
|
36
|
-
return this.replace(body, `${fragment}${body}`);
|
|
37
|
-
}
|
|
38
|
-
replace(reg, text) {
|
|
39
|
-
this.content = this.content.replace(reg, text);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
const templateInjectableStream = ({
|
|
43
|
-
prependHead,
|
|
44
|
-
appendHead,
|
|
45
|
-
prependBody,
|
|
46
|
-
appendBody
|
|
47
|
-
}) => new Transform({
|
|
48
|
-
write(chunk, _, callback) {
|
|
49
|
-
let chunk_str = chunk.toString();
|
|
50
|
-
if (prependHead) {
|
|
51
|
-
const { head } = RegList.before;
|
|
52
|
-
chunk_str = chunk_str.replace(head, `${head}${prependHead}`);
|
|
53
|
-
}
|
|
54
|
-
if (appendHead) {
|
|
55
|
-
const { head } = RegList.after;
|
|
56
|
-
chunk_str = chunk_str.replace(head, `${appendHead}${head}`);
|
|
57
|
-
}
|
|
58
|
-
if (prependBody) {
|
|
59
|
-
const { body } = RegList.before;
|
|
60
|
-
chunk_str = chunk_str.replace(body, `${body}${prependBody}`);
|
|
61
|
-
}
|
|
62
|
-
if (appendBody) {
|
|
63
|
-
const { body } = RegList.after;
|
|
64
|
-
chunk_str = chunk_str.replace(body, `${appendBody}${body}`);
|
|
65
|
-
}
|
|
66
|
-
this.push(chunk_str);
|
|
67
|
-
callback();
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
export {
|
|
71
|
-
TemplateAPI,
|
|
72
|
-
templateInjectableStream
|
|
73
|
-
};
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defProps = Object.defineProperties;
|
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
12
|
-
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
17
|
-
return a;
|
|
18
|
-
};
|
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
import * as path from "path";
|
|
21
|
-
import { compatRequire, fs, DEFAULT_SERVER_CONFIG } from "@modern-js/utils";
|
|
22
|
-
import mergeDeep from "merge-deep";
|
|
23
|
-
const getServerConfigPath = (distDirectory, serverConfigFile = DEFAULT_SERVER_CONFIG) => {
|
|
24
|
-
const serverConfigPath = path.join(distDirectory, serverConfigFile);
|
|
25
|
-
return `${serverConfigPath}.js`;
|
|
26
|
-
};
|
|
27
|
-
const requireConfig = (serverConfigPath) => {
|
|
28
|
-
if (fs.pathExistsSync(serverConfigPath)) {
|
|
29
|
-
return compatRequire(serverConfigPath);
|
|
30
|
-
}
|
|
31
|
-
return {};
|
|
32
|
-
};
|
|
33
|
-
const loadConfig = ({
|
|
34
|
-
cliConfig,
|
|
35
|
-
serverConfig,
|
|
36
|
-
resolvedConfigPath
|
|
37
|
-
}) => {
|
|
38
|
-
let config = null;
|
|
39
|
-
if (process.env.NODE_ENV === "production") {
|
|
40
|
-
const resolvedConfig = requireConfig(resolvedConfigPath);
|
|
41
|
-
config = mergeDeep(
|
|
42
|
-
__spreadProps(__spreadValues({}, resolvedConfig), {
|
|
43
|
-
plugins: []
|
|
44
|
-
}),
|
|
45
|
-
serverConfig,
|
|
46
|
-
cliConfig
|
|
47
|
-
);
|
|
48
|
-
} else {
|
|
49
|
-
config = mergeDeep(
|
|
50
|
-
__spreadProps(__spreadValues({}, cliConfig), {
|
|
51
|
-
plugins: []
|
|
52
|
-
}),
|
|
53
|
-
serverConfig
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
return config;
|
|
57
|
-
};
|
|
58
|
-
export {
|
|
59
|
-
getServerConfigPath,
|
|
60
|
-
loadConfig,
|
|
61
|
-
requireConfig
|
|
62
|
-
};
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
-
var __spreadValues = (a, b) => {
|
|
7
|
-
for (var prop in b || (b = {}))
|
|
8
|
-
if (__hasOwnProp.call(b, prop))
|
|
9
|
-
__defNormalProp(a, prop, b[prop]);
|
|
10
|
-
if (__getOwnPropSymbols)
|
|
11
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
-
if (__propIsEnum.call(b, prop))
|
|
13
|
-
__defNormalProp(a, prop, b[prop]);
|
|
14
|
-
}
|
|
15
|
-
return a;
|
|
16
|
-
};
|
|
17
|
-
const LOG_LEVEL = {
|
|
18
|
-
error: 0,
|
|
19
|
-
warn: 1,
|
|
20
|
-
info: 2,
|
|
21
|
-
debug: 3,
|
|
22
|
-
log: 4
|
|
23
|
-
};
|
|
24
|
-
const LOG_TYPES = {
|
|
25
|
-
error: {
|
|
26
|
-
color: "red",
|
|
27
|
-
label: "error",
|
|
28
|
-
level: "error"
|
|
29
|
-
},
|
|
30
|
-
info: {
|
|
31
|
-
color: "cyan",
|
|
32
|
-
label: "info",
|
|
33
|
-
level: "info"
|
|
34
|
-
},
|
|
35
|
-
success: {
|
|
36
|
-
color: "green",
|
|
37
|
-
label: "Success",
|
|
38
|
-
level: "info"
|
|
39
|
-
},
|
|
40
|
-
warn: {
|
|
41
|
-
color: "yellow",
|
|
42
|
-
label: "warn",
|
|
43
|
-
level: "warn"
|
|
44
|
-
},
|
|
45
|
-
debug: {
|
|
46
|
-
color: "red",
|
|
47
|
-
label: "debug",
|
|
48
|
-
level: "debug"
|
|
49
|
-
},
|
|
50
|
-
log: { level: "log" }
|
|
51
|
-
};
|
|
52
|
-
const DEFAULT_CONFIG = {
|
|
53
|
-
displayLabel: true,
|
|
54
|
-
uppercaseLabel: false
|
|
55
|
-
};
|
|
56
|
-
class Logger {
|
|
57
|
-
constructor(options = {}) {
|
|
58
|
-
this.level = options.level || LOG_TYPES.log.level;
|
|
59
|
-
this.config = __spreadValues(__spreadValues({}, DEFAULT_CONFIG), options.config || {});
|
|
60
|
-
this.types = __spreadValues(__spreadValues({}, LOG_TYPES), options.types || {});
|
|
61
|
-
this.longestLabel = this.getLongestLabel();
|
|
62
|
-
Object.keys(this.types).forEach((type) => {
|
|
63
|
-
this[type] = this._log.bind(this, type);
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
_log(type, message, ...args) {
|
|
67
|
-
if (message === void 0 || message === null) {
|
|
68
|
-
console.log();
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
if (LOG_LEVEL[type] > LOG_LEVEL[this.level]) {
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
let label = "";
|
|
75
|
-
let text = "";
|
|
76
|
-
const logType = this.types[type];
|
|
77
|
-
if (this.config.displayLabel && logType.label) {
|
|
78
|
-
label = this.config.uppercaseLabel ? logType.label.toUpperCase() : logType.label;
|
|
79
|
-
label = label.padEnd(this.longestLabel.length);
|
|
80
|
-
}
|
|
81
|
-
if (message instanceof Error) {
|
|
82
|
-
if (message.stack) {
|
|
83
|
-
const [name, ...rest] = message.stack.split("\n");
|
|
84
|
-
text = `${name}
|
|
85
|
-
${rest.join("\n")}`;
|
|
86
|
-
} else {
|
|
87
|
-
text = message.message;
|
|
88
|
-
}
|
|
89
|
-
} else {
|
|
90
|
-
text = `${message}`;
|
|
91
|
-
}
|
|
92
|
-
const log = label.length > 0 ? `${label} ${text}` : text;
|
|
93
|
-
console.log(log, ...args);
|
|
94
|
-
}
|
|
95
|
-
getLongestLabel() {
|
|
96
|
-
let longestLabel = "";
|
|
97
|
-
Object.keys(this.types).forEach((type) => {
|
|
98
|
-
const { label = "" } = this.types[type];
|
|
99
|
-
if (label.length > longestLabel.length) {
|
|
100
|
-
longestLabel = label;
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
return longestLabel;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
const logger = new Logger();
|
|
107
|
-
logger.Logger = Logger;
|
|
108
|
-
export {
|
|
109
|
-
Logger,
|
|
110
|
-
logger
|
|
111
|
-
};
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
-
var __spreadValues = (a, b) => {
|
|
7
|
-
for (var prop in b || (b = {}))
|
|
8
|
-
if (__hasOwnProp.call(b, prop))
|
|
9
|
-
__defNormalProp(a, prop, b[prop]);
|
|
10
|
-
if (__getOwnPropSymbols)
|
|
11
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
-
if (__propIsEnum.call(b, prop))
|
|
13
|
-
__defNormalProp(a, prop, b[prop]);
|
|
14
|
-
}
|
|
15
|
-
return a;
|
|
16
|
-
};
|
|
17
|
-
var __async = (__this, __arguments, generator) => {
|
|
18
|
-
return new Promise((resolve, reject) => {
|
|
19
|
-
var fulfilled = (value) => {
|
|
20
|
-
try {
|
|
21
|
-
step(generator.next(value));
|
|
22
|
-
} catch (e) {
|
|
23
|
-
reject(e);
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
var rejected = (value) => {
|
|
27
|
-
try {
|
|
28
|
-
step(generator.throw(value));
|
|
29
|
-
} catch (e) {
|
|
30
|
-
reject(e);
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
34
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
35
|
-
});
|
|
36
|
-
};
|
|
37
|
-
import { createProxyMiddleware } from "http-proxy-middleware";
|
|
38
|
-
import { debug } from "../utils";
|
|
39
|
-
function formatProxyOptions(proxyOptions) {
|
|
40
|
-
const formattedProxy = [];
|
|
41
|
-
if (!Array.isArray(proxyOptions)) {
|
|
42
|
-
if ("target" in proxyOptions) {
|
|
43
|
-
formattedProxy.push(proxyOptions);
|
|
44
|
-
} else {
|
|
45
|
-
Array.prototype.push.apply(
|
|
46
|
-
formattedProxy,
|
|
47
|
-
Object.keys(proxyOptions).reduce(
|
|
48
|
-
(total, source) => {
|
|
49
|
-
const option = proxyOptions[source];
|
|
50
|
-
total.push(__spreadValues({
|
|
51
|
-
context: source,
|
|
52
|
-
changeOrigin: true,
|
|
53
|
-
logLevel: "warn"
|
|
54
|
-
}, typeof option === "string" ? { target: option } : option));
|
|
55
|
-
return total;
|
|
56
|
-
},
|
|
57
|
-
[]
|
|
58
|
-
)
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
} else {
|
|
62
|
-
formattedProxy.push(...proxyOptions);
|
|
63
|
-
}
|
|
64
|
-
return formattedProxy;
|
|
65
|
-
}
|
|
66
|
-
const createProxyHandler = (proxyOptions) => {
|
|
67
|
-
debug("createProxyHandler", proxyOptions);
|
|
68
|
-
if (!proxyOptions) {
|
|
69
|
-
return null;
|
|
70
|
-
}
|
|
71
|
-
const formattedProxy = formatProxyOptions(proxyOptions);
|
|
72
|
-
const middlewares = formattedProxy.map((option) => {
|
|
73
|
-
const middleware = createProxyMiddleware(option.context, option);
|
|
74
|
-
return (ctx, next) => __async(void 0, null, function* () {
|
|
75
|
-
const { req, res } = ctx;
|
|
76
|
-
const bypassUrl = typeof option.bypass === "function" ? option.bypass(req, res, option) : null;
|
|
77
|
-
if (typeof bypassUrl === "boolean") {
|
|
78
|
-
ctx.status = 404;
|
|
79
|
-
return next();
|
|
80
|
-
} else if (typeof bypassUrl === "string") {
|
|
81
|
-
ctx.url = bypassUrl;
|
|
82
|
-
return next();
|
|
83
|
-
}
|
|
84
|
-
middleware(req, res, next);
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
return middlewares;
|
|
88
|
-
};
|
|
89
|
-
export {
|
|
90
|
-
createProxyHandler,
|
|
91
|
-
formatProxyOptions
|
|
92
|
-
};
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
2
|
-
var __commonJS = (cb, mod) => function __require() {
|
|
3
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
4
|
-
};
|
|
5
|
-
var __async = (__this, __arguments, generator) => {
|
|
6
|
-
return new Promise((resolve, reject) => {
|
|
7
|
-
var fulfilled = (value) => {
|
|
8
|
-
try {
|
|
9
|
-
step(generator.next(value));
|
|
10
|
-
} catch (e) {
|
|
11
|
-
reject(e);
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
var rejected = (value) => {
|
|
15
|
-
try {
|
|
16
|
-
step(generator.throw(value));
|
|
17
|
-
} catch (e) {
|
|
18
|
-
reject(e);
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
22
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
23
|
-
});
|
|
24
|
-
};
|
|
25
|
-
import url from "url";
|
|
26
|
-
import { createCache, destroyCache } from "../spr";
|
|
27
|
-
import {
|
|
28
|
-
cacheAddition,
|
|
29
|
-
connectFactor,
|
|
30
|
-
fname,
|
|
31
|
-
maybeSync,
|
|
32
|
-
namespaceHash,
|
|
33
|
-
valueFactory,
|
|
34
|
-
withCoalescedInvoke
|
|
35
|
-
} from "../util";
|
|
36
|
-
var require_cache_fun_test = __commonJS({
|
|
37
|
-
"src/libs/render/cache/__tests__/cache.fun.test.ts"(exports) {
|
|
38
|
-
describe("test spr util functions", () => {
|
|
39
|
-
it("should return value correctly", () => {
|
|
40
|
-
expect(connectFactor("bar", "foo")).toBe("bar-foo");
|
|
41
|
-
expect(fname(1)).toBe("f1");
|
|
42
|
-
expect(namespaceHash("modern", "!@#$%^&")).toBe("modern/!@#$%^&");
|
|
43
|
-
});
|
|
44
|
-
it("should create or destroy instance correctly", () => {
|
|
45
|
-
const ins1 = createCache();
|
|
46
|
-
const ins2 = createCache();
|
|
47
|
-
expect(ins1 === ins2).toBe(true);
|
|
48
|
-
destroyCache();
|
|
49
|
-
const ins3 = createCache();
|
|
50
|
-
expect(ins1 === ins3).toBe(false);
|
|
51
|
-
expect(ins2 === ins3).toBe(false);
|
|
52
|
-
});
|
|
53
|
-
it("should return function correctly", () => {
|
|
54
|
-
const urlParams = (() => new url.URLSearchParams())();
|
|
55
|
-
urlParams.set("name", "modern");
|
|
56
|
-
const getParam = valueFactory(urlParams);
|
|
57
|
-
expect(getParam("name")).toBe("modern");
|
|
58
|
-
const headers = { age: "12345" };
|
|
59
|
-
const getHeader = valueFactory(headers);
|
|
60
|
-
expect(getHeader("age")).toBe("12345");
|
|
61
|
-
});
|
|
62
|
-
it("should add target html content", () => {
|
|
63
|
-
const contentNoHead = "<div>123</div>";
|
|
64
|
-
const html = cacheAddition(contentNoHead, Math.random().toString());
|
|
65
|
-
expect(html).toBe(contentNoHead);
|
|
66
|
-
const contentWithHead = "<head></head><div>123</div>";
|
|
67
|
-
const hash = Math.random().toString();
|
|
68
|
-
const htmlWithHead = cacheAddition(contentWithHead, hash);
|
|
69
|
-
expect(htmlWithHead).toBe(
|
|
70
|
-
`<head><meta name="x-moden-spr" content="${hash}"></head><div>123</div>`
|
|
71
|
-
);
|
|
72
|
-
});
|
|
73
|
-
it("should only invoke func one time", () => __async(exports, null, function* () {
|
|
74
|
-
let index = 0;
|
|
75
|
-
const fn = withCoalescedInvoke(
|
|
76
|
-
() => __async(exports, null, function* () {
|
|
77
|
-
return new Promise((resolve) => {
|
|
78
|
-
setTimeout(() => {
|
|
79
|
-
index += 1;
|
|
80
|
-
resolve(index);
|
|
81
|
-
}, 500);
|
|
82
|
-
});
|
|
83
|
-
})
|
|
84
|
-
);
|
|
85
|
-
const key = "test";
|
|
86
|
-
const [res1, res2] = yield Promise.all([fn(key, []), fn(key, [])]);
|
|
87
|
-
expect(res1.isOrigin && res2.isOrigin).toBe(false);
|
|
88
|
-
expect(res1.isOrigin || res2.isOrigin).toBe(true);
|
|
89
|
-
expect(res1.value).toBe(1);
|
|
90
|
-
expect(res2.value).toBe(1);
|
|
91
|
-
}));
|
|
92
|
-
it("should invoke sync or async", () => __async(exports, null, function* () {
|
|
93
|
-
const foo = "";
|
|
94
|
-
const async = yield maybeSync(
|
|
95
|
-
() => new Promise((resolve) => {
|
|
96
|
-
setTimeout(() => {
|
|
97
|
-
resolve(foo);
|
|
98
|
-
}, 100);
|
|
99
|
-
})
|
|
100
|
-
)(false);
|
|
101
|
-
expect(async).toBeUndefined();
|
|
102
|
-
const sync = yield maybeSync(
|
|
103
|
-
() => new Promise((resolve) => {
|
|
104
|
-
setTimeout(() => {
|
|
105
|
-
resolve(foo);
|
|
106
|
-
}, 100);
|
|
107
|
-
})
|
|
108
|
-
)(true);
|
|
109
|
-
expect(sync).toBe(foo);
|
|
110
|
-
}));
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
export default require_cache_fun_test();
|