@modern-js/prod-server 2.48.0 → 2.48.1

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.
Files changed (47) hide show
  1. package/dist/cjs/libs/context/context.js +4 -8
  2. package/dist/cjs/libs/hook-api/base.js +0 -11
  3. package/dist/cjs/libs/hook-api/index.worker.js +0 -3
  4. package/dist/cjs/libs/hook-api/route.js +0 -4
  5. package/dist/cjs/libs/hook-api/template.js +0 -2
  6. package/dist/cjs/libs/render/ssrCache/cacheMod.js +0 -5
  7. package/dist/cjs/libs/render/ssrCache/manager.js +2 -3
  8. package/dist/cjs/libs/route/index.js +1 -3
  9. package/dist/cjs/libs/route/matcher.js +1 -5
  10. package/dist/cjs/libs/route/route.js +1 -10
  11. package/dist/cjs/libs/serverTiming.js +0 -3
  12. package/dist/cjs/renderHtml.js +0 -7
  13. package/dist/cjs/server/index.js +1 -7
  14. package/dist/cjs/server/modernServer.js +4 -20
  15. package/dist/cjs/workerServer.js +4 -8
  16. package/dist/esm/libs/context/context.js +66 -98
  17. package/dist/esm/libs/hook-api/base.js +36 -71
  18. package/dist/esm/libs/hook-api/index.worker.js +15 -29
  19. package/dist/esm/libs/hook-api/route.js +12 -27
  20. package/dist/esm/libs/hook-api/template.js +33 -61
  21. package/dist/esm/libs/render/ssrCache/cacheMod.js +10 -18
  22. package/dist/esm/libs/render/ssrCache/manager.js +145 -157
  23. package/dist/esm/libs/route/index.js +62 -96
  24. package/dist/esm/libs/route/matcher.js +58 -94
  25. package/dist/esm/libs/route/route.js +1 -10
  26. package/dist/esm/libs/serverTiming.js +8 -16
  27. package/dist/esm/renderHtml.js +22 -39
  28. package/dist/esm/server/index.js +307 -383
  29. package/dist/esm/server/modernServer.js +802 -942
  30. package/dist/esm/server/modernServerSplit.js +61 -86
  31. package/dist/esm/workerServer.js +87 -82
  32. package/dist/esm-node/libs/context/context.js +4 -8
  33. package/dist/esm-node/libs/hook-api/base.js +0 -11
  34. package/dist/esm-node/libs/hook-api/index.worker.js +0 -3
  35. package/dist/esm-node/libs/hook-api/route.js +0 -4
  36. package/dist/esm-node/libs/hook-api/template.js +0 -2
  37. package/dist/esm-node/libs/render/ssrCache/cacheMod.js +0 -5
  38. package/dist/esm-node/libs/render/ssrCache/manager.js +2 -3
  39. package/dist/esm-node/libs/route/index.js +1 -3
  40. package/dist/esm-node/libs/route/matcher.js +1 -5
  41. package/dist/esm-node/libs/route/route.js +1 -10
  42. package/dist/esm-node/libs/serverTiming.js +0 -3
  43. package/dist/esm-node/renderHtml.js +0 -7
  44. package/dist/esm-node/server/index.js +1 -7
  45. package/dist/esm-node/server/modernServer.js +4 -20
  46. package/dist/esm-node/workerServer.js +4 -8
  47. package/package.json +8 -8
@@ -1,86 +1,55 @@
1
1
  import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
2
- import { _ as _create_class } from "@swc/helpers/_/_create_class";
3
- import { _ as _define_property } from "@swc/helpers/_/_define_property";
4
2
  import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
5
3
  import cookie from "cookie";
6
4
  var BaseResponse = /* @__PURE__ */ function() {
7
5
  "use strict";
8
6
  function BaseResponse2(res) {
9
7
  _class_call_check(this, BaseResponse2);
10
- _define_property(this, "cookies", void 0);
11
- _define_property(this, "res", void 0);
12
8
  this.res = res;
13
9
  this.cookies = {
14
10
  set: this.setCookie.bind(this),
15
11
  clear: this.clearCookie.bind(this)
16
12
  };
17
13
  }
18
- _create_class(BaseResponse2, [
19
- {
20
- key: "get",
21
- value: function get(key) {
22
- return this.res.getHeader(key);
23
- }
24
- },
25
- {
26
- key: "set",
27
- value: function set(key, value) {
28
- return this.res.setHeader(key, value);
29
- }
30
- },
31
- {
32
- key: "status",
33
- value: function status(code) {
34
- this.res.statusCode = code;
35
- }
36
- },
37
- {
38
- key: "setCookie",
39
- value: function setCookie(key, value, options) {
40
- var cookieValue = this.res.getHeader("set-cookie") || "";
41
- var fmt = Array.isArray(cookieValue) ? cookieValue : [
42
- cookieValue
43
- ].filter(Boolean);
44
- fmt.push(cookie.serialize(key, value, options));
45
- this.res.setHeader("set-cookie", fmt.length === 1 ? fmt[0] : fmt);
46
- }
47
- },
48
- {
49
- key: "clearCookie",
50
- value: function clearCookie() {
51
- this.res.removeHeader("set-cookie");
52
- }
53
- },
54
- {
55
- key: "raw",
56
- value: function raw(body, options) {
57
- var _this = this;
58
- var _ref = options || {}, status = _ref.status, _ref_headers = _ref.headers, headers = _ref_headers === void 0 ? {} : _ref_headers;
59
- Object.entries(headers).forEach(function(param) {
60
- var _param = _sliced_to_array(param, 2), key = _param[0], value = _param[1];
61
- _this.res.setHeader(key, value);
62
- });
63
- if (status) {
64
- this.res.statusCode = status;
65
- }
66
- this.res.end(body);
67
- }
14
+ var _proto = BaseResponse2.prototype;
15
+ _proto.get = function get(key) {
16
+ return this.res.getHeader(key);
17
+ };
18
+ _proto.set = function set(key, value) {
19
+ return this.res.setHeader(key, value);
20
+ };
21
+ _proto.status = function status(code) {
22
+ this.res.statusCode = code;
23
+ };
24
+ _proto.setCookie = function setCookie(key, value, options) {
25
+ var cookieValue = this.res.getHeader("set-cookie") || "";
26
+ var fmt = Array.isArray(cookieValue) ? cookieValue : [
27
+ cookieValue
28
+ ].filter(Boolean);
29
+ fmt.push(cookie.serialize(key, value, options));
30
+ this.res.setHeader("set-cookie", fmt.length === 1 ? fmt[0] : fmt);
31
+ };
32
+ _proto.clearCookie = function clearCookie() {
33
+ this.res.removeHeader("set-cookie");
34
+ };
35
+ _proto.raw = function raw(body, options) {
36
+ var _this = this;
37
+ var _ref = options || {}, status = _ref.status, _ref_headers = _ref.headers, headers = _ref_headers === void 0 ? {} : _ref_headers;
38
+ Object.entries(headers).forEach(function(param) {
39
+ var _param = _sliced_to_array(param, 2), key = _param[0], value = _param[1];
40
+ _this.res.setHeader(key, value);
41
+ });
42
+ if (status) {
43
+ this.res.statusCode = status;
68
44
  }
69
- ]);
45
+ this.res.end(body);
46
+ };
70
47
  return BaseResponse2;
71
48
  }();
72
49
  var BaseRequest = /* @__PURE__ */ function() {
73
50
  "use strict";
74
51
  function BaseRequest2(request) {
75
52
  _class_call_check(this, BaseRequest2);
76
- _define_property(this, "url", void 0);
77
- _define_property(this, "host", void 0);
78
- _define_property(this, "pathname", void 0);
79
- _define_property(this, "query", void 0);
80
- _define_property(this, "headers", void 0);
81
- _define_property(this, "cookie", void 0);
82
- _define_property(this, "cookies", void 0);
83
- _define_property(this, "_cookie", void 0);
84
53
  this.url = request.url;
85
54
  this.host = request.host;
86
55
  this.pathname = request.path;
@@ -92,14 +61,10 @@ var BaseRequest = /* @__PURE__ */ function() {
92
61
  get: this.getCookie.bind(this)
93
62
  };
94
63
  }
95
- _create_class(BaseRequest2, [
96
- {
97
- key: "getCookie",
98
- value: function getCookie(key) {
99
- return this._cookie[key];
100
- }
101
- }
102
- ]);
64
+ var _proto = BaseRequest2.prototype;
65
+ _proto.getCookie = function getCookie(key) {
66
+ return this._cookie[key];
67
+ };
103
68
  return BaseRequest2;
104
69
  }();
105
70
  export {
@@ -1,6 +1,5 @@
1
1
  import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
2
2
  import { _ as _create_class } from "@swc/helpers/_/_create_class";
3
- import { _ as _define_property } from "@swc/helpers/_/_define_property";
4
3
  import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
5
4
  import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
6
5
  import { BaseRequest, BaseResponse } from "./base";
@@ -10,11 +9,24 @@ var ServerResponse = /* @__PURE__ */ function() {
10
9
  "use strict";
11
10
  function ServerResponse2(res) {
12
11
  _class_call_check(this, ServerResponse2);
13
- _define_property(this, "locals", void 0);
14
- _define_property(this, "res", void 0);
15
12
  this.res = res;
16
13
  this.locals = res.locals;
17
14
  }
15
+ var _proto = ServerResponse2.prototype;
16
+ _proto.getHeader = function getHeader(key) {
17
+ var _this_res_headers_get;
18
+ return (_this_res_headers_get = this.res.headers.get(key)) !== null && _this_res_headers_get !== void 0 ? _this_res_headers_get : void 0;
19
+ };
20
+ _proto.setHeader = function setHeader(key, value) {
21
+ this.res.headers.set(key, value);
22
+ };
23
+ _proto.removeHeader = function removeHeader(key) {
24
+ this.res.headers.delete(key);
25
+ };
26
+ _proto.end = function end(body) {
27
+ this.res.body = body;
28
+ this.res.isSent = true;
29
+ };
18
30
  _create_class(ServerResponse2, [
19
31
  {
20
32
  key: "statusCode",
@@ -24,32 +36,6 @@ var ServerResponse = /* @__PURE__ */ function() {
24
36
  set: function set(code) {
25
37
  this.res.status = code;
26
38
  }
27
- },
28
- {
29
- key: "getHeader",
30
- value: function getHeader(key) {
31
- var _this_res_headers_get;
32
- return (_this_res_headers_get = this.res.headers.get(key)) !== null && _this_res_headers_get !== void 0 ? _this_res_headers_get : void 0;
33
- }
34
- },
35
- {
36
- key: "setHeader",
37
- value: function setHeader(key, value) {
38
- this.res.headers.set(key, value);
39
- }
40
- },
41
- {
42
- key: "removeHeader",
43
- value: function removeHeader(key) {
44
- this.res.headers.delete(key);
45
- }
46
- },
47
- {
48
- key: "end",
49
- value: function end(body) {
50
- this.res.body = body;
51
- this.res.isSent = true;
52
- }
53
39
  }
54
40
  ]);
55
41
  return ServerResponse2;
@@ -1,39 +1,24 @@
1
1
  import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
2
- import { _ as _create_class } from "@swc/helpers/_/_create_class";
3
- import { _ as _define_property } from "@swc/helpers/_/_define_property";
4
2
  var RouteAPI = /* @__PURE__ */ function() {
5
3
  "use strict";
6
4
  function RouteAPI2(entryName) {
7
5
  _class_call_check(this, RouteAPI2);
8
- _define_property(this, "current", void 0);
9
- _define_property(this, "status", void 0);
10
- _define_property(this, "url", void 0);
11
6
  this.current = entryName;
12
7
  this.status = 200;
13
8
  this.url = "";
14
9
  }
15
- _create_class(RouteAPI2, [
16
- {
17
- key: "redirect",
18
- value: function redirect(url) {
19
- var status = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 302;
20
- this.url = url;
21
- this.status = status;
22
- }
23
- },
24
- {
25
- key: "rewrite",
26
- value: function rewrite(entryName) {
27
- this.current = entryName;
28
- }
29
- },
30
- {
31
- key: "use",
32
- value: function use(entryName) {
33
- this.rewrite(entryName);
34
- }
35
- }
36
- ]);
10
+ var _proto = RouteAPI2.prototype;
11
+ _proto.redirect = function redirect(url) {
12
+ var status = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 302;
13
+ this.url = url;
14
+ this.status = status;
15
+ };
16
+ _proto.rewrite = function rewrite(entryName) {
17
+ this.current = entryName;
18
+ };
19
+ _proto.use = function use(entryName) {
20
+ this.rewrite(entryName);
21
+ };
37
22
  return RouteAPI2;
38
23
  }();
39
24
  export {
@@ -1,6 +1,4 @@
1
1
  import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
2
- import { _ as _create_class } from "@swc/helpers/_/_create_class";
3
- import { _ as _define_property } from "@swc/helpers/_/_define_property";
4
2
  var RegList = {
5
3
  before: {
6
4
  head: "<head[^>]*>",
@@ -15,67 +13,41 @@ var TemplateAPI = /* @__PURE__ */ function() {
15
13
  "use strict";
16
14
  function TemplateAPI2(content) {
17
15
  _class_call_check(this, TemplateAPI2);
18
- _define_property(this, "content", void 0);
19
16
  this.content = content;
20
17
  }
21
- _create_class(TemplateAPI2, [
22
- {
23
- key: "get",
24
- value: function get() {
25
- return this.content;
26
- }
27
- },
28
- {
29
- key: "set",
30
- value: function set(content) {
31
- this.content = content;
32
- }
33
- },
34
- {
35
- key: "prependHead",
36
- value: function prependHead(fragment) {
37
- var head = RegList.before.head;
38
- return this.replaceByFunction(new RegExp(head), function(beforeHead) {
39
- return "".concat(beforeHead).concat(fragment);
40
- });
41
- }
42
- },
43
- {
44
- key: "appendHead",
45
- value: function appendHead(fragment) {
46
- var head = RegList.after.head;
47
- return this.replace(head, "".concat(fragment).concat(head));
48
- }
49
- },
50
- {
51
- key: "prependBody",
52
- value: function prependBody(fragment) {
53
- var body = RegList.before.body;
54
- return this.replaceByFunction(new RegExp(body), function(beforeBody) {
55
- return "".concat(beforeBody).concat(fragment);
56
- });
57
- }
58
- },
59
- {
60
- key: "appendBody",
61
- value: function appendBody(fragment) {
62
- var body = RegList.after.body;
63
- return this.replace(body, "".concat(fragment).concat(body));
64
- }
65
- },
66
- {
67
- key: "replaceByFunction",
68
- value: function replaceByFunction(reg, replacer) {
69
- this.content = this.content.replace(reg, replacer);
70
- }
71
- },
72
- {
73
- key: "replace",
74
- value: function replace(reg, text) {
75
- this.content = this.content.replace(reg, text);
76
- }
77
- }
78
- ]);
18
+ var _proto = TemplateAPI2.prototype;
19
+ _proto.get = function get() {
20
+ return this.content;
21
+ };
22
+ _proto.set = function set(content) {
23
+ this.content = content;
24
+ };
25
+ _proto.prependHead = function prependHead(fragment) {
26
+ var head = RegList.before.head;
27
+ return this.replaceByFunction(new RegExp(head), function(beforeHead) {
28
+ return "".concat(beforeHead).concat(fragment);
29
+ });
30
+ };
31
+ _proto.appendHead = function appendHead(fragment) {
32
+ var head = RegList.after.head;
33
+ return this.replace(head, "".concat(fragment).concat(head));
34
+ };
35
+ _proto.prependBody = function prependBody(fragment) {
36
+ var body = RegList.before.body;
37
+ return this.replaceByFunction(new RegExp(body), function(beforeBody) {
38
+ return "".concat(beforeBody).concat(fragment);
39
+ });
40
+ };
41
+ _proto.appendBody = function appendBody(fragment) {
42
+ var body = RegList.after.body;
43
+ return this.replace(body, "".concat(fragment).concat(body));
44
+ };
45
+ _proto.replaceByFunction = function replaceByFunction(reg, replacer) {
46
+ this.content = this.content.replace(reg, replacer);
47
+ };
48
+ _proto.replace = function replace(reg, text) {
49
+ this.content = this.content.replace(reg, text);
50
+ };
79
51
  return TemplateAPI2;
80
52
  }();
81
53
  export {
@@ -1,6 +1,4 @@
1
1
  import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
2
- import { _ as _create_class } from "@swc/helpers/_/_create_class";
3
- import { _ as _define_property } from "@swc/helpers/_/_define_property";
4
2
  import path from "path";
5
3
  import { SERVER_DIR, requireExistModule } from "@modern-js/utils";
6
4
  var CACHE_FILENAME = "cache";
@@ -8,23 +6,17 @@ var ServerCacheMod = /* @__PURE__ */ function() {
8
6
  "use strict";
9
7
  function ServerCacheMod2() {
10
8
  _class_call_check(this, ServerCacheMod2);
11
- _define_property(this, "customContainer", void 0);
12
- _define_property(this, "cacheOption", void 0);
13
9
  }
14
- _create_class(ServerCacheMod2, [
15
- {
16
- key: "loadServerCacheMod",
17
- value: function loadServerCacheMod() {
18
- var pwd = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : process.cwd();
19
- var serverCacheFilepath = path.resolve(pwd, SERVER_DIR, CACHE_FILENAME);
20
- var mod = requireExistModule(serverCacheFilepath, {
21
- interop: false
22
- });
23
- this.customContainer = mod === null || mod === void 0 ? void 0 : mod.customContainer;
24
- this.cacheOption = mod === null || mod === void 0 ? void 0 : mod.cacheOption;
25
- }
26
- }
27
- ]);
10
+ var _proto = ServerCacheMod2.prototype;
11
+ _proto.loadServerCacheMod = function loadServerCacheMod() {
12
+ var pwd = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : process.cwd();
13
+ var serverCacheFilepath = path.resolve(pwd, SERVER_DIR, CACHE_FILENAME);
14
+ var mod = requireExistModule(serverCacheFilepath, {
15
+ interop: false
16
+ });
17
+ this.customContainer = mod === null || mod === void 0 ? void 0 : mod.customContainer;
18
+ this.cacheOption = mod === null || mod === void 0 ? void 0 : mod.cacheOption;
19
+ };
28
20
  return ServerCacheMod2;
29
21
  }();
30
22
  var cacheMod = new ServerCacheMod();