@modern-js/prod-server 2.5.1-alpha.2 → 2.6.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 (154) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/cjs/libs/context/context.js +13 -0
  3. package/dist/cjs/libs/hook-api/index.js +4 -0
  4. package/dist/cjs/libs/loadConfig.js +5 -0
  5. package/dist/cjs/libs/render/cache/__tests__/cache.fun.test.js +4 -0
  6. package/dist/cjs/libs/render/cache/page-caches/lru.js +4 -0
  7. package/dist/cjs/libs/render/cache/spr.js +5 -0
  8. package/dist/cjs/libs/render/cache/util.js +4 -0
  9. package/dist/cjs/libs/render/index.js +4 -0
  10. package/dist/cjs/libs/render/reader.js +9 -0
  11. package/dist/cjs/libs/render/ssr.js +16 -4
  12. package/dist/cjs/libs/render/static.js +4 -0
  13. package/dist/cjs/libs/route/index.js +4 -0
  14. package/dist/cjs/libs/route/matcher.js +4 -0
  15. package/dist/cjs/libs/serve-file.js +26 -19
  16. package/dist/cjs/server/index.js +32 -4
  17. package/dist/cjs/server/modern-server.js +19 -3
  18. package/dist/esm/libs/context/context.js +15 -6
  19. package/dist/esm/libs/render/cache/spr.js +1 -0
  20. package/dist/esm/libs/render/ssr.js +5 -5
  21. package/dist/esm/libs/route/index.js +4 -0
  22. package/dist/esm/libs/route/matcher.js +4 -0
  23. package/dist/esm/libs/serve-file.js +2 -1
  24. package/dist/esm/server/index.js +30 -7
  25. package/dist/esm/server/modern-server.js +17 -4
  26. package/dist/esm-node/libs/context/context.js +9 -0
  27. package/dist/esm-node/libs/loadConfig.js +1 -0
  28. package/dist/esm-node/libs/render/cache/spr.js +1 -0
  29. package/dist/esm-node/libs/render/reader.js +5 -0
  30. package/dist/esm-node/libs/render/ssr.js +12 -4
  31. package/dist/esm-node/libs/route/index.js +4 -0
  32. package/dist/esm-node/libs/route/matcher.js +4 -0
  33. package/dist/esm-node/libs/serve-file.js +22 -19
  34. package/dist/esm-node/server/index.js +28 -4
  35. package/dist/esm-node/server/modern-server.js +15 -3
  36. package/dist/types/libs/context/context.d.ts +1 -1
  37. package/dist/types/libs/render/ssr.d.ts +1 -0
  38. package/dist/types/type.d.ts +1 -8
  39. package/dist/types/utils.d.ts +1 -1
  40. package/package.json +9 -9
  41. package/dist/js/modern/constants.js +0 -35
  42. package/dist/js/modern/index.js +0 -18
  43. package/dist/js/modern/libs/context/context.js +0 -160
  44. package/dist/js/modern/libs/context/index.js +0 -6
  45. package/dist/js/modern/libs/hook-api/index.js +0 -134
  46. package/dist/js/modern/libs/hook-api/route.js +0 -20
  47. package/dist/js/modern/libs/hook-api/template.js +0 -73
  48. package/dist/js/modern/libs/loadConfig.js +0 -62
  49. package/dist/js/modern/libs/logger.js +0 -111
  50. package/dist/js/modern/libs/metrics.js +0 -11
  51. package/dist/js/modern/libs/proxy.js +0 -92
  52. package/dist/js/modern/libs/render/cache/__tests__/cache.fun.test.js +0 -114
  53. package/dist/js/modern/libs/render/cache/__tests__/cache.test.js +0 -254
  54. package/dist/js/modern/libs/render/cache/__tests__/cacheable.js +0 -47
  55. package/dist/js/modern/libs/render/cache/__tests__/error-configuration.js +0 -37
  56. package/dist/js/modern/libs/render/cache/__tests__/matched-cache.js +0 -91
  57. package/dist/js/modern/libs/render/cache/index.js +0 -115
  58. package/dist/js/modern/libs/render/cache/page-caches/index.js +0 -32
  59. package/dist/js/modern/libs/render/cache/page-caches/lru.js +0 -29
  60. package/dist/js/modern/libs/render/cache/spr.js +0 -248
  61. package/dist/js/modern/libs/render/cache/type.js +0 -0
  62. package/dist/js/modern/libs/render/cache/util.js +0 -102
  63. package/dist/js/modern/libs/render/index.js +0 -86
  64. package/dist/js/modern/libs/render/measure.js +0 -68
  65. package/dist/js/modern/libs/render/reader.js +0 -107
  66. package/dist/js/modern/libs/render/ssr.js +0 -100
  67. package/dist/js/modern/libs/render/static.js +0 -60
  68. package/dist/js/modern/libs/render/type.js +0 -9
  69. package/dist/js/modern/libs/route/index.js +0 -54
  70. package/dist/js/modern/libs/route/matcher.js +0 -87
  71. package/dist/js/modern/libs/route/route.js +0 -16
  72. package/dist/js/modern/libs/serve-file.js +0 -67
  73. package/dist/js/modern/server/index.js +0 -208
  74. package/dist/js/modern/server/modern-server-split.js +0 -74
  75. package/dist/js/modern/server/modern-server.js +0 -554
  76. package/dist/js/modern/type.js +0 -0
  77. package/dist/js/modern/utils.js +0 -136
  78. package/dist/js/modern/worker-server.js +0 -89
  79. package/dist/js/node/constants.js +0 -62
  80. package/dist/js/node/index.js +0 -44
  81. package/dist/js/node/libs/context/context.js +0 -189
  82. package/dist/js/node/libs/context/index.js +0 -30
  83. package/dist/js/node/libs/hook-api/index.js +0 -164
  84. package/dist/js/node/libs/hook-api/route.js +0 -43
  85. package/dist/js/node/libs/hook-api/template.js +0 -97
  86. package/dist/js/node/libs/loadConfig.js +0 -91
  87. package/dist/js/node/libs/logger.js +0 -133
  88. package/dist/js/node/libs/metrics.js +0 -34
  89. package/dist/js/node/libs/proxy.js +0 -114
  90. package/dist/js/node/libs/render/cache/__tests__/cache.fun.test.js +0 -115
  91. package/dist/js/node/libs/render/cache/__tests__/cache.test.js +0 -245
  92. package/dist/js/node/libs/render/cache/__tests__/cacheable.js +0 -70
  93. package/dist/js/node/libs/render/cache/__tests__/error-configuration.js +0 -60
  94. package/dist/js/node/libs/render/cache/__tests__/matched-cache.js +0 -114
  95. package/dist/js/node/libs/render/cache/index.js +0 -134
  96. package/dist/js/node/libs/render/cache/page-caches/index.js +0 -55
  97. package/dist/js/node/libs/render/cache/page-caches/lru.js +0 -58
  98. package/dist/js/node/libs/render/cache/spr.js +0 -270
  99. package/dist/js/node/libs/render/cache/type.js +0 -15
  100. package/dist/js/node/libs/render/cache/util.js +0 -138
  101. package/dist/js/node/libs/render/index.js +0 -115
  102. package/dist/js/node/libs/render/measure.js +0 -90
  103. package/dist/js/node/libs/render/reader.js +0 -140
  104. package/dist/js/node/libs/render/ssr.js +0 -123
  105. package/dist/js/node/libs/render/static.js +0 -89
  106. package/dist/js/node/libs/render/type.js +0 -32
  107. package/dist/js/node/libs/route/index.js +0 -78
  108. package/dist/js/node/libs/route/matcher.js +0 -106
  109. package/dist/js/node/libs/route/route.js +0 -39
  110. package/dist/js/node/libs/serve-file.js +0 -97
  111. package/dist/js/node/server/index.js +0 -219
  112. package/dist/js/node/server/modern-server-split.js +0 -97
  113. package/dist/js/node/server/modern-server.js +0 -559
  114. package/dist/js/node/type.js +0 -15
  115. package/dist/js/node/utils.js +0 -166
  116. package/dist/js/node/worker-server.js +0 -113
  117. package/dist/js/treeshaking/constants.js +0 -29
  118. package/dist/js/treeshaking/index.js +0 -13
  119. package/dist/js/treeshaking/libs/context/context.js +0 -274
  120. package/dist/js/treeshaking/libs/context/index.js +0 -5
  121. package/dist/js/treeshaking/libs/hook-api/index.js +0 -281
  122. package/dist/js/treeshaking/libs/hook-api/route.js +0 -68
  123. package/dist/js/treeshaking/libs/hook-api/template.js +0 -127
  124. package/dist/js/treeshaking/libs/loadConfig.js +0 -82
  125. package/dist/js/treeshaking/libs/logger.js +0 -205
  126. package/dist/js/treeshaking/libs/metrics.js +0 -6
  127. package/dist/js/treeshaking/libs/proxy.js +0 -244
  128. package/dist/js/treeshaking/libs/render/cache/__tests__/cache.fun.test.js +0 -291
  129. package/dist/js/treeshaking/libs/render/cache/__tests__/cache.test.js +0 -781
  130. package/dist/js/treeshaking/libs/render/cache/__tests__/cacheable.js +0 -67
  131. package/dist/js/treeshaking/libs/render/cache/__tests__/error-configuration.js +0 -45
  132. package/dist/js/treeshaking/libs/render/cache/__tests__/matched-cache.js +0 -147
  133. package/dist/js/treeshaking/libs/render/cache/index.js +0 -346
  134. package/dist/js/treeshaking/libs/render/cache/page-caches/index.js +0 -154
  135. package/dist/js/treeshaking/libs/render/cache/page-caches/lru.js +0 -84
  136. package/dist/js/treeshaking/libs/render/cache/spr.js +0 -492
  137. package/dist/js/treeshaking/libs/render/cache/type.js +0 -1
  138. package/dist/js/treeshaking/libs/render/cache/util.js +0 -280
  139. package/dist/js/treeshaking/libs/render/index.js +0 -234
  140. package/dist/js/treeshaking/libs/render/measure.js +0 -146
  141. package/dist/js/treeshaking/libs/render/reader.js +0 -339
  142. package/dist/js/treeshaking/libs/render/ssr.js +0 -223
  143. package/dist/js/treeshaking/libs/render/static.js +0 -216
  144. package/dist/js/treeshaking/libs/render/type.js +0 -7
  145. package/dist/js/treeshaking/libs/route/index.js +0 -130
  146. package/dist/js/treeshaking/libs/route/matcher.js +0 -143
  147. package/dist/js/treeshaking/libs/route/route.js +0 -40
  148. package/dist/js/treeshaking/libs/serve-file.js +0 -184
  149. package/dist/js/treeshaking/server/index.js +0 -505
  150. package/dist/js/treeshaking/server/modern-server-split.js +0 -360
  151. package/dist/js/treeshaking/server/modern-server.js +0 -1089
  152. package/dist/js/treeshaking/type.js +0 -1
  153. package/dist/js/treeshaking/utils.js +0 -147
  154. package/dist/js/treeshaking/worker-server.js +0 -233
@@ -1,216 +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
- import path from "path";
126
- import { mime } from "@modern-js/utils";
127
- import { readFile } from "./reader";
128
- function handleDirectory(ctx, entryPath, urlPath) {
129
- return _handleDirectory.apply(this, arguments);
130
- }
131
- function _handleDirectory() {
132
- _handleDirectory = _asyncToGenerator(function(ctx, entryPath, urlPath) {
133
- var pathname, filepath, content, contentType;
134
- return __generator(this, function(_state) {
135
- switch(_state.label){
136
- case 0:
137
- pathname = ctx.path;
138
- filepath = path.join(entryPath, trimLeft(pathname, urlPath));
139
- return [
140
- 4,
141
- readFile(filepath)
142
- ];
143
- case 1:
144
- content = _state.sent();
145
- contentType = mime.contentType(path.extname(filepath) || "");
146
- if (!!content) return [
147
- 3,
148
- 7
149
- ];
150
- if (!pathname.endsWith("/")) return [
151
- 3,
152
- 3
153
- ];
154
- return [
155
- 4,
156
- readFile("".concat(filepath, "index.html"))
157
- ];
158
- case 2:
159
- content = _state.sent();
160
- return [
161
- 3,
162
- 6
163
- ];
164
- case 3:
165
- if (!!pathname.includes(".")) return [
166
- 3,
167
- 6
168
- ];
169
- return [
170
- 4,
171
- readFile("".concat(filepath, ".html"))
172
- ];
173
- case 4:
174
- content = _state.sent();
175
- if (!!content) return [
176
- 3,
177
- 6
178
- ];
179
- return [
180
- 4,
181
- readFile("".concat(filepath, "/index.html"))
182
- ];
183
- case 5:
184
- content = _state.sent();
185
- _state.label = 6;
186
- case 6:
187
- if (content) {
188
- contentType = mime.contentType("html");
189
- }
190
- _state.label = 7;
191
- case 7:
192
- if (!content) {
193
- return [
194
- 2,
195
- null
196
- ];
197
- }
198
- return [
199
- 2,
200
- {
201
- content: content,
202
- contentType: contentType || ""
203
- }
204
- ];
205
- }
206
- });
207
- });
208
- return _handleDirectory.apply(this, arguments);
209
- }
210
- var trimLeft = function(str, prefix) {
211
- if (str.startsWith(prefix)) {
212
- return str.substring(prefix.length);
213
- }
214
- return str;
215
- };
216
- export { handleDirectory };
@@ -1,7 +0,0 @@
1
- var RenderLevel = /* @__PURE__ */ function(RenderLevel2) {
2
- RenderLevel2[RenderLevel2["CLIENT_RENDER"] = 0] = "CLIENT_RENDER";
3
- RenderLevel2[RenderLevel2["SERVER_PREFETCH"] = 1] = "SERVER_PREFETCH";
4
- RenderLevel2[RenderLevel2["SERVER_RENDER"] = 2] = "SERVER_RENDER";
5
- return RenderLevel2;
6
- }(RenderLevel || {});
7
- export { RenderLevel };
@@ -1,130 +0,0 @@
1
- function _classCallCheck(instance, Constructor) {
2
- if (!(instance instanceof Constructor)) {
3
- throw new TypeError("Cannot call a class as a function");
4
- }
5
- }
6
- function _defineProperties(target, props) {
7
- for(var i = 0; i < props.length; i++){
8
- var descriptor = props[i];
9
- descriptor.enumerable = descriptor.enumerable || false;
10
- descriptor.configurable = true;
11
- if ("value" in descriptor) descriptor.writable = true;
12
- Object.defineProperty(target, descriptor.key, descriptor);
13
- }
14
- }
15
- function _createClass(Constructor, protoProps, staticProps) {
16
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
17
- if (staticProps) _defineProperties(Constructor, staticProps);
18
- return Constructor;
19
- }
20
- function _defineProperty(obj, key, value) {
21
- if (key in obj) {
22
- Object.defineProperty(obj, key, {
23
- value: value,
24
- enumerable: true,
25
- configurable: true,
26
- writable: true
27
- });
28
- } else {
29
- obj[key] = value;
30
- }
31
- return obj;
32
- }
33
- import { RouteMatcher } from "./matcher";
34
- var RouteMatchManager = /*#__PURE__*/ function() {
35
- "use strict";
36
- function RouteMatchManager() {
37
- _classCallCheck(this, RouteMatchManager);
38
- _defineProperty(this, "matchers", void 0);
39
- _defineProperty(this, "specs", []);
40
- this.matchers = [];
41
- }
42
- _createClass(RouteMatchManager, [
43
- {
44
- key: "filter",
45
- value: function filter(pathname) {
46
- return this.matchers.reduce(function(matches, matcher) {
47
- if (matcher.matchUrlPath(pathname)) {
48
- matches.push(matcher);
49
- }
50
- return matches;
51
- }, []);
52
- }
53
- },
54
- {
55
- key: "best",
56
- value: function best(pathname, matches) {
57
- var best;
58
- var matchedLen = 0;
59
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
60
- try {
61
- for(var _iterator = matches[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
62
- var match = _step.value;
63
- var len = match.matchLength(pathname);
64
- if (len === null) {
65
- continue;
66
- }
67
- if (len > matchedLen) {
68
- best = match;
69
- matchedLen = len;
70
- }
71
- }
72
- } catch (err) {
73
- _didIteratorError = true;
74
- _iteratorError = err;
75
- } finally{
76
- try {
77
- if (!_iteratorNormalCompletion && _iterator.return != null) {
78
- _iterator.return();
79
- }
80
- } finally{
81
- if (_didIteratorError) {
82
- throw _iteratorError;
83
- }
84
- }
85
- }
86
- return best;
87
- }
88
- },
89
- {
90
- key: "reset",
91
- value: function reset(specs) {
92
- this.specs = specs;
93
- var matchers = specs.reduce(function(ms, spec) {
94
- ms.push(new RouteMatcher(spec));
95
- return ms;
96
- }, []);
97
- this.matchers = matchers;
98
- }
99
- },
100
- {
101
- key: "match",
102
- value: function match(pathname) {
103
- var matches = this.filter(pathname);
104
- var best = this.best(pathname, matches);
105
- return best;
106
- }
107
- },
108
- {
109
- key: "matchEntry",
110
- value: function matchEntry(entryname) {
111
- return this.matchers.find(function(matcher) {
112
- return matcher.matchEntry(entryname);
113
- });
114
- }
115
- },
116
- {
117
- key: "getBundles",
118
- value: function getBundles() {
119
- var bundles = this.specs.filter(function(route) {
120
- return route.isSSR;
121
- }).map(function(route) {
122
- return route.bundle;
123
- });
124
- return bundles;
125
- }
126
- }
127
- ]);
128
- return RouteMatchManager;
129
- }();
130
- export { RouteMatchManager, RouteMatcher };
@@ -1,143 +0,0 @@
1
- function _classCallCheck(instance, Constructor) {
2
- if (!(instance instanceof Constructor)) {
3
- throw new TypeError("Cannot call a class as a function");
4
- }
5
- }
6
- function _defineProperties(target, props) {
7
- for(var i = 0; i < props.length; i++){
8
- var descriptor = props[i];
9
- descriptor.enumerable = descriptor.enumerable || false;
10
- descriptor.configurable = true;
11
- if ("value" in descriptor) descriptor.writable = true;
12
- Object.defineProperty(target, descriptor.key, descriptor);
13
- }
14
- }
15
- function _createClass(Constructor, protoProps, staticProps) {
16
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
17
- if (staticProps) _defineProperties(Constructor, staticProps);
18
- return Constructor;
19
- }
20
- function _defineProperty(obj, key, value) {
21
- if (key in obj) {
22
- Object.defineProperty(obj, key, {
23
- value: value,
24
- enumerable: true,
25
- configurable: true,
26
- writable: true
27
- });
28
- } else {
29
- obj[key] = value;
30
- }
31
- return obj;
32
- }
33
- import { match, pathToRegexp, compile } from "path-to-regexp";
34
- import { ModernRoute } from "./route";
35
- var removeTailSlash = function(s) {
36
- return s.replace(/\/+$/, "");
37
- };
38
- var removeHtmlSuffix = function(url) {
39
- if (url.endsWith(".html")) {
40
- return url.slice(0, -5);
41
- }
42
- return url;
43
- };
44
- var toPath = function(reg, params) {
45
- var fn = compile(reg, {
46
- encode: encodeURIComponent
47
- });
48
- return fn(params);
49
- };
50
- var regCharsDetector = /[^a-zA-Z\-_0-9\/\.]/;
51
- var RouteMatcher = /*#__PURE__*/ function() {
52
- "use strict";
53
- function RouteMatcher(spec) {
54
- _classCallCheck(this, RouteMatcher);
55
- _defineProperty(this, "spec", void 0);
56
- _defineProperty(this, "urlPath", "");
57
- _defineProperty(this, "urlMatcher", void 0);
58
- _defineProperty(this, "urlReg", void 0);
59
- this.spec = spec;
60
- this.setupUrlPath();
61
- }
62
- _createClass(RouteMatcher, [
63
- {
64
- key: "generate",
65
- value: function generate(url) {
66
- var route = new ModernRoute(this.spec);
67
- if (this.urlPath) {
68
- var params = this.parseURLParams(url);
69
- route.urlPath = toPath(route.urlPath, params);
70
- route.params = params;
71
- }
72
- return route;
73
- }
74
- },
75
- {
76
- key: "parseURLParams",
77
- value: function parseURLParams(pathname) {
78
- if (!this.urlMatcher) {
79
- return {};
80
- } else {
81
- var matchResult = this.urlMatcher(pathname);
82
- return matchResult.params;
83
- }
84
- }
85
- },
86
- {
87
- key: "matchLength",
88
- value: function matchLength(pathname) {
89
- if (!this.urlReg) {
90
- return this.urlPath.length;
91
- } else {
92
- var _result_;
93
- var result = this.urlReg.exec(pathname);
94
- return (result === null || result === void 0 ? void 0 : (_result_ = result[0]) === null || _result_ === void 0 ? void 0 : _result_.length) || null;
95
- }
96
- }
97
- },
98
- {
99
- key: "matchUrlPath",
100
- value: function matchUrlPath(requestUrl) {
101
- var urlWithoutSlash = requestUrl.endsWith("/") && requestUrl !== "/" ? requestUrl.slice(0, -1) : requestUrl;
102
- urlWithoutSlash = removeHtmlSuffix(urlWithoutSlash);
103
- if (this.urlMatcher) {
104
- return Boolean(this.urlMatcher(urlWithoutSlash));
105
- } else {
106
- var urlPath = removeHtmlSuffix(this.urlPath);
107
- if (urlWithoutSlash.startsWith(urlPath)) {
108
- if (urlPath !== "/" && urlWithoutSlash.length > urlPath.length && !urlWithoutSlash.startsWith("".concat(urlPath, "/"))) {
109
- return false;
110
- }
111
- return true;
112
- }
113
- return false;
114
- }
115
- }
116
- },
117
- {
118
- key: "matchEntry",
119
- value: function matchEntry(entryName) {
120
- return this.spec.entryName === entryName;
121
- }
122
- },
123
- {
124
- key: "setupUrlPath",
125
- value: function setupUrlPath() {
126
- var urlPath = this.spec.urlPath;
127
- this.urlPath = urlPath === "/" ? urlPath : removeTailSlash(urlPath);
128
- var useReg = regCharsDetector.test(urlPath);
129
- if (useReg) {
130
- this.urlMatcher = match(urlPath, {
131
- end: false,
132
- decode: decodeURIComponent
133
- });
134
- this.urlReg = pathToRegexp(urlPath, [], {
135
- end: false
136
- });
137
- }
138
- }
139
- }
140
- ]);
141
- return RouteMatcher;
142
- }();
143
- export { RouteMatcher };
@@ -1,40 +0,0 @@
1
- function _classCallCheck(instance, Constructor) {
2
- if (!(instance instanceof Constructor)) {
3
- throw new TypeError("Cannot call a class as a function");
4
- }
5
- }
6
- function _defineProperty(obj, key, value) {
7
- if (key in obj) {
8
- Object.defineProperty(obj, key, {
9
- value: value,
10
- enumerable: true,
11
- configurable: true,
12
- writable: true
13
- });
14
- } else {
15
- obj[key] = value;
16
- }
17
- return obj;
18
- }
19
- var ModernRoute = function ModernRoute(routeSpec) {
20
- "use strict";
21
- _classCallCheck(this, ModernRoute);
22
- _defineProperty(this, "entryName", void 0);
23
- _defineProperty(this, "urlPath", void 0);
24
- _defineProperty(this, "entryPath", void 0);
25
- _defineProperty(this, "bundle", void 0);
26
- _defineProperty(this, "isApi", void 0);
27
- _defineProperty(this, "isSSR", void 0);
28
- _defineProperty(this, "isSPA", void 0);
29
- _defineProperty(this, "params", {});
30
- _defineProperty(this, "responseHeaders", void 0);
31
- this.entryName = routeSpec.entryName || "";
32
- this.urlPath = routeSpec.urlPath;
33
- this.entryPath = routeSpec.entryPath || "";
34
- this.isSSR = routeSpec.isSSR || false;
35
- this.isSPA = routeSpec.isSPA || false;
36
- this.isApi = routeSpec.isApi || false;
37
- this.bundle = routeSpec.bundle || "";
38
- this.responseHeaders = routeSpec.responseHeaders;
39
- };
40
- export { ModernRoute };