@modern-js/prod-server 2.6.1-alpha.0 → 2.8.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.
Files changed (133) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/README.md +2 -2
  3. package/dist/cjs/libs/context/context.js +8 -9
  4. package/dist/cjs/libs/serveFile.js +3 -4
  5. package/dist/cjs/server/modernServer.js +25 -15
  6. package/dist/cjs/utils.js +4 -13
  7. package/dist/esm/libs/context/context.js +11 -12
  8. package/dist/esm/libs/serveFile.js +4 -5
  9. package/dist/esm/server/modernServer.js +50 -28
  10. package/dist/esm/utils.js +4 -8
  11. package/dist/esm-node/libs/context/context.js +8 -9
  12. package/dist/esm-node/libs/serveFile.js +3 -4
  13. package/dist/esm-node/server/modernServer.js +32 -16
  14. package/dist/esm-node/utils.js +4 -12
  15. package/dist/types/libs/context/context.d.ts +2 -4
  16. package/dist/types/libs/serveFile.d.ts +1 -2
  17. package/dist/types/server/modernServer.d.ts +1 -1
  18. package/dist/types/utils.d.ts +2 -3
  19. package/package.json +11 -11
  20. package/dist/js/modern/constants.js +0 -35
  21. package/dist/js/modern/index.js +0 -18
  22. package/dist/js/modern/libs/context/context.js +0 -160
  23. package/dist/js/modern/libs/context/index.js +0 -6
  24. package/dist/js/modern/libs/hook-api/index.js +0 -134
  25. package/dist/js/modern/libs/hook-api/route.js +0 -20
  26. package/dist/js/modern/libs/hook-api/template.js +0 -73
  27. package/dist/js/modern/libs/loadConfig.js +0 -62
  28. package/dist/js/modern/libs/logger.js +0 -111
  29. package/dist/js/modern/libs/metrics.js +0 -11
  30. package/dist/js/modern/libs/proxy.js +0 -92
  31. package/dist/js/modern/libs/render/cache/__tests__/cache.fun.test.js +0 -114
  32. package/dist/js/modern/libs/render/cache/__tests__/cache.test.js +0 -254
  33. package/dist/js/modern/libs/render/cache/__tests__/cacheable.js +0 -47
  34. package/dist/js/modern/libs/render/cache/__tests__/error-configuration.js +0 -37
  35. package/dist/js/modern/libs/render/cache/__tests__/matched-cache.js +0 -91
  36. package/dist/js/modern/libs/render/cache/index.js +0 -115
  37. package/dist/js/modern/libs/render/cache/page-caches/index.js +0 -32
  38. package/dist/js/modern/libs/render/cache/page-caches/lru.js +0 -29
  39. package/dist/js/modern/libs/render/cache/spr.js +0 -248
  40. package/dist/js/modern/libs/render/cache/type.js +0 -0
  41. package/dist/js/modern/libs/render/cache/util.js +0 -102
  42. package/dist/js/modern/libs/render/index.js +0 -86
  43. package/dist/js/modern/libs/render/measure.js +0 -68
  44. package/dist/js/modern/libs/render/reader.js +0 -107
  45. package/dist/js/modern/libs/render/ssr.js +0 -100
  46. package/dist/js/modern/libs/render/static.js +0 -60
  47. package/dist/js/modern/libs/render/type.js +0 -9
  48. package/dist/js/modern/libs/route/index.js +0 -54
  49. package/dist/js/modern/libs/route/matcher.js +0 -87
  50. package/dist/js/modern/libs/route/route.js +0 -16
  51. package/dist/js/modern/libs/serve-file.js +0 -67
  52. package/dist/js/modern/server/index.js +0 -208
  53. package/dist/js/modern/server/modern-server-split.js +0 -74
  54. package/dist/js/modern/server/modern-server.js +0 -554
  55. package/dist/js/modern/type.js +0 -0
  56. package/dist/js/modern/utils.js +0 -136
  57. package/dist/js/modern/worker-server.js +0 -89
  58. package/dist/js/node/constants.js +0 -62
  59. package/dist/js/node/index.js +0 -44
  60. package/dist/js/node/libs/context/context.js +0 -189
  61. package/dist/js/node/libs/context/index.js +0 -30
  62. package/dist/js/node/libs/hook-api/index.js +0 -164
  63. package/dist/js/node/libs/hook-api/route.js +0 -43
  64. package/dist/js/node/libs/hook-api/template.js +0 -97
  65. package/dist/js/node/libs/loadConfig.js +0 -91
  66. package/dist/js/node/libs/logger.js +0 -133
  67. package/dist/js/node/libs/metrics.js +0 -34
  68. package/dist/js/node/libs/proxy.js +0 -114
  69. package/dist/js/node/libs/render/cache/__tests__/cache.fun.test.js +0 -115
  70. package/dist/js/node/libs/render/cache/__tests__/cache.test.js +0 -245
  71. package/dist/js/node/libs/render/cache/__tests__/cacheable.js +0 -70
  72. package/dist/js/node/libs/render/cache/__tests__/error-configuration.js +0 -60
  73. package/dist/js/node/libs/render/cache/__tests__/matched-cache.js +0 -114
  74. package/dist/js/node/libs/render/cache/index.js +0 -134
  75. package/dist/js/node/libs/render/cache/page-caches/index.js +0 -55
  76. package/dist/js/node/libs/render/cache/page-caches/lru.js +0 -58
  77. package/dist/js/node/libs/render/cache/spr.js +0 -270
  78. package/dist/js/node/libs/render/cache/type.js +0 -15
  79. package/dist/js/node/libs/render/cache/util.js +0 -138
  80. package/dist/js/node/libs/render/index.js +0 -115
  81. package/dist/js/node/libs/render/measure.js +0 -90
  82. package/dist/js/node/libs/render/reader.js +0 -140
  83. package/dist/js/node/libs/render/ssr.js +0 -123
  84. package/dist/js/node/libs/render/static.js +0 -89
  85. package/dist/js/node/libs/render/type.js +0 -32
  86. package/dist/js/node/libs/route/index.js +0 -78
  87. package/dist/js/node/libs/route/matcher.js +0 -106
  88. package/dist/js/node/libs/route/route.js +0 -39
  89. package/dist/js/node/libs/serve-file.js +0 -97
  90. package/dist/js/node/server/index.js +0 -219
  91. package/dist/js/node/server/modern-server-split.js +0 -97
  92. package/dist/js/node/server/modern-server.js +0 -559
  93. package/dist/js/node/type.js +0 -15
  94. package/dist/js/node/utils.js +0 -166
  95. package/dist/js/node/worker-server.js +0 -113
  96. package/dist/js/treeshaking/constants.js +0 -29
  97. package/dist/js/treeshaking/index.js +0 -13
  98. package/dist/js/treeshaking/libs/context/context.js +0 -274
  99. package/dist/js/treeshaking/libs/context/index.js +0 -5
  100. package/dist/js/treeshaking/libs/hook-api/index.js +0 -281
  101. package/dist/js/treeshaking/libs/hook-api/route.js +0 -68
  102. package/dist/js/treeshaking/libs/hook-api/template.js +0 -127
  103. package/dist/js/treeshaking/libs/loadConfig.js +0 -82
  104. package/dist/js/treeshaking/libs/logger.js +0 -205
  105. package/dist/js/treeshaking/libs/metrics.js +0 -6
  106. package/dist/js/treeshaking/libs/proxy.js +0 -244
  107. package/dist/js/treeshaking/libs/render/cache/__tests__/cache.fun.test.js +0 -291
  108. package/dist/js/treeshaking/libs/render/cache/__tests__/cache.test.js +0 -781
  109. package/dist/js/treeshaking/libs/render/cache/__tests__/cacheable.js +0 -67
  110. package/dist/js/treeshaking/libs/render/cache/__tests__/error-configuration.js +0 -45
  111. package/dist/js/treeshaking/libs/render/cache/__tests__/matched-cache.js +0 -147
  112. package/dist/js/treeshaking/libs/render/cache/index.js +0 -346
  113. package/dist/js/treeshaking/libs/render/cache/page-caches/index.js +0 -154
  114. package/dist/js/treeshaking/libs/render/cache/page-caches/lru.js +0 -84
  115. package/dist/js/treeshaking/libs/render/cache/spr.js +0 -492
  116. package/dist/js/treeshaking/libs/render/cache/type.js +0 -1
  117. package/dist/js/treeshaking/libs/render/cache/util.js +0 -280
  118. package/dist/js/treeshaking/libs/render/index.js +0 -234
  119. package/dist/js/treeshaking/libs/render/measure.js +0 -146
  120. package/dist/js/treeshaking/libs/render/reader.js +0 -339
  121. package/dist/js/treeshaking/libs/render/ssr.js +0 -223
  122. package/dist/js/treeshaking/libs/render/static.js +0 -216
  123. package/dist/js/treeshaking/libs/render/type.js +0 -7
  124. package/dist/js/treeshaking/libs/route/index.js +0 -130
  125. package/dist/js/treeshaking/libs/route/matcher.js +0 -143
  126. package/dist/js/treeshaking/libs/route/route.js +0 -40
  127. package/dist/js/treeshaking/libs/serve-file.js +0 -184
  128. package/dist/js/treeshaking/server/index.js +0 -505
  129. package/dist/js/treeshaking/server/modern-server-split.js +0 -360
  130. package/dist/js/treeshaking/server/modern-server.js +0 -1089
  131. package/dist/js/treeshaking/type.js +0 -1
  132. package/dist/js/treeshaking/utils.js +0 -147
  133. package/dist/js/treeshaking/worker-server.js +0 -233
@@ -1 +0,0 @@
1
- "use strict";
@@ -1,147 +0,0 @@
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
- };
61
- };
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 ");
66
- };
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
- };
82
- return {
83
- getMiddlewares: getMiddlewares,
84
- addWebMiddleware: addWebMiddleware,
85
- addAPIMiddleware: addAPIMiddleware
86
- };
87
- };
88
- var useLocalPrefix = function(url) {
89
- return isProd() && !url.includes(".");
90
- };
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, _output_assetPrefix = output.assetPrefix, assetPrefix = _output_assetPrefix === void 0 ? "/" : _output_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);
103
- });
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;
138
- };
139
- var isRedirect = function(code) {
140
- return [
141
- 301,
142
- 302,
143
- 307,
144
- 308
145
- ].includes(code);
146
- };
147
- export { createErrorDocument, createMiddlewareCollecter, debug, getStaticReg, headersWithoutCookie, isRedirect, mergeExtension, noop, prepareFavicons, useLocalPrefix };
@@ -1,233 +0,0 @@
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: []
39
- };
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 _ctx_request, _ctx_request1, _ctx_request2;
126
- import { Logger } from "./libs/logger";
127
- import { RouteMatchManager } from "./libs/route";
128
- import { metrics as defaultMetrics } from "./libs/metrics";
129
- var handleUrl = function(url) {
130
- return url.replace(/^https?:\/\/.*?\//gi, "/");
131
- };
132
- var createHandler = function(manifest) {
133
- var routeMgr = new RouteMatchManager();
134
- var pages = manifest.pages, routes = manifest.routes;
135
- routeMgr.reset(routes);
136
- return function() {
137
- var _ref = _asyncToGenerator(function(ctx) {
138
- var pageMatch, page, _query, _pathname, _params, params, e;
139
- return __generator(this, function(_state) {
140
- switch(_state.label){
141
- case 0:
142
- pageMatch = routeMgr.match(ctx.url);
143
- if (!pageMatch) {
144
- ctx.body = "404: Page not found";
145
- ctx.status = 404;
146
- return [
147
- 2
148
- ];
149
- }
150
- page = pages[pageMatch.spec.urlPath];
151
- (_query = (_ctx_request = ctx.request).query) !== null && _query !== void 0 ? _query : _ctx_request.query = ctx.query;
152
- (_pathname = (_ctx_request1 = ctx.request).pathname) !== null && _pathname !== void 0 ? _pathname : _ctx_request1.pathname = ctx.pathname;
153
- (_params = (_ctx_request2 = ctx.request).params) !== null && _params !== void 0 ? _params : _ctx_request2.params = ctx.params;
154
- params = pageMatch.parseURLParams(ctx.url);
155
- if (!page.serverRender) return [
156
- 3,
157
- 4
158
- ];
159
- _state.label = 1;
160
- case 1:
161
- _state.trys.push([
162
- 1,
163
- 3,
164
- ,
165
- 4
166
- ]);
167
- return [
168
- 4,
169
- page.serverRender({
170
- entryName: page.entryName,
171
- template: page.template,
172
- query: ctx.query,
173
- request: ctx.request,
174
- response: ctx.response,
175
- pathname: ctx.pathname,
176
- req: ctx.request,
177
- res: ctx.response,
178
- params: ctx.params || params || {},
179
- logger: ctx.logger || new Logger({
180
- level: "warn"
181
- }),
182
- metrics: ctx.metrics || defaultMetrics,
183
- loadableStats: ctx.loadableStats,
184
- routeManifest: ctx.routeManifest
185
- })
186
- ];
187
- case 2:
188
- ctx.body = _state.sent();
189
- ctx.status = 200;
190
- return [
191
- 2
192
- ];
193
- case 3:
194
- e = _state.sent();
195
- if (page.template) {
196
- ctx.body = page.template;
197
- ctx.status = 200;
198
- return [
199
- 2
200
- ];
201
- } else {
202
- ctx.body = "404: not found";
203
- ctx.status = 404;
204
- return [
205
- 2
206
- ];
207
- }
208
- return [
209
- 3,
210
- 4
211
- ];
212
- case 4:
213
- if (page.template) {
214
- ctx.body = page.template;
215
- ctx.status = 200;
216
- return [
217
- 2
218
- ];
219
- }
220
- ctx.body = "404: not found";
221
- ctx.status = 404;
222
- return [
223
- 2
224
- ];
225
- }
226
- });
227
- });
228
- return function(ctx) {
229
- return _ref.apply(this, arguments);
230
- };
231
- }();
232
- };
233
- export { createHandler, handleUrl };