@modern-js/prod-server 2.0.0-beta.3 → 2.0.0-beta.6

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 (130) hide show
  1. package/CHANGELOG.md +139 -0
  2. package/dist/js/modern/constants.js +32 -25
  3. package/dist/js/modern/index.js +11 -6
  4. package/dist/js/modern/libs/context/context.js +52 -84
  5. package/dist/js/modern/libs/context/index.js +5 -2
  6. package/dist/js/modern/libs/hook-api/index.js +44 -35
  7. package/dist/js/modern/libs/hook-api/route.js +6 -7
  8. package/dist/js/modern/libs/hook-api/template.js +20 -34
  9. package/dist/js/modern/libs/loadConfig.js +45 -24
  10. package/dist/js/modern/libs/metrics.js +3 -4
  11. package/dist/js/modern/libs/proxy.js +68 -37
  12. package/dist/js/modern/libs/render/cache/__tests__/cache.fun.test.js +112 -67
  13. package/dist/js/modern/libs/render/cache/__tests__/cache.test.js +246 -216
  14. package/dist/js/modern/libs/render/cache/__tests__/cacheable.js +43 -49
  15. package/dist/js/modern/libs/render/cache/__tests__/error-configuration.js +36 -34
  16. package/dist/js/modern/libs/render/cache/__tests__/matched-cache.js +83 -113
  17. package/dist/js/modern/libs/render/cache/index.js +88 -54
  18. package/dist/js/modern/libs/render/cache/page-caches/index.js +31 -8
  19. package/dist/js/modern/libs/render/cache/page-caches/lru.js +6 -6
  20. package/dist/js/modern/libs/render/cache/spr.js +133 -117
  21. package/dist/js/modern/libs/render/cache/type.js +0 -1
  22. package/dist/js/modern/libs/render/cache/util.js +71 -39
  23. package/dist/js/modern/libs/render/index.js +76 -56
  24. package/dist/js/modern/libs/render/measure.js +38 -27
  25. package/dist/js/modern/libs/render/reader.js +65 -62
  26. package/dist/js/modern/libs/render/ssr.js +50 -32
  27. package/dist/js/modern/libs/render/static.js +50 -33
  28. package/dist/js/modern/libs/render/type.js +9 -6
  29. package/dist/js/modern/libs/route/index.js +8 -15
  30. package/dist/js/modern/libs/route/matcher.js +20 -34
  31. package/dist/js/modern/libs/route/route.js +9 -18
  32. package/dist/js/modern/libs/serve-file.js +33 -20
  33. package/dist/js/modern/server/index.js +150 -145
  34. package/dist/js/modern/server/modern-server-split.js +46 -12
  35. package/dist/js/modern/server/modern-server.js +384 -422
  36. package/dist/js/modern/type.js +0 -1
  37. package/dist/js/modern/utils.js +62 -43
  38. package/dist/js/modern/worker-server.js +34 -14
  39. package/dist/js/node/constants.js +53 -30
  40. package/dist/js/node/index.js +37 -57
  41. package/dist/js/node/libs/context/context.js +83 -94
  42. package/dist/js/node/libs/context/index.js +28 -13
  43. package/dist/js/node/libs/hook-api/index.js +76 -48
  44. package/dist/js/node/libs/hook-api/route.js +26 -11
  45. package/dist/js/node/libs/hook-api/template.js +41 -39
  46. package/dist/js/node/libs/loadConfig.js +73 -35
  47. package/dist/js/node/libs/metrics.js +25 -9
  48. package/dist/js/node/libs/proxy.js +89 -44
  49. package/dist/js/node/libs/render/cache/__tests__/cache.fun.test.js +99 -56
  50. package/dist/js/node/libs/render/cache/__tests__/cache.test.js +147 -128
  51. package/dist/js/node/libs/render/cache/__tests__/cacheable.js +65 -55
  52. package/dist/js/node/libs/render/cache/__tests__/error-configuration.js +58 -40
  53. package/dist/js/node/libs/render/cache/__tests__/matched-cache.js +105 -119
  54. package/dist/js/node/libs/render/cache/index.js +110 -64
  55. package/dist/js/node/libs/render/cache/page-caches/index.js +54 -14
  56. package/dist/js/node/libs/render/cache/page-caches/lru.js +33 -12
  57. package/dist/js/node/libs/render/cache/spr.js +161 -129
  58. package/dist/js/node/libs/render/cache/type.js +15 -5
  59. package/dist/js/node/libs/render/cache/util.js +99 -45
  60. package/dist/js/node/libs/render/index.js +106 -67
  61. package/dist/js/node/libs/render/measure.js +58 -31
  62. package/dist/js/node/libs/render/reader.js +95 -70
  63. package/dist/js/node/libs/render/ssr.js +80 -47
  64. package/dist/js/node/libs/render/static.js +79 -40
  65. package/dist/js/node/libs/render/type.js +31 -12
  66. package/dist/js/node/libs/route/index.js +31 -26
  67. package/dist/js/node/libs/route/matcher.js +40 -41
  68. package/dist/js/node/libs/route/route.js +29 -22
  69. package/dist/js/node/libs/serve-file.js +66 -32
  70. package/dist/js/node/server/index.js +168 -160
  71. package/dist/js/node/server/modern-server-split.js +72 -22
  72. package/dist/js/node/server/modern-server.js +403 -445
  73. package/dist/js/node/type.js +15 -3
  74. package/dist/js/node/utils.js +85 -52
  75. package/dist/js/node/worker-server.js +57 -21
  76. package/dist/js/treeshaking/constants.js +26 -25
  77. package/dist/js/treeshaking/index.js +10 -10
  78. package/dist/js/treeshaking/libs/context/context.js +268 -237
  79. package/dist/js/treeshaking/libs/context/index.js +3 -3
  80. package/dist/js/treeshaking/libs/hook-api/index.js +267 -143
  81. package/dist/js/treeshaking/libs/hook-api/route.js +65 -30
  82. package/dist/js/treeshaking/libs/hook-api/template.js +121 -85
  83. package/dist/js/treeshaking/libs/loadConfig.js +80 -37
  84. package/dist/js/treeshaking/libs/metrics.js +4 -10
  85. package/dist/js/treeshaking/libs/proxy.js +240 -76
  86. package/dist/js/treeshaking/libs/render/cache/__tests__/cache.fun.test.js +288 -121
  87. package/dist/js/treeshaking/libs/render/cache/__tests__/cache.test.js +772 -455
  88. package/dist/js/treeshaking/libs/render/cache/__tests__/cacheable.js +65 -51
  89. package/dist/js/treeshaking/libs/render/cache/__tests__/error-configuration.js +45 -35
  90. package/dist/js/treeshaking/libs/render/cache/__tests__/matched-cache.js +144 -118
  91. package/dist/js/treeshaking/libs/render/cache/index.js +337 -175
  92. package/dist/js/treeshaking/libs/render/cache/page-caches/index.js +151 -27
  93. package/dist/js/treeshaking/libs/render/cache/page-caches/lru.js +80 -42
  94. package/dist/js/treeshaking/libs/render/cache/spr.js +470 -340
  95. package/dist/js/treeshaking/libs/render/cache/type.js +1 -1
  96. package/dist/js/treeshaking/libs/render/cache/util.js +271 -92
  97. package/dist/js/treeshaking/libs/render/index.js +228 -95
  98. package/dist/js/treeshaking/libs/render/measure.js +142 -57
  99. package/dist/js/treeshaking/libs/render/reader.js +325 -177
  100. package/dist/js/treeshaking/libs/render/ssr.js +220 -95
  101. package/dist/js/treeshaking/libs/render/static.js +210 -78
  102. package/dist/js/treeshaking/libs/render/type.js +7 -6
  103. package/dist/js/treeshaking/libs/route/index.js +125 -89
  104. package/dist/js/treeshaking/libs/route/matcher.js +132 -107
  105. package/dist/js/treeshaking/libs/route/route.js +40 -26
  106. package/dist/js/treeshaking/libs/serve-file.js +177 -68
  107. package/dist/js/treeshaking/server/index.js +493 -327
  108. package/dist/js/treeshaking/server/modern-server-split.js +352 -144
  109. package/dist/js/treeshaking/server/modern-server.js +1048 -909
  110. package/dist/js/treeshaking/type.js +1 -1
  111. package/dist/js/treeshaking/utils.js +138 -81
  112. package/dist/js/treeshaking/worker-server.js +176 -55
  113. package/dist/types/index.d.ts +2 -0
  114. package/dist/types/libs/context/context.d.ts +4 -1
  115. package/dist/types/libs/loadConfig.d.ts +1 -0
  116. package/dist/types/libs/render/cache/index.d.ts +2 -0
  117. package/dist/types/libs/render/cache/spr.d.ts +2 -0
  118. package/dist/types/libs/route/route.d.ts +0 -1
  119. package/dist/types/server/index.d.ts +3 -0
  120. package/dist/types/utils.d.ts +1 -1
  121. package/dist/types/worker-server.d.ts +1 -2
  122. package/package.json +7 -14
  123. package/dist/js/modern/libs/render/modern/browser-list.js +0 -7
  124. package/dist/js/modern/libs/render/modern/index.js +0 -37
  125. package/dist/js/node/libs/render/modern/browser-list.js +0 -14
  126. package/dist/js/node/libs/render/modern/index.js +0 -46
  127. package/dist/js/treeshaking/libs/render/modern/browser-list.js +0 -7
  128. package/dist/js/treeshaking/libs/render/modern/index.js +0 -39
  129. package/dist/types/libs/render/modern/browser-list.d.ts +0 -1
  130. package/dist/types/libs/render/modern/index.d.ts +0 -3
@@ -1 +1 @@
1
- import { IncomingMessage } from 'http';
1
+ "use strict";
@@ -1,90 +1,147 @@
1
- import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
- import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
3
- import { createDebugger, isProd } from '@modern-js/utils';
4
- export var debug = createDebugger('prod-server');
5
- export var mergeExtension = function mergeExtension(users) {
6
- var output = [];
7
- return {
8
- middleware: output.concat(users)
9
- };
10
- };
11
- export var noop = function noop() {
12
- // noop
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 _arrayWithoutHoles(arr) {
7
+ if (Array.isArray(arr)) return _arrayLikeToArray(arr);
8
+ }
9
+ function _defineProperty(obj, key, value) {
10
+ if (key in obj) {
11
+ Object.defineProperty(obj, key, {
12
+ value: value,
13
+ enumerable: true,
14
+ configurable: true,
15
+ writable: true
16
+ });
17
+ } else {
18
+ obj[key] = value;
19
+ }
20
+ return obj;
21
+ }
22
+ function _iterableToArray(iter) {
23
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
24
+ }
25
+ function _nonIterableSpread() {
26
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
27
+ }
28
+ function _objectSpread(target) {
29
+ for(var i = 1; i < arguments.length; i++){
30
+ var source = arguments[i] != null ? arguments[i] : {};
31
+ var ownKeys = Object.keys(source);
32
+ if (typeof Object.getOwnPropertySymbols === "function") {
33
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
34
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
35
+ }));
36
+ }
37
+ ownKeys.forEach(function(key) {
38
+ _defineProperty(target, key, source[key]);
39
+ });
40
+ }
41
+ return target;
42
+ }
43
+ function _toConsumableArray(arr) {
44
+ return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
45
+ }
46
+ function _unsupportedIterableToArray(o, minLen) {
47
+ if (!o) return;
48
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
49
+ var n = Object.prototype.toString.call(o).slice(8, -1);
50
+ if (n === "Object" && o.constructor) n = o.constructor.name;
51
+ if (n === "Map" || n === "Set") return Array.from(n);
52
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
53
+ }
54
+ import { createDebugger, isProd } from "@modern-js/utils";
55
+ var debug = createDebugger("prod-server");
56
+ var mergeExtension = function(users) {
57
+ var output = [];
58
+ return {
59
+ middleware: output.concat(users)
60
+ };
13
61
  };
14
- export var createErrorDocument = function createErrorDocument(status, text) {
15
- var title = "".concat(status, ": ").concat(text);
16
- return "<!DOCTYPE html>\n <html lang=\"en\">\n <head>\n <meta charset=\"utf-8\">\n <meta name=\"viewport\" content=\"width=device-width\">\n <title>".concat(title, "</title>\n <style>\n html,body {\n margin: 0;\n }\n\n .page-container {\n color: #000;\n background: #fff;\n height: 100vh;\n text-align: center;\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n }\n </style>\n </head>\n <body>\n <div class=\"page-container\">\n <h1>").concat(status, "</h1>\n <div>").concat(text, "</div>\n </body>\n </html>\n ");
62
+ var noop = function() {};
63
+ var createErrorDocument = function(status, text) {
64
+ var title = "".concat(status, ": ").concat(text);
65
+ return '<!DOCTYPE html>\n <html lang="en">\n <head>\n <meta charset="utf-8">\n <meta name="viewport" content="width=device-width">\n <title>'.concat(title, '</title>\n <style>\n html,body {\n margin: 0;\n }\n\n .page-container {\n color: #000;\n background: #fff;\n height: 100vh;\n text-align: center;\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n }\n </style>\n </head>\n <body>\n <div class="page-container">\n <h1>').concat(status, "</h1>\n <div>").concat(text, "</div>\n </body>\n </html>\n ");
17
66
  };
18
- export var createMiddlewareCollecter = function createMiddlewareCollecter() {
19
- var webMiddlewares = [];
20
- var apiMiddlewares = [];
21
- var addWebMiddleware = function addWebMiddleware(input) {
22
- webMiddlewares.push(input);
23
- };
24
- var addAPIMiddleware = function addAPIMiddleware(input) {
25
- apiMiddlewares.push(input);
26
- };
27
- var getMiddlewares = function getMiddlewares() {
67
+ var createMiddlewareCollecter = function() {
68
+ var webMiddlewares = [];
69
+ var apiMiddlewares = [];
70
+ var addWebMiddleware = function(input) {
71
+ webMiddlewares.push(input);
72
+ };
73
+ var addAPIMiddleware = function(input) {
74
+ apiMiddlewares.push(input);
75
+ };
76
+ var getMiddlewares = function() {
77
+ return {
78
+ web: webMiddlewares,
79
+ api: apiMiddlewares
80
+ };
81
+ };
28
82
  return {
29
- web: webMiddlewares,
30
- api: apiMiddlewares
83
+ getMiddlewares: getMiddlewares,
84
+ addWebMiddleware: addWebMiddleware,
85
+ addAPIMiddleware: addAPIMiddleware
31
86
  };
32
- };
33
- return {
34
- getMiddlewares: getMiddlewares,
35
- addWebMiddleware: addWebMiddleware,
36
- addAPIMiddleware: addAPIMiddleware
37
- };
38
- };
39
- export var useLocalPrefix = function useLocalPrefix(url) {
40
- return isProd() && !url.includes('.');
41
87
  };
42
- export var getStaticReg = function getStaticReg() {
43
- var output = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
44
- var html = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
45
- var _output$distPath = output.distPath;
46
- _output$distPath = _output$distPath === void 0 ? {} : _output$distPath;
47
- var cssPath = _output$distPath.css,
48
- jsPath = _output$distPath.js,
49
- mediaPath = _output$distPath.media,
50
- _output$assetPrefix = output.assetPrefix,
51
- assetPrefix = _output$assetPrefix === void 0 ? '/' : _output$assetPrefix;
52
- var favicon = html.favicon,
53
- faviconByEntries = html.faviconByEntries;
54
- var prefix = useLocalPrefix(assetPrefix) ? assetPrefix : '';
55
- var favicons = prepareFavicons(favicon, faviconByEntries);
56
- var staticFiles = [cssPath, jsPath, mediaPath].filter(function (v) {
57
- return Boolean(v);
58
- });
59
- var staticReg = ['static/', 'upload/'].concat(_toConsumableArray(staticFiles));
60
- var iconReg = ['favicon.ico', 'icon.png'].concat(_toConsumableArray(favicons));
61
- var regPrefix = prefix.endsWith('/') ? prefix : "".concat(prefix, "/");
62
- var staticPathRegExp = new RegExp("^".concat(regPrefix, "(").concat([].concat(_toConsumableArray(staticReg), _toConsumableArray(iconReg)).join('|'), ")"));
63
- return staticPathRegExp;
88
+ var useLocalPrefix = function(url) {
89
+ return isProd() && !url.includes(".");
64
90
  };
65
- export var prepareFavicons = function prepareFavicons(favicon, faviconByEntries) {
66
- var faviconNames = [];
67
- if (favicon) {
68
- faviconNames.push(favicon.substring(favicon.lastIndexOf('/') + 1));
69
- }
70
- if (faviconByEntries) {
71
- Object.keys(faviconByEntries).forEach(function (f) {
72
- var curFavicon = faviconByEntries[f];
73
- if (curFavicon) {
74
- faviconNames.push(curFavicon.substring(curFavicon.lastIndexOf('/') + 1));
75
- }
91
+ var getStaticReg = function() {
92
+ var output = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, html = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
93
+ var tmp = output.distPath, ref = tmp === void 0 ? {} : tmp, cssPath = ref.css, jsPath = ref.js, mediaPath = ref.media, _assetPrefix = output.assetPrefix, assetPrefix = _assetPrefix === void 0 ? "/" : _assetPrefix;
94
+ var favicon = html.favicon, faviconByEntries = html.faviconByEntries;
95
+ var prefix = useLocalPrefix(assetPrefix) ? assetPrefix : "";
96
+ var favicons = prepareFavicons(favicon, faviconByEntries);
97
+ var staticFiles = [
98
+ cssPath,
99
+ jsPath,
100
+ mediaPath
101
+ ].filter(function(v) {
102
+ return Boolean(v);
76
103
  });
77
- }
78
- return faviconNames;
104
+ var staticReg = [
105
+ "static/",
106
+ "upload/"
107
+ ].concat(_toConsumableArray(staticFiles));
108
+ var iconReg = [
109
+ "favicon.ico",
110
+ "icon.png"
111
+ ].concat(_toConsumableArray(favicons));
112
+ var regPrefix = prefix.endsWith("/") ? prefix : "".concat(prefix, "/");
113
+ var staticPathRegExp = new RegExp("^".concat(regPrefix, "(").concat(_toConsumableArray(staticReg).concat(_toConsumableArray(iconReg)).join("|"), ")"));
114
+ return staticPathRegExp;
115
+ };
116
+ var prepareFavicons = function(favicon, faviconByEntries) {
117
+ var faviconNames = [];
118
+ if (favicon) {
119
+ faviconNames.push(favicon.substring(favicon.lastIndexOf("/") + 1));
120
+ }
121
+ if (faviconByEntries) {
122
+ Object.keys(faviconByEntries).forEach(function(f) {
123
+ var curFavicon = faviconByEntries[f];
124
+ if (curFavicon) {
125
+ faviconNames.push(curFavicon.substring(curFavicon.lastIndexOf("/") + 1));
126
+ }
127
+ });
128
+ }
129
+ return faviconNames;
130
+ };
131
+ var headersWithoutCookie = function(headers) {
132
+ if (typeof headers.cookie !== "undefined") {
133
+ var safeHeaders = _objectSpread({}, headers);
134
+ delete safeHeaders.cookie;
135
+ return safeHeaders;
136
+ }
137
+ return headers;
79
138
  };
80
- export var headersWithoutCookie = function headersWithoutCookie(headers) {
81
- if (typeof headers.cookie !== 'undefined') {
82
- var safeHeaders = _objectSpread({}, headers);
83
- delete safeHeaders.cookie;
84
- return safeHeaders;
85
- }
86
- return headers;
139
+ var isRedirect = function(code) {
140
+ return [
141
+ 301,
142
+ 302,
143
+ 307,
144
+ 308
145
+ ].includes(code);
87
146
  };
88
- export var isRedirect = function isRedirect(code) {
89
- return [301, 302, 307, 308].includes(code);
90
- };
147
+ export { createErrorDocument, createMiddlewareCollecter, debug, getStaticReg, headersWithoutCookie, isRedirect, mergeExtension, noop, prepareFavicons, useLocalPrefix };
@@ -1,56 +1,177 @@
1
- import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
2
- import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
3
- import { RouteMatchManager } from "./libs/route";
4
- export var createHandler = function createHandler(manifest) {
5
- var routeMgr = new RouteMatchManager();
6
- var pages = manifest.pages,
7
- routes = manifest.routes;
8
- routeMgr.reset(routes);
9
- return /*#__PURE__*/function () {
10
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(ctx) {
11
- var _ctx$request, _ctx$request$query, _ctx$request2, _ctx$request2$pathnam, _ctx$request3, _ctx$request3$params;
12
- var pageMatch, page, params;
13
- return _regeneratorRuntime().wrap(function _callee$(_context) {
14
- while (1) {
15
- switch (_context.prev = _context.next) {
16
- case 0:
17
- pageMatch = routeMgr.match(ctx.url);
18
- if (pageMatch) {
19
- _context.next = 5;
20
- break;
21
- }
22
- ctx.body = '404: Page not found';
23
- ctx.status = 404;
24
- return _context.abrupt("return");
25
- case 5:
26
- page = pages[pageMatch.spec.urlPath];
27
- (_ctx$request$query = (_ctx$request = ctx.request).query) !== null && _ctx$request$query !== void 0 ? _ctx$request$query : _ctx$request.query = ctx.query;
28
- (_ctx$request2$pathnam = (_ctx$request2 = ctx.request).pathname) !== null && _ctx$request2$pathnam !== void 0 ? _ctx$request2$pathnam : _ctx$request2.pathname = ctx.pathname;
29
- (_ctx$request3$params = (_ctx$request3 = ctx.request).params) !== null && _ctx$request3$params !== void 0 ? _ctx$request3$params : _ctx$request3.params = ctx.params;
30
- params = pageMatch.parseURLParams(ctx.url);
31
- _context.next = 12;
32
- return page.serverRender({
33
- template: page.template,
34
- query: ctx.query,
35
- request: ctx.request,
36
- response: ctx.response,
37
- pathname: ctx.pathname,
38
- req: ctx.request,
39
- res: ctx.response,
40
- params: ctx.params || params || {}
41
- });
42
- case 12:
43
- ctx.body = _context.sent;
44
- ctx.status = 200;
45
- case 14:
46
- case "end":
47
- return _context.stop();
48
- }
49
- }
50
- }, _callee);
51
- }));
52
- return function (_x) {
53
- return _ref.apply(this, arguments);
1
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
2
+ try {
3
+ var info = gen[key](arg);
4
+ var value = info.value;
5
+ } catch (error) {
6
+ reject(error);
7
+ return;
8
+ }
9
+ if (info.done) {
10
+ resolve(value);
11
+ } else {
12
+ Promise.resolve(value).then(_next, _throw);
13
+ }
14
+ }
15
+ function _asyncToGenerator(fn) {
16
+ return function() {
17
+ var self = this, args = arguments;
18
+ return new Promise(function(resolve, reject) {
19
+ var gen = fn.apply(self, args);
20
+ function _next(value) {
21
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
22
+ }
23
+ function _throw(err) {
24
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
25
+ }
26
+ _next(undefined);
27
+ });
28
+ };
29
+ }
30
+ var __generator = this && this.__generator || function(thisArg, body) {
31
+ var f, y, t, g, _ = {
32
+ label: 0,
33
+ sent: function() {
34
+ if (t[0] & 1) throw t[1];
35
+ return t[1];
36
+ },
37
+ trys: [],
38
+ ops: []
54
39
  };
55
- }();
56
- };
40
+ return(g = {
41
+ next: verb(0),
42
+ "throw": verb(1),
43
+ "return": verb(2)
44
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
45
+ return this;
46
+ }), g);
47
+ function verb(n) {
48
+ return function(v) {
49
+ return step([
50
+ n,
51
+ v
52
+ ]);
53
+ };
54
+ }
55
+ function step(op) {
56
+ if (f) throw new TypeError("Generator is already executing.");
57
+ while(_)try {
58
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
59
+ if (y = 0, t) op = [
60
+ op[0] & 2,
61
+ t.value
62
+ ];
63
+ switch(op[0]){
64
+ case 0:
65
+ case 1:
66
+ t = op;
67
+ break;
68
+ case 4:
69
+ _.label++;
70
+ return {
71
+ value: op[1],
72
+ done: false
73
+ };
74
+ case 5:
75
+ _.label++;
76
+ y = op[1];
77
+ op = [
78
+ 0
79
+ ];
80
+ continue;
81
+ case 7:
82
+ op = _.ops.pop();
83
+ _.trys.pop();
84
+ continue;
85
+ default:
86
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
87
+ _ = 0;
88
+ continue;
89
+ }
90
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
91
+ _.label = op[1];
92
+ break;
93
+ }
94
+ if (op[0] === 6 && _.label < t[1]) {
95
+ _.label = t[1];
96
+ t = op;
97
+ break;
98
+ }
99
+ if (t && _.label < t[2]) {
100
+ _.label = t[2];
101
+ _.ops.push(op);
102
+ break;
103
+ }
104
+ if (t[2]) _.ops.pop();
105
+ _.trys.pop();
106
+ continue;
107
+ }
108
+ op = body.call(thisArg, _);
109
+ } catch (e) {
110
+ op = [
111
+ 6,
112
+ e
113
+ ];
114
+ y = 0;
115
+ } finally{
116
+ f = t = 0;
117
+ }
118
+ if (op[0] & 5) throw op[1];
119
+ return {
120
+ value: op[0] ? op[1] : void 0,
121
+ done: true
122
+ };
123
+ }
124
+ };
125
+ var _request, _request1, _request2;
126
+ import { RouteMatchManager } from "./libs/route";
127
+ var createHandler = function(manifest) {
128
+ var routeMgr = new RouteMatchManager();
129
+ var pages = manifest.pages, routes = manifest.routes;
130
+ routeMgr.reset(routes);
131
+ return function() {
132
+ var _ref = _asyncToGenerator(function(ctx) {
133
+ var pageMatch, page, _query, _pathname, _params, params;
134
+ return __generator(this, function(_state) {
135
+ switch(_state.label){
136
+ case 0:
137
+ pageMatch = routeMgr.match(ctx.url);
138
+ if (!pageMatch) {
139
+ ctx.body = "404: Page not found";
140
+ ctx.status = 404;
141
+ return [
142
+ 2
143
+ ];
144
+ }
145
+ page = pages[pageMatch.spec.urlPath];
146
+ (_query = (_request = ctx.request).query) !== null && _query !== void 0 ? _query : _request.query = ctx.query;
147
+ (_pathname = (_request1 = ctx.request).pathname) !== null && _pathname !== void 0 ? _pathname : _request1.pathname = ctx.pathname;
148
+ (_params = (_request2 = ctx.request).params) !== null && _params !== void 0 ? _params : _request2.params = ctx.params;
149
+ params = pageMatch.parseURLParams(ctx.url);
150
+ return [
151
+ 4,
152
+ page.serverRender({
153
+ template: page.template,
154
+ query: ctx.query,
155
+ request: ctx.request,
156
+ response: ctx.response,
157
+ pathname: ctx.pathname,
158
+ req: ctx.request,
159
+ res: ctx.response,
160
+ params: ctx.params || params || {}
161
+ })
162
+ ];
163
+ case 1:
164
+ ctx.body = _state.sent();
165
+ ctx.status = 200;
166
+ return [
167
+ 2
168
+ ];
169
+ }
170
+ });
171
+ });
172
+ return function(ctx) {
173
+ return _ref.apply(this, arguments);
174
+ };
175
+ }();
176
+ };
177
+ export { createHandler };
@@ -6,5 +6,7 @@ export { ModernServer } from './server/modern-server';
6
6
  export { createProxyHandler } from './libs/proxy';
7
7
  export * from './type';
8
8
  export * from './constants';
9
+
9
10
  declare const _default: (options: ModernServerOptions) => Promise<Server>;
11
+
10
12
  export default _default;
@@ -1,9 +1,9 @@
1
- /// <reference path="../../type.d.ts" />
2
1
  /// <reference types="node" />
3
2
  /// <reference types="node" />
4
3
  /// <reference types="node" />
5
4
  /// <reference types="node" />
6
5
  /// <reference types="node/http" />
6
+ /// <reference types=".dts-temp/kvE-lN6mJShspqSQDC8Aw/src/type" />
7
7
  import { IncomingMessage, ServerResponse } from 'http';
8
8
  import { URL } from 'url';
9
9
  import qs from 'querystring';
@@ -20,10 +20,12 @@ export declare class ModernServerContext implements ModernServerContextInterface
20
20
  /**
21
21
  * http response
22
22
  */
23
+
23
24
  res: ServerResponse;
24
25
  /**
25
26
  * url params
26
27
  */
28
+
27
29
  params: Record<string, string>;
28
30
  get logger(): import("@modern-js/types").Logger;
29
31
  get metrics(): import("@modern-js/types").Metrics;
@@ -54,6 +56,7 @@ export declare class ModernServerContext implements ModernServerContextInterface
54
56
  /**
55
57
  * 判断链接是否已经关闭
56
58
  */
59
+
57
60
  resHasHandled(): boolean;
58
61
  error(dig: string, e?: Error | string): void;
59
62
  }
@@ -6,6 +6,7 @@ export declare const requireConfig: (serverConfigPath: string) => any;
6
6
  * 生产环境下,resolvedConfig 与 serverConfig 进行深合并
7
7
  * resolvedConfigPath: 构建序列化后的 modern.config.js 文件路径
8
8
  */
9
+
9
10
  export declare const loadConfig: ({
10
11
  cliConfig,
11
12
  serverConfig,
@@ -2,5 +2,7 @@
2
2
  import { Readable } from 'stream';
3
3
  import type { ModernServerContext } from '@modern-js/types';
4
4
  import { RenderFunction, SSRServerContext } from '../type';
5
+
5
6
  declare const _default: (renderFn: RenderFunction, ctx: ModernServerContext) => (context: SSRServerContext) => Promise<string | Readable>;
7
+
6
8
  export default _default;
@@ -1,5 +1,6 @@
1
1
  import LRUCache from 'lru-cache';
2
2
  import { CacheContent, CacheManagerOptions, CacheResult, CacheContext, CacheConfig } from './type';
3
+
3
4
  declare class CacheManager {
4
5
  cache: LRUCache<string, CacheContent>;
5
6
  cacheOptions: CacheManagerOptions;
@@ -17,6 +18,7 @@ declare class CacheManager {
17
18
  set(context: CacheContext, html: string, cacheConfig: CacheConfig, sync?: boolean): Promise<any>;
18
19
  del(context: CacheContext, cacheHash: string): Promise<void>;
19
20
  }
21
+
20
22
  export declare function createCache(): CacheManager;
21
23
  export declare function destroyCache(): void;
22
24
  export {};
@@ -8,7 +8,6 @@ export declare class ModernRoute implements ModernRouteInterface {
8
8
  isApi: boolean;
9
9
  isSSR: boolean;
10
10
  isSPA: boolean;
11
- enableModernMode?: boolean;
12
11
  params: Record<string, any>;
13
12
  responseHeaders?: Record<string, any>;
14
13
  constructor(routeSpec: ModernRouteInterface);
@@ -25,12 +25,14 @@ export declare class Server {
25
25
  * - 执行 prepare hook
26
26
  * - 执行 server init
27
27
  */
28
+
28
29
  init(): Promise<this>;
29
30
  /**
30
31
  * Execute config hooks
31
32
  * @param runner
32
33
  * @param options
33
34
  */
35
+
34
36
  private runConfigHook;
35
37
  private runPrepareHook;
36
38
  private initServerConfig;
@@ -38,6 +40,7 @@ export declare class Server {
38
40
  *
39
41
  * merge cliConfig and serverConfig
40
42
  */
43
+
41
44
  private initConfig;
42
45
  close(): Promise<void>;
43
46
  listen<T extends number | ListenOptions | undefined>(options: T, listener: any): void;
@@ -1,6 +1,6 @@
1
- /// <reference path="type.d.ts" />
2
1
  /// <reference types="node" />
3
2
  /// <reference types="node/http" />
3
+ /// <reference types=".dts-temp/kvE-lN6mJShspqSQDC8Aw/src/type" />
4
4
  import { IncomingMessage } from 'http';
5
5
  import type { OutputNormalizedConfig, HtmlNormalizedConfig } from '@modern-js/server-core';
6
6
  export declare const debug: any;
@@ -4,8 +4,7 @@ export interface UrlQuery {
4
4
  [key: string]: string;
5
5
  }
6
6
  export declare type Manifest = {
7
- pages: Record<string,
8
- // path
7
+ pages: Record<string, // path
9
8
  {
10
9
  entryName: string;
11
10
  template: string;
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "2.0.0-beta.3",
14
+ "version": "2.0.0-beta.6",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/js/node/index.js",
@@ -46,11 +46,9 @@
46
46
  }
47
47
  },
48
48
  "dependencies": {
49
- "@babel/compat-data": "^7.17.10",
50
49
  "axios": "^0.24.0",
51
50
  "etag": "^1.8.1",
52
51
  "fresh": "^0.5.2",
53
- "compare-versions": "^3.6.0",
54
52
  "cookie": "^0.4.2",
55
53
  "http-proxy-middleware": "^2.0.1",
56
54
  "ignore-styles": "^5.0.1",
@@ -58,9 +56,8 @@
58
56
  "merge-deep": "^3.0.3",
59
57
  "path-to-regexp": "^6.2.0",
60
58
  "serve-static": "^1.14.1",
61
- "ua-parser-js": "^0.7.28",
62
- "@modern-js/utils": "2.0.0-beta.3",
63
- "@modern-js/server-core": "2.0.0-beta.3"
59
+ "@modern-js/utils": "2.0.0-beta.6",
60
+ "@modern-js/server-core": "2.0.0-beta.6"
64
61
  },
65
62
  "devDependencies": {
66
63
  "@types/cookie": "^0.4.1",
@@ -71,20 +68,16 @@
71
68
  "@types/etag": "^1.8.1",
72
69
  "@types/fresh": "^0.5.0",
73
70
  "@types/serve-static": "^1.13.10",
74
- "@types/ua-parser-js": "^0.7.36",
75
71
  "jest": "^27",
76
72
  "node-mocks-http": "^1.11.0",
77
73
  "portfinder": "^1.0.28",
78
74
  "typescript": "^4",
79
- "@modern-js/types": "2.0.0-beta.3",
80
- "@modern-js/server-core": "2.0.0-beta.3",
81
- "@scripts/jest-config": "2.0.0-beta.3",
82
- "@scripts/build": "2.0.0-beta.3"
75
+ "@modern-js/types": "2.0.0-beta.6",
76
+ "@modern-js/server-core": "2.0.0-beta.6",
77
+ "@scripts/build": "2.0.0-beta.6",
78
+ "@scripts/jest-config": "2.0.0-beta.6"
83
79
  },
84
80
  "sideEffects": false,
85
- "modernConfig": {
86
- "output": {}
87
- },
88
81
  "publishConfig": {
89
82
  "access": "public",
90
83
  "registry": "https://registry.npmjs.org/"
@@ -1,7 +0,0 @@
1
- export const NativeModuleNameMap = {
2
- Chrome: 'chrome',
3
- 'Mobile Safari': 'ios_saf',
4
- Safari: 'safari',
5
- Edge: 'edge',
6
- Firefox: 'firefox'
7
- };