@modern-js/prod-server 2.4.0 → 2.5.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 +27 -0
- package/dist/{js/node → cjs}/constants.js +0 -0
- package/dist/{js/node → cjs}/index.js +0 -0
- package/dist/{js/node → cjs}/libs/context/context.js +0 -0
- package/dist/{js/node → cjs}/libs/context/index.js +0 -0
- package/dist/{js/node → cjs}/libs/hook-api/index.js +12 -25
- package/dist/{js/node → cjs}/libs/hook-api/route.js +0 -0
- package/dist/{js/node → cjs}/libs/hook-api/template.js +0 -0
- package/dist/{js/node → cjs}/libs/loadConfig.js +6 -21
- package/dist/cjs/libs/logger.js +122 -0
- package/dist/{js/node → cjs}/libs/metrics.js +0 -0
- package/dist/{js/node → cjs}/libs/proxy.js +6 -39
- package/dist/{js/node → cjs}/libs/render/cache/__tests__/cache.fun.test.js +12 -34
- package/dist/{js/node → cjs}/libs/render/cache/__tests__/cache.test.js +43 -78
- package/dist/{js/node → cjs}/libs/render/cache/__tests__/cacheable.js +0 -0
- package/dist/{js/node → cjs}/libs/render/cache/__tests__/error-configuration.js +0 -0
- package/dist/{js/node → cjs}/libs/render/cache/__tests__/matched-cache.js +0 -0
- package/dist/cjs/libs/render/cache/index.js +97 -0
- package/dist/cjs/libs/render/cache/page-caches/index.js +33 -0
- package/dist/{js/node → cjs}/libs/render/cache/page-caches/lru.js +0 -0
- package/dist/{js/node → cjs}/libs/render/cache/spr.js +69 -97
- package/dist/{js/node → cjs}/libs/render/cache/type.js +0 -0
- package/dist/{js/node → cjs}/libs/render/cache/util.js +19 -41
- package/dist/cjs/libs/render/index.js +93 -0
- package/dist/{js/node → cjs}/libs/render/measure.js +6 -21
- package/dist/{js/node → cjs}/libs/render/reader.js +24 -46
- package/dist/{js/node → cjs}/libs/render/ssr.js +3 -23
- package/dist/{js/node → cjs}/libs/render/static.js +22 -44
- package/dist/{js/node → cjs}/libs/render/type.js +0 -0
- package/dist/{js/node → cjs}/libs/route/index.js +0 -0
- package/dist/{js/node → cjs}/libs/route/matcher.js +0 -0
- package/dist/{js/node → cjs}/libs/route/route.js +0 -0
- package/dist/{js/node → cjs}/libs/serve-file.js +2 -22
- package/dist/{js/node → cjs}/server/index.js +56 -106
- package/dist/{js/node → cjs}/server/modern-server-split.js +9 -40
- package/dist/cjs/server/modern-server.js +490 -0
- package/dist/{js/node → cjs}/type.js +0 -0
- package/dist/{js/node → cjs}/utils.js +1 -15
- package/dist/{js/node → cjs}/worker-server.js +51 -35
- package/dist/{js/treeshaking → esm}/constants.js +0 -0
- package/dist/{js/treeshaking → esm}/index.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/context/context.js +2 -2
- package/dist/{js/treeshaking → esm}/libs/context/index.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/hook-api/index.js +1 -1
- package/dist/{js/treeshaking → esm}/libs/hook-api/route.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/hook-api/template.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/loadConfig.js +0 -0
- package/dist/esm/libs/logger.js +205 -0
- package/dist/{js/treeshaking → esm}/libs/metrics.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/proxy.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/render/cache/__tests__/cache.fun.test.js +3 -3
- package/dist/{js/treeshaking → esm}/libs/render/cache/__tests__/cache.test.js +2 -2
- package/dist/{js/treeshaking → esm}/libs/render/cache/__tests__/cacheable.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/render/cache/__tests__/error-configuration.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/render/cache/__tests__/matched-cache.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/render/cache/index.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/render/cache/page-caches/index.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/render/cache/page-caches/lru.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/render/cache/spr.js +8 -8
- package/dist/{js/treeshaking → esm}/libs/render/cache/type.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/render/cache/util.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/render/index.js +4 -3
- package/dist/{js/treeshaking → esm}/libs/render/measure.js +2 -2
- package/dist/{js/treeshaking → esm}/libs/render/reader.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/render/ssr.js +3 -3
- package/dist/{js/treeshaking → esm}/libs/render/static.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/render/type.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/route/index.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/route/matcher.js +2 -2
- package/dist/{js/treeshaking → esm}/libs/route/route.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/serve-file.js +2 -2
- package/dist/{js/treeshaking → esm}/server/index.js +3 -3
- package/dist/{js/treeshaking → esm}/server/modern-server-split.js +0 -0
- package/dist/{js/treeshaking → esm}/server/modern-server.js +21 -15
- package/dist/{js/treeshaking → esm}/type.js +0 -0
- package/dist/{js/treeshaking → esm}/utils.js +1 -1
- package/dist/{js/treeshaking → esm}/worker-server.js +64 -8
- package/dist/{js/modern → esm-node}/constants.js +0 -0
- package/dist/{js/modern → esm-node}/index.js +0 -0
- package/dist/{js/modern → esm-node}/libs/context/context.js +0 -0
- package/dist/{js/modern → esm-node}/libs/context/index.js +0 -0
- package/dist/{js/modern → esm-node}/libs/hook-api/index.js +12 -27
- package/dist/{js/modern → esm-node}/libs/hook-api/route.js +0 -0
- package/dist/{js/modern → esm-node}/libs/hook-api/template.js +0 -0
- package/dist/esm-node/libs/loadConfig.js +45 -0
- package/dist/esm-node/libs/logger.js +98 -0
- package/dist/{js/modern → esm-node}/libs/metrics.js +0 -0
- package/dist/{js/modern → esm-node}/libs/proxy.js +6 -41
- package/dist/esm-node/libs/render/cache/__tests__/cache.fun.test.js +83 -0
- package/dist/esm-node/libs/render/cache/__tests__/cache.test.js +210 -0
- package/dist/{js/modern → esm-node}/libs/render/cache/__tests__/cacheable.js +0 -0
- package/dist/{js/modern → esm-node}/libs/render/cache/__tests__/error-configuration.js +0 -0
- package/dist/{js/modern → esm-node}/libs/render/cache/__tests__/matched-cache.js +0 -0
- package/dist/esm-node/libs/render/cache/index.js +76 -0
- package/dist/esm-node/libs/render/cache/page-caches/index.js +10 -0
- package/dist/{js/modern → esm-node}/libs/render/cache/page-caches/lru.js +0 -0
- package/dist/{js/modern → esm-node}/libs/render/cache/spr.js +69 -97
- package/dist/{js/modern → esm-node}/libs/render/cache/type.js +0 -0
- package/dist/{js/modern → esm-node}/libs/render/cache/util.js +19 -41
- package/dist/esm-node/libs/render/index.js +64 -0
- package/dist/{js/modern → esm-node}/libs/render/measure.js +6 -23
- package/dist/esm-node/libs/render/reader.js +85 -0
- package/dist/{js/modern → esm-node}/libs/render/ssr.js +3 -23
- package/dist/esm-node/libs/render/static.js +38 -0
- package/dist/{js/modern → esm-node}/libs/render/type.js +0 -0
- package/dist/{js/modern → esm-node}/libs/route/index.js +0 -0
- package/dist/{js/modern → esm-node}/libs/route/matcher.js +0 -0
- package/dist/{js/modern → esm-node}/libs/route/route.js +0 -0
- package/dist/{js/modern → esm-node}/libs/serve-file.js +2 -22
- package/dist/esm-node/server/index.js +156 -0
- package/dist/esm-node/server/modern-server-split.js +43 -0
- package/dist/esm-node/server/modern-server.js +483 -0
- package/dist/{js/modern → esm-node}/type.js +0 -0
- package/dist/{js/modern → esm-node}/utils.js +1 -17
- package/dist/esm-node/worker-server.js +69 -0
- package/dist/types/libs/context/context.d.ts +1 -1
- package/dist/types/libs/logger.d.ts +63 -0
- package/dist/types/libs/render/index.d.ts +3 -1
- package/dist/types/utils.d.ts +1 -1
- package/dist/types/worker-server.d.ts +2 -1
- package/package.json +15 -16
- package/dist/js/modern/libs/loadConfig.js +0 -62
- 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/index.js +0 -115
- package/dist/js/modern/libs/render/cache/page-caches/index.js +0 -32
- package/dist/js/modern/libs/render/index.js +0 -84
- package/dist/js/modern/libs/render/reader.js +0 -107
- package/dist/js/modern/libs/render/static.js +0 -60
- 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 -548
- package/dist/js/modern/worker-server.js +0 -54
- 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/index.js +0 -113
- package/dist/js/node/server/modern-server.js +0 -553
|
@@ -15,37 +15,23 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
15
|
return to;
|
|
16
16
|
};
|
|
17
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var __async = (__this, __arguments, generator) => {
|
|
19
|
-
return new Promise((resolve, reject) => {
|
|
20
|
-
var fulfilled = (value) => {
|
|
21
|
-
try {
|
|
22
|
-
step(generator.next(value));
|
|
23
|
-
} catch (e) {
|
|
24
|
-
reject(e);
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
var rejected = (value) => {
|
|
28
|
-
try {
|
|
29
|
-
step(generator.throw(value));
|
|
30
|
-
} catch (e) {
|
|
31
|
-
reject(e);
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
35
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
36
|
-
});
|
|
37
|
-
};
|
|
38
18
|
var worker_server_exports = {};
|
|
39
19
|
__export(worker_server_exports, {
|
|
40
|
-
createHandler: () => createHandler
|
|
20
|
+
createHandler: () => createHandler,
|
|
21
|
+
handleUrl: () => handleUrl
|
|
41
22
|
});
|
|
42
23
|
module.exports = __toCommonJS(worker_server_exports);
|
|
24
|
+
var import_logger = require("./libs/logger");
|
|
43
25
|
var import_route = require("./libs/route");
|
|
26
|
+
var import_metrics = require("./libs/metrics");
|
|
27
|
+
const handleUrl = (url) => {
|
|
28
|
+
return url.replace(/^https?:\/\/.*?\//gi, "/");
|
|
29
|
+
};
|
|
44
30
|
const createHandler = (manifest) => {
|
|
45
31
|
const routeMgr = new import_route.RouteMatchManager();
|
|
46
32
|
const { pages, routes } = manifest;
|
|
47
33
|
routeMgr.reset(routes);
|
|
48
|
-
return (ctx) =>
|
|
34
|
+
return async (ctx) => {
|
|
49
35
|
var _a, _b, _c, _d, _e, _f;
|
|
50
36
|
const pageMatch = routeMgr.match(ctx.url);
|
|
51
37
|
if (!pageMatch) {
|
|
@@ -58,20 +44,50 @@ const createHandler = (manifest) => {
|
|
|
58
44
|
(_d = (_c = ctx.request).pathname) != null ? _d : _c.pathname = ctx.pathname;
|
|
59
45
|
(_f = (_e = ctx.request).params) != null ? _f : _e.params = ctx.params;
|
|
60
46
|
const params = pageMatch.parseURLParams(ctx.url);
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
47
|
+
if (page.serverRender) {
|
|
48
|
+
try {
|
|
49
|
+
ctx.body = await page.serverRender({
|
|
50
|
+
entryName: page.entryName,
|
|
51
|
+
template: page.template,
|
|
52
|
+
query: ctx.query,
|
|
53
|
+
request: ctx.request,
|
|
54
|
+
response: ctx.response,
|
|
55
|
+
pathname: ctx.pathname,
|
|
56
|
+
req: ctx.request,
|
|
57
|
+
res: ctx.response,
|
|
58
|
+
params: ctx.params || params || {},
|
|
59
|
+
logger: ctx.logger || new import_logger.Logger({
|
|
60
|
+
level: "warn"
|
|
61
|
+
}),
|
|
62
|
+
metrics: ctx.metrics || import_metrics.metrics,
|
|
63
|
+
loadableStats: ctx.loadableStats,
|
|
64
|
+
routeManifest: ctx.routeManifest
|
|
65
|
+
});
|
|
66
|
+
ctx.status = 200;
|
|
67
|
+
return;
|
|
68
|
+
} catch (e) {
|
|
69
|
+
if (page.template) {
|
|
70
|
+
ctx.body = page.template;
|
|
71
|
+
ctx.status = 200;
|
|
72
|
+
return;
|
|
73
|
+
} else {
|
|
74
|
+
ctx.body = "404: not found";
|
|
75
|
+
ctx.status = 404;
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (page.template) {
|
|
81
|
+
ctx.body = page.template;
|
|
82
|
+
ctx.status = 200;
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
ctx.body = "404: not found";
|
|
86
|
+
ctx.status = 404;
|
|
87
|
+
};
|
|
73
88
|
};
|
|
74
89
|
// Annotate the CommonJS export names for ESM import in node:
|
|
75
90
|
0 && (module.exports = {
|
|
76
|
-
createHandler
|
|
91
|
+
createHandler,
|
|
92
|
+
handleUrl
|
|
77
93
|
});
|
|
File without changes
|
|
File without changes
|
|
@@ -75,7 +75,7 @@ var ModernServerContext = /*#__PURE__*/ function() {
|
|
|
75
75
|
key: "bind",
|
|
76
76
|
value: function bind() {
|
|
77
77
|
var _this = this;
|
|
78
|
-
var
|
|
78
|
+
var _this1 = this, req = _this1.req, res = _this1.res;
|
|
79
79
|
req.get = function(key) {
|
|
80
80
|
return _this.getReqHeader(key);
|
|
81
81
|
};
|
|
@@ -140,7 +140,7 @@ var ModernServerContext = /*#__PURE__*/ function() {
|
|
|
140
140
|
{
|
|
141
141
|
key: "fresh",
|
|
142
142
|
get: function get() {
|
|
143
|
-
var
|
|
143
|
+
var _this = this, status = _this.status, res = _this.res, method = _this.method;
|
|
144
144
|
if ("GET" !== method && "HEAD" !== method) {
|
|
145
145
|
return false;
|
|
146
146
|
}
|
|
File without changes
|
|
@@ -198,7 +198,7 @@ var Response = /*#__PURE__*/ function() {
|
|
|
198
198
|
key: "raw",
|
|
199
199
|
value: function raw(body, options) {
|
|
200
200
|
var _this = this;
|
|
201
|
-
var
|
|
201
|
+
var _ref = options || {}, status = _ref.status, _ref_headers = _ref.headers, headers = _ref_headers === void 0 ? {} : _ref_headers;
|
|
202
202
|
Object.entries(headers).forEach(function(param) {
|
|
203
203
|
var _param = _slicedToArray(param, 2), key = _param[0], value = _param[1];
|
|
204
204
|
_this.res.setHeader(key, value);
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
function _arrayLikeToArray(arr, len) {
|
|
2
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
3
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
4
|
+
return arr2;
|
|
5
|
+
}
|
|
6
|
+
function _arrayWithHoles(arr) {
|
|
7
|
+
if (Array.isArray(arr)) return arr;
|
|
8
|
+
}
|
|
9
|
+
function _arrayWithoutHoles(arr) {
|
|
10
|
+
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
|
|
11
|
+
}
|
|
12
|
+
function _classCallCheck(instance, Constructor) {
|
|
13
|
+
if (!(instance instanceof Constructor)) {
|
|
14
|
+
throw new TypeError("Cannot call a class as a function");
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function _defineProperties(target, props) {
|
|
18
|
+
for(var i = 0; i < props.length; i++){
|
|
19
|
+
var descriptor = props[i];
|
|
20
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
21
|
+
descriptor.configurable = true;
|
|
22
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
23
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function _createClass(Constructor, protoProps, staticProps) {
|
|
27
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
28
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
29
|
+
return Constructor;
|
|
30
|
+
}
|
|
31
|
+
function _defineProperty(obj, key, value) {
|
|
32
|
+
if (key in obj) {
|
|
33
|
+
Object.defineProperty(obj, key, {
|
|
34
|
+
value: value,
|
|
35
|
+
enumerable: true,
|
|
36
|
+
configurable: true,
|
|
37
|
+
writable: true
|
|
38
|
+
});
|
|
39
|
+
} else {
|
|
40
|
+
obj[key] = value;
|
|
41
|
+
}
|
|
42
|
+
return obj;
|
|
43
|
+
}
|
|
44
|
+
function _instanceof(left, right) {
|
|
45
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
46
|
+
return !!right[Symbol.hasInstance](left);
|
|
47
|
+
} else {
|
|
48
|
+
return left instanceof right;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function _iterableToArray(iter) {
|
|
52
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
53
|
+
}
|
|
54
|
+
function _nonIterableRest() {
|
|
55
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
56
|
+
}
|
|
57
|
+
function _nonIterableSpread() {
|
|
58
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
59
|
+
}
|
|
60
|
+
function _objectSpread(target) {
|
|
61
|
+
for(var i = 1; i < arguments.length; i++){
|
|
62
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
63
|
+
var ownKeys = Object.keys(source);
|
|
64
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
65
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
66
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
67
|
+
}));
|
|
68
|
+
}
|
|
69
|
+
ownKeys.forEach(function(key) {
|
|
70
|
+
_defineProperty(target, key, source[key]);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
return target;
|
|
74
|
+
}
|
|
75
|
+
function _toArray(arr) {
|
|
76
|
+
return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableRest();
|
|
77
|
+
}
|
|
78
|
+
function _toConsumableArray(arr) {
|
|
79
|
+
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
|
|
80
|
+
}
|
|
81
|
+
function _unsupportedIterableToArray(o, minLen) {
|
|
82
|
+
if (!o) return;
|
|
83
|
+
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
84
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
85
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
86
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
87
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
88
|
+
}
|
|
89
|
+
var LOG_LEVEL = {
|
|
90
|
+
error: 0,
|
|
91
|
+
warn: 1,
|
|
92
|
+
info: 2,
|
|
93
|
+
debug: 3,
|
|
94
|
+
log: 4
|
|
95
|
+
};
|
|
96
|
+
var LOG_TYPES = {
|
|
97
|
+
error: {
|
|
98
|
+
color: "red",
|
|
99
|
+
label: "error",
|
|
100
|
+
level: "error"
|
|
101
|
+
},
|
|
102
|
+
info: {
|
|
103
|
+
color: "cyan",
|
|
104
|
+
label: "info",
|
|
105
|
+
level: "info"
|
|
106
|
+
},
|
|
107
|
+
success: {
|
|
108
|
+
color: "green",
|
|
109
|
+
label: "Success",
|
|
110
|
+
level: "info"
|
|
111
|
+
},
|
|
112
|
+
warn: {
|
|
113
|
+
color: "yellow",
|
|
114
|
+
label: "warn",
|
|
115
|
+
level: "warn"
|
|
116
|
+
},
|
|
117
|
+
debug: {
|
|
118
|
+
color: "red",
|
|
119
|
+
label: "debug",
|
|
120
|
+
level: "debug"
|
|
121
|
+
},
|
|
122
|
+
log: {
|
|
123
|
+
level: "log"
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
var DEFAULT_CONFIG = {
|
|
127
|
+
displayLabel: true,
|
|
128
|
+
uppercaseLabel: false
|
|
129
|
+
};
|
|
130
|
+
var Logger = /*#__PURE__*/ function() {
|
|
131
|
+
"use strict";
|
|
132
|
+
function Logger() {
|
|
133
|
+
var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
134
|
+
var _this = this;
|
|
135
|
+
_classCallCheck(this, Logger);
|
|
136
|
+
_defineProperty(this, "level", void 0);
|
|
137
|
+
_defineProperty(this, "config", void 0);
|
|
138
|
+
_defineProperty(this, "types", void 0);
|
|
139
|
+
_defineProperty(this, "longestLabel", void 0);
|
|
140
|
+
this.level = options.level || LOG_TYPES.log.level;
|
|
141
|
+
this.config = _objectSpread({}, DEFAULT_CONFIG, options.config || {});
|
|
142
|
+
this.types = _objectSpread({}, LOG_TYPES, options.types || {});
|
|
143
|
+
this.longestLabel = this.getLongestLabel();
|
|
144
|
+
Object.keys(this.types).forEach(function(type) {
|
|
145
|
+
_this[type] = _this._log.bind(_this, type);
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
_createClass(Logger, [
|
|
149
|
+
{
|
|
150
|
+
key: "_log",
|
|
151
|
+
value: function _log(type, message) {
|
|
152
|
+
for(var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++){
|
|
153
|
+
args[_key - 2] = arguments[_key];
|
|
154
|
+
}
|
|
155
|
+
var _console;
|
|
156
|
+
if (message === void 0 || message === null) {
|
|
157
|
+
console.log();
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
if (LOG_LEVEL[type] > LOG_LEVEL[this.level]) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
var label = "";
|
|
164
|
+
var text = "";
|
|
165
|
+
var logType = this.types[type];
|
|
166
|
+
if (this.config.displayLabel && logType.label) {
|
|
167
|
+
label = this.config.uppercaseLabel ? logType.label.toUpperCase() : logType.label;
|
|
168
|
+
label = label.padEnd(this.longestLabel.length);
|
|
169
|
+
}
|
|
170
|
+
if (_instanceof(message, Error)) {
|
|
171
|
+
if (message.stack) {
|
|
172
|
+
var _message_stack_split = _toArray(message.stack.split("\n")), name = _message_stack_split[0], rest = _message_stack_split.slice(1);
|
|
173
|
+
text = "".concat(name, "\n").concat(rest.join("\n"));
|
|
174
|
+
} else {
|
|
175
|
+
text = message.message;
|
|
176
|
+
}
|
|
177
|
+
} else {
|
|
178
|
+
text = "".concat(message);
|
|
179
|
+
}
|
|
180
|
+
var log = label.length > 0 ? "".concat(label, " ").concat(text) : text;
|
|
181
|
+
(_console = console).log.apply(_console, [
|
|
182
|
+
log
|
|
183
|
+
].concat(_toConsumableArray(args)));
|
|
184
|
+
}
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
key: "getLongestLabel",
|
|
188
|
+
value: function getLongestLabel() {
|
|
189
|
+
var _this = this;
|
|
190
|
+
var longestLabel = "";
|
|
191
|
+
Object.keys(this.types).forEach(function(type) {
|
|
192
|
+
var _this_types_type = _this.types[type], _this_types_type_label = _this_types_type.label, label = _this_types_type_label === void 0 ? "" : _this_types_type_label;
|
|
193
|
+
if (label.length > longestLabel.length) {
|
|
194
|
+
longestLabel = label;
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
return longestLabel;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
]);
|
|
201
|
+
return Logger;
|
|
202
|
+
}();
|
|
203
|
+
var logger = new Logger();
|
|
204
|
+
logger.Logger = Logger;
|
|
205
|
+
export { Logger, logger };
|
|
File without changes
|
|
File without changes
|
|
@@ -209,7 +209,7 @@ describe("test spr util functions", function() {
|
|
|
209
209
|
expect(htmlWithHead).toBe('<head><meta name="x-moden-spr" content="'.concat(hash, '"></head><div>123</div>'));
|
|
210
210
|
});
|
|
211
211
|
it("should only invoke func one time", /*#__PURE__*/ _asyncToGenerator(function() {
|
|
212
|
-
var index, fn, key,
|
|
212
|
+
var index, fn, key, _ref, res1, res2;
|
|
213
213
|
return __generator(this, function(_state) {
|
|
214
214
|
switch(_state.label){
|
|
215
215
|
case 0:
|
|
@@ -236,10 +236,10 @@ describe("test spr util functions", function() {
|
|
|
236
236
|
])
|
|
237
237
|
];
|
|
238
238
|
case 1:
|
|
239
|
-
|
|
239
|
+
_ref = _slicedToArray.apply(void 0, [
|
|
240
240
|
_state.sent(),
|
|
241
241
|
2
|
|
242
|
-
]), res1 =
|
|
242
|
+
]), res1 = _ref[0], res2 = _ref[1];
|
|
243
243
|
expect(res1.isOrigin && res2.isOrigin).toBe(false);
|
|
244
244
|
expect(res1.isOrigin || res2.isOrigin).toBe(true);
|
|
245
245
|
expect(res1.value).toBe(1);
|
|
@@ -517,7 +517,7 @@ describe("cache", function() {
|
|
|
517
517
|
});
|
|
518
518
|
}));
|
|
519
519
|
it("should match cache correctly", /*#__PURE__*/ _asyncToGenerator(function() {
|
|
520
|
-
var cache, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, cacheable, _cacheable, baseCacheable, matchOne, other,
|
|
520
|
+
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;
|
|
521
521
|
return __generator(this, function(_state) {
|
|
522
522
|
switch(_state.label){
|
|
523
523
|
case 0:
|
|
@@ -541,7 +541,7 @@ describe("cache", function() {
|
|
|
541
541
|
];
|
|
542
542
|
cacheable = _step.value;
|
|
543
543
|
_cacheable = _toArray(cacheable), baseCacheable = _cacheable[0], matchOne = _cacheable[1], other = _cacheable.slice(2);
|
|
544
|
-
|
|
544
|
+
_baseCacheable_requestOpt = baseCacheable.requestOpt, requestOpt = _baseCacheable_requestOpt === void 0 ? {} : _baseCacheable_requestOpt, cacheConfig = baseCacheable.cacheConfig, content = baseCacheable.content;
|
|
545
545
|
context = {
|
|
546
546
|
entry: "",
|
|
547
547
|
pathname: requestOpt.url,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -205,8 +205,8 @@ var CacheManager = /*#__PURE__*/ function() {
|
|
|
205
205
|
max: Math.min(MAX_SIZE_EACH_CLUSTER, 600) * 1024 * 1024,
|
|
206
206
|
length: function length(n) {
|
|
207
207
|
var len = n.caches.keys().reduce(function(total, cur) {
|
|
208
|
-
var
|
|
209
|
-
return total + (((
|
|
208
|
+
var _n_caches_peek;
|
|
209
|
+
return total + (((_n_caches_peek = n.caches.peek(cur)) === null || _n_caches_peek === void 0 ? void 0 : _n_caches_peek.size) || 0);
|
|
210
210
|
}, 1);
|
|
211
211
|
return len;
|
|
212
212
|
}
|
|
@@ -266,9 +266,9 @@ var CacheManager = /*#__PURE__*/ function() {
|
|
|
266
266
|
{
|
|
267
267
|
key: "queryFactor",
|
|
268
268
|
value: function queryFactor(context, data) {
|
|
269
|
-
var
|
|
270
|
-
var queryKeys = (
|
|
271
|
-
var queryMatches = (
|
|
269
|
+
var _data_includes, _data_matches;
|
|
270
|
+
var queryKeys = (_data_includes = data.includes) === null || _data_includes === void 0 ? void 0 : _data_includes.query;
|
|
271
|
+
var queryMatches = (_data_matches = data.matches) === null || _data_matches === void 0 ? void 0 : _data_matches.query;
|
|
272
272
|
if (!queryKeys || queryKeys.length === 0) {
|
|
273
273
|
return null;
|
|
274
274
|
}
|
|
@@ -280,9 +280,9 @@ var CacheManager = /*#__PURE__*/ function() {
|
|
|
280
280
|
{
|
|
281
281
|
key: "headerFactor",
|
|
282
282
|
value: function headerFactor(context, data) {
|
|
283
|
-
var
|
|
284
|
-
var headerKeys = (
|
|
285
|
-
var headerMatches = (
|
|
283
|
+
var _data_includes, _data_matches;
|
|
284
|
+
var headerKeys = (_data_includes = data.includes) === null || _data_includes === void 0 ? void 0 : _data_includes.header;
|
|
285
|
+
var headerMatches = (_data_matches = data.matches) === null || _data_matches === void 0 ? void 0 : _data_matches.header;
|
|
286
286
|
if (!headerKeys || headerKeys.length === 0) {
|
|
287
287
|
return null;
|
|
288
288
|
}
|
|
File without changes
|
|
File without changes
|
|
@@ -129,10 +129,10 @@ import { handleDirectory } from "./static";
|
|
|
129
129
|
import { readFile } from "./reader";
|
|
130
130
|
import * as ssr from "./ssr";
|
|
131
131
|
var createRenderHandler = function(param) {
|
|
132
|
-
var distDir = param.distDir, staticGenerate = param.staticGenerate;
|
|
132
|
+
var distDir = param.distDir, staticGenerate = param.staticGenerate, forceCSR = param.forceCSR;
|
|
133
133
|
return function() {
|
|
134
134
|
var _render = _asyncToGenerator(function(param) {
|
|
135
|
-
var ctx, route, runner, entryPath, urlPath, entry, result, templatePath, content, result1, err;
|
|
135
|
+
var ctx, route, runner, entryPath, urlPath, entry, result, templatePath, content, useCSR, result1, err;
|
|
136
136
|
return __generator(this, function(_state) {
|
|
137
137
|
switch(_state.label){
|
|
138
138
|
case 0:
|
|
@@ -176,7 +176,8 @@ var createRenderHandler = function(param) {
|
|
|
176
176
|
null
|
|
177
177
|
];
|
|
178
178
|
}
|
|
179
|
-
|
|
179
|
+
useCSR = forceCSR && ctx.query.csr;
|
|
180
|
+
if (!(route.isSSR && !useCSR)) return [
|
|
180
181
|
3,
|
|
181
182
|
7
|
|
182
183
|
];
|
|
@@ -85,7 +85,7 @@ function _unsupportedIterableToArray(o, minLen) {
|
|
|
85
85
|
import { headersWithoutCookie } from "../../utils";
|
|
86
86
|
var createMetrics = function(context, metrics) {
|
|
87
87
|
var entry = context.entryName, request = context.request;
|
|
88
|
-
var
|
|
88
|
+
var _ref = request || {}, _ref_pathname = _ref.pathname, pathname = _ref_pathname === void 0 ? "" : _ref_pathname;
|
|
89
89
|
var emitTimer = function(name, cost) {
|
|
90
90
|
var tags = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
91
91
|
metrics.emitTimer(name, cost, _objectSpreadProps(_objectSpread({}, tags), {
|
|
@@ -107,7 +107,7 @@ var createMetrics = function(context, metrics) {
|
|
|
107
107
|
};
|
|
108
108
|
var createLogger = function(serverContext, logger) {
|
|
109
109
|
var request = serverContext.request || {};
|
|
110
|
-
var
|
|
110
|
+
var _request_headers = request.headers, headers = _request_headers === void 0 ? {} : _request_headers, _request_pathname = request.pathname, pathname = _request_pathname === void 0 ? "" : _request_pathname;
|
|
111
111
|
var debug = function(message) {
|
|
112
112
|
for(var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){
|
|
113
113
|
args[_key - 1] = arguments[_key];
|
|
File without changes
|
|
@@ -129,7 +129,7 @@ import cache from "./cache";
|
|
|
129
129
|
import { createLogger, createMetrics } from "./measure";
|
|
130
130
|
var render = function() {
|
|
131
131
|
var _ref = _asyncToGenerator(function(ctx, renderOptions, runner) {
|
|
132
|
-
var
|
|
132
|
+
var _ctx_res, urlPath, bundle, distDir, template, entryName, staticGenerate, bundleJS, loadableUri, loadableStats, routesManifestUri, routeManifest, context, serverRender, content, _context_redirection, url, _context_redirection_status, status;
|
|
133
133
|
return __generator(this, function(_state) {
|
|
134
134
|
switch(_state.label){
|
|
135
135
|
case 0:
|
|
@@ -157,7 +157,7 @@ var render = function() {
|
|
|
157
157
|
status: function(code) {
|
|
158
158
|
ctx.res.statusCode = code;
|
|
159
159
|
},
|
|
160
|
-
locals: ((
|
|
160
|
+
locals: ((_ctx_res = ctx.res) === null || _ctx_res === void 0 ? void 0 : _ctx_res.locals) || {}
|
|
161
161
|
},
|
|
162
162
|
redirection: {},
|
|
163
163
|
template: template,
|
|
@@ -180,7 +180,7 @@ var render = function() {
|
|
|
180
180
|
];
|
|
181
181
|
case 1:
|
|
182
182
|
content = _state.sent();
|
|
183
|
-
|
|
183
|
+
_context_redirection = context.redirection, url = _context_redirection.url, _context_redirection_status = _context_redirection.status, status = _context_redirection_status === void 0 ? 302 : _context_redirection_status;
|
|
184
184
|
if (url) {
|
|
185
185
|
return [
|
|
186
186
|
2,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -89,9 +89,9 @@ var RouteMatcher = /*#__PURE__*/ function() {
|
|
|
89
89
|
if (!this.urlReg) {
|
|
90
90
|
return this.urlPath.length;
|
|
91
91
|
} else {
|
|
92
|
-
var
|
|
92
|
+
var _result_;
|
|
93
93
|
var result = this.urlReg.exec(pathname);
|
|
94
|
-
return (result === null || result === void 0 ? void 0 : (
|
|
94
|
+
return (result === null || result === void 0 ? void 0 : (_result_ = result[0]) === null || _result_ === void 0 ? void 0 : _result_.length) || null;
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
97
|
},
|
|
File without changes
|
|
@@ -147,10 +147,10 @@ var createStaticFileHandler = function(rules) {
|
|
|
147
147
|
var output = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
148
148
|
return function() {
|
|
149
149
|
var _ref = _asyncToGenerator(function(context, next) {
|
|
150
|
-
var requestUrl, req, res,
|
|
150
|
+
var requestUrl, req, res, _output_assetPrefix, assetPrefix, hitRule, resume;
|
|
151
151
|
return __generator(this, function(_state) {
|
|
152
152
|
requestUrl = context.url, req = context.req, res = context.res;
|
|
153
|
-
|
|
153
|
+
_output_assetPrefix = output.assetPrefix, assetPrefix = _output_assetPrefix === void 0 ? "/" : _output_assetPrefix;
|
|
154
154
|
hitRule = rules.find(function(item) {
|
|
155
155
|
if (isString(item.path) && requestUrl.startsWith(item.path)) {
|
|
156
156
|
return true;
|
|
@@ -417,13 +417,13 @@ var Server = /*#__PURE__*/ function() {
|
|
|
417
417
|
value: function createHookRunner() {
|
|
418
418
|
var _this = this;
|
|
419
419
|
return _asyncToGenerator(function() {
|
|
420
|
-
var options,
|
|
420
|
+
var options, _options_internalPlugins, internalPlugins, pwd, _options_plugins, plugins, serverPlugins, loadedPlugins, hooksRunner;
|
|
421
421
|
return __generator(this, function(_state) {
|
|
422
422
|
switch(_state.label){
|
|
423
423
|
case 0:
|
|
424
424
|
serverManager.clear();
|
|
425
425
|
options = _this.options;
|
|
426
|
-
|
|
426
|
+
_options_internalPlugins = options.internalPlugins, internalPlugins = _options_internalPlugins === void 0 ? INTERNAL_SERVER_PLUGINS : _options_internalPlugins, pwd = options.pwd, _options_plugins = options.plugins, plugins = _options_plugins === void 0 ? [] : _options_plugins;
|
|
427
427
|
serverPlugins = _this.serverConfig.plugins || [];
|
|
428
428
|
loadedPlugins = loadPlugins(pwd, _toConsumableArray(serverPlugins).concat(_toConsumableArray(plugins)), {
|
|
429
429
|
internalPlugins: internalPlugins
|
|
@@ -471,7 +471,7 @@ var Server = /*#__PURE__*/ function() {
|
|
|
471
471
|
key: "initAppContext",
|
|
472
472
|
value: function initAppContext() {
|
|
473
473
|
var options = this.options;
|
|
474
|
-
var appDirectory = options.pwd,
|
|
474
|
+
var appDirectory = options.pwd, _options_plugins = options.plugins, plugins = _options_plugins === void 0 ? [] : _options_plugins, config = options.config;
|
|
475
475
|
var serverPlugins = plugins.map(function(p) {
|
|
476
476
|
return {
|
|
477
477
|
server: p
|
|
File without changes
|