@modern-js/prod-server 2.14.0 → 2.16.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 (122) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/dist/cjs/constants.js +15 -31
  3. package/dist/cjs/index.js +35 -37
  4. package/dist/cjs/libs/context/context.js +53 -66
  5. package/dist/cjs/libs/context/index.js +15 -28
  6. package/dist/cjs/libs/hook-api/index.js +59 -54
  7. package/dist/cjs/libs/hook-api/route.js +28 -30
  8. package/dist/cjs/libs/hook-api/template.js +30 -34
  9. package/dist/cjs/libs/loadConfig.js +74 -65
  10. package/dist/cjs/libs/logger.js +46 -37
  11. package/dist/cjs/libs/metrics.js +7 -25
  12. package/dist/cjs/libs/proxy.js +29 -46
  13. package/dist/cjs/libs/render/cache/__tests__/cache.fun.test.js +48 -64
  14. package/dist/cjs/libs/render/cache/__tests__/cache.test.js +53 -37
  15. package/dist/cjs/libs/render/cache/__tests__/cacheable.js +38 -34
  16. package/dist/cjs/libs/render/cache/__tests__/error-configuration.js +22 -30
  17. package/dist/cjs/libs/render/cache/__tests__/matched-cache.js +86 -46
  18. package/dist/cjs/libs/render/cache/index.js +17 -37
  19. package/dist/cjs/libs/render/cache/page-caches/index.js +12 -28
  20. package/dist/cjs/libs/render/cache/page-caches/lru.js +32 -40
  21. package/dist/cjs/libs/render/cache/spr.js +104 -111
  22. package/dist/cjs/libs/render/cache/type.js +4 -15
  23. package/dist/cjs/libs/render/cache/util.js +29 -53
  24. package/dist/cjs/libs/render/index.js +75 -73
  25. package/dist/cjs/libs/render/measure.js +19 -34
  26. package/dist/cjs/libs/render/reader.js +52 -61
  27. package/dist/cjs/libs/render/ssr.js +34 -66
  28. package/dist/cjs/libs/render/static.js +22 -45
  29. package/dist/cjs/libs/render/type.js +10 -28
  30. package/dist/cjs/libs/render/utils.js +17 -38
  31. package/dist/cjs/libs/route/index.js +32 -31
  32. package/dist/cjs/libs/route/matcher.js +38 -38
  33. package/dist/cjs/libs/route/route.js +29 -26
  34. package/dist/cjs/libs/serveFile.js +23 -41
  35. package/dist/cjs/server/index.js +101 -107
  36. package/dist/cjs/server/modernServer.js +191 -171
  37. package/dist/cjs/server/modernServerSplit.js +12 -30
  38. package/dist/cjs/type.js +4 -15
  39. package/dist/cjs/utils.js +50 -50
  40. package/dist/cjs/workerServer.js +26 -36
  41. package/dist/esm/constants.js +24 -25
  42. package/dist/esm/index.js +11 -10
  43. package/dist/esm/libs/context/context.js +271 -264
  44. package/dist/esm/libs/context/index.js +3 -3
  45. package/dist/esm/libs/hook-api/index.js +237 -223
  46. package/dist/esm/libs/hook-api/route.js +62 -60
  47. package/dist/esm/libs/hook-api/template.js +117 -115
  48. package/dist/esm/libs/loadConfig.js +68 -69
  49. package/dist/esm/libs/logger.js +188 -174
  50. package/dist/esm/libs/metrics.js +6 -3
  51. package/dist/esm/libs/proxy.js +236 -221
  52. package/dist/esm/libs/render/cache/__tests__/cache.fun.test.js +286 -267
  53. package/dist/esm/libs/render/cache/__tests__/cache.test.js +765 -745
  54. package/dist/esm/libs/render/cache/__tests__/cacheable.js +62 -63
  55. package/dist/esm/libs/render/cache/__tests__/error-configuration.js +42 -43
  56. package/dist/esm/libs/render/cache/__tests__/matched-cache.js +134 -135
  57. package/dist/esm/libs/render/cache/index.js +337 -326
  58. package/dist/esm/libs/render/cache/page-caches/index.js +147 -141
  59. package/dist/esm/libs/render/cache/page-caches/lru.js +78 -76
  60. package/dist/esm/libs/render/cache/spr.js +465 -456
  61. package/dist/esm/libs/render/cache/type.js +1 -1
  62. package/dist/esm/libs/render/cache/util.js +266 -246
  63. package/dist/esm/libs/render/index.js +226 -218
  64. package/dist/esm/libs/render/measure.js +136 -128
  65. package/dist/esm/libs/render/reader.js +315 -304
  66. package/dist/esm/libs/render/ssr.js +214 -209
  67. package/dist/esm/libs/render/static.js +208 -198
  68. package/dist/esm/libs/render/type.js +6 -7
  69. package/dist/esm/libs/render/utils.js +8 -9
  70. package/dist/esm/libs/route/index.js +134 -123
  71. package/dist/esm/libs/route/matcher.js +140 -130
  72. package/dist/esm/libs/route/route.js +36 -37
  73. package/dist/esm/libs/serveFile.js +177 -168
  74. package/dist/esm/server/index.js +578 -549
  75. package/dist/esm/server/modernServer.js +1137 -1074
  76. package/dist/esm/server/modernServerSplit.js +344 -328
  77. package/dist/esm/type.js +1 -1
  78. package/dist/esm/utils.js +133 -124
  79. package/dist/esm/workerServer.js +226 -220
  80. package/dist/esm-node/constants.js +7 -14
  81. package/dist/esm-node/index.js +4 -9
  82. package/dist/esm-node/libs/context/context.js +32 -25
  83. package/dist/esm-node/libs/context/index.js +2 -5
  84. package/dist/esm-node/libs/hook-api/index.js +40 -21
  85. package/dist/esm-node/libs/hook-api/route.js +21 -8
  86. package/dist/esm-node/libs/hook-api/template.js +19 -14
  87. package/dist/esm-node/libs/loadConfig.js +11 -28
  88. package/dist/esm-node/libs/logger.js +37 -17
  89. package/dist/esm-node/libs/metrics.js +1 -3
  90. package/dist/esm-node/libs/proxy.js +14 -22
  91. package/dist/esm-node/libs/render/cache/__tests__/cache.fun.test.js +25 -36
  92. package/dist/esm-node/libs/render/cache/__tests__/cache.test.js +23 -11
  93. package/dist/esm-node/libs/render/cache/__tests__/cacheable.js +32 -13
  94. package/dist/esm-node/libs/render/cache/__tests__/error-configuration.js +16 -9
  95. package/dist/esm-node/libs/render/cache/__tests__/matched-cache.js +80 -25
  96. package/dist/esm-node/libs/render/cache/index.js +3 -10
  97. package/dist/esm-node/libs/render/cache/page-caches/index.js +4 -5
  98. package/dist/esm-node/libs/render/cache/page-caches/lru.js +20 -8
  99. package/dist/esm-node/libs/render/cache/spr.js +79 -80
  100. package/dist/esm-node/libs/render/cache/type.js +1 -0
  101. package/dist/esm-node/libs/render/cache/util.js +13 -23
  102. package/dist/esm-node/libs/render/index.js +10 -28
  103. package/dist/esm-node/libs/render/measure.js +7 -13
  104. package/dist/esm-node/libs/render/reader.js +31 -26
  105. package/dist/esm-node/libs/render/ssr.js +5 -21
  106. package/dist/esm-node/libs/render/static.js +1 -4
  107. package/dist/esm-node/libs/render/type.js +3 -6
  108. package/dist/esm-node/libs/render/utils.js +6 -18
  109. package/dist/esm-node/libs/route/index.js +20 -9
  110. package/dist/esm-node/libs/route/matcher.js +28 -17
  111. package/dist/esm-node/libs/route/route.js +23 -5
  112. package/dist/esm-node/libs/serveFile.js +2 -6
  113. package/dist/esm-node/server/index.js +72 -75
  114. package/dist/esm-node/server/modernServer.js +102 -130
  115. package/dist/esm-node/server/modernServerSplit.js +1 -4
  116. package/dist/esm-node/type.js +1 -0
  117. package/dist/esm-node/utils.js +41 -32
  118. package/dist/esm-node/workerServer.js +9 -10
  119. package/dist/types/libs/context/context.d.ts +1 -1
  120. package/dist/types/server/modernServer.d.ts +1 -1
  121. package/dist/types/utils.d.ts +1 -1
  122. package/package.json +12 -8
@@ -1,134 +1,145 @@
1
- function _classCallCheck(instance, Constructor) {
2
- if (!(instance instanceof Constructor)) {
3
- throw new TypeError("Cannot call a class as a function");
4
- }
1
+ function _class_call_check(instance, Constructor) {
2
+ if (!(instance instanceof Constructor)) {
3
+ throw new TypeError("Cannot call a class as a function");
4
+ }
5
5
  }
6
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
- }
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)
12
+ descriptor.writable = true;
13
+ Object.defineProperty(target, descriptor.key, descriptor);
14
+ }
14
15
  }
15
- function _createClass(Constructor, protoProps, staticProps) {
16
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
17
- if (staticProps) _defineProperties(Constructor, staticProps);
18
- return Constructor;
16
+ function _create_class(Constructor, protoProps, staticProps) {
17
+ if (protoProps)
18
+ _defineProperties(Constructor.prototype, protoProps);
19
+ if (staticProps)
20
+ _defineProperties(Constructor, staticProps);
21
+ return Constructor;
19
22
  }
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;
23
+ function _define_property(obj, key, value) {
24
+ if (key in obj) {
25
+ Object.defineProperty(obj, key, {
26
+ value,
27
+ enumerable: true,
28
+ configurable: true,
29
+ writable: true
30
+ });
31
+ } else {
32
+ obj[key] = value;
33
+ }
34
+ return obj;
32
35
  }
33
36
  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
- // get all routes matches pathname
45
- key: "filter",
46
- value: function filter(pathname) {
47
- return this.matchers.reduce(function(matches, matcher) {
48
- if (matcher.matchUrlPath(pathname)) {
49
- matches.push(matcher);
50
- }
51
- return matches;
52
- }, []);
53
- }
54
- },
55
- {
56
- // get best match from a set of matches
57
- key: "best",
58
- value: function best(pathname, matches) {
59
- var best;
60
- var matchedLen = 0;
61
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
62
- try {
63
- for(var _iterator = matches[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
64
- var match = _step.value;
65
- var len = match.matchLength(pathname);
66
- if (len === null) {
67
- continue;
68
- }
69
- if (len > matchedLen) {
70
- best = match;
71
- matchedLen = len;
72
- }
73
- }
74
- } catch (err) {
75
- _didIteratorError = true;
76
- _iteratorError = err;
77
- } finally{
78
- try {
79
- if (!_iteratorNormalCompletion && _iterator.return != null) {
80
- _iterator.return();
81
- }
82
- } finally{
83
- if (_didIteratorError) {
84
- throw _iteratorError;
85
- }
86
- }
87
- }
88
- return best;
89
- }
90
- },
91
- {
92
- // reset routes matcher
93
- key: "reset",
94
- value: function reset(specs) {
95
- this.specs = specs;
96
- var matchers = specs.reduce(function(ms, spec) {
97
- ms.push(new RouteMatcher(spec));
98
- return ms;
99
- }, []);
100
- this.matchers = matchers;
37
+ export var RouteMatchManager = /* @__PURE__ */ function() {
38
+ "use strict";
39
+ function RouteMatchManager2() {
40
+ _class_call_check(this, RouteMatchManager2);
41
+ _define_property(this, "matchers", void 0);
42
+ _define_property(this, "specs", []);
43
+ this.matchers = [];
44
+ }
45
+ _create_class(RouteMatchManager2, [
46
+ {
47
+ key: "filter",
48
+ value: (
49
+ // get all routes matches pathname
50
+ function filter(pathname) {
51
+ return this.matchers.reduce(function(matches, matcher) {
52
+ if (matcher.matchUrlPath(pathname)) {
53
+ matches.push(matcher);
101
54
  }
102
- },
103
- {
104
- // get best match from all matcher in manager
105
- key: "match",
106
- value: function match(pathname) {
107
- var matches = this.filter(pathname);
108
- var best = this.best(pathname, matches);
109
- return best;
110
- }
111
- },
112
- {
113
- key: "matchEntry",
114
- value: function matchEntry(entryname) {
115
- return this.matchers.find(function(matcher) {
116
- return matcher.matchEntry(entryname);
117
- });
55
+ return matches;
56
+ }, []);
57
+ }
58
+ )
59
+ },
60
+ {
61
+ key: "best",
62
+ value: (
63
+ // get best match from a set of matches
64
+ function best(pathname, matches) {
65
+ var best2;
66
+ var matchedLen = 0;
67
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
68
+ try {
69
+ for (var _iterator = matches[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
70
+ var match = _step.value;
71
+ var len = match.matchLength(pathname);
72
+ if (len === null) {
73
+ continue;
74
+ }
75
+ if (len > matchedLen) {
76
+ best2 = match;
77
+ matchedLen = len;
78
+ }
118
79
  }
119
- },
120
- {
121
- key: "getBundles",
122
- value: function getBundles() {
123
- var bundles = this.specs.filter(function(route) {
124
- return route.isSSR;
125
- }).map(function(route) {
126
- return route.bundle;
127
- });
128
- return bundles;
80
+ } catch (err) {
81
+ _didIteratorError = true;
82
+ _iteratorError = err;
83
+ } finally {
84
+ try {
85
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
86
+ _iterator.return();
87
+ }
88
+ } finally {
89
+ if (_didIteratorError) {
90
+ throw _iteratorError;
91
+ }
129
92
  }
93
+ }
94
+ return best2;
95
+ }
96
+ )
97
+ },
98
+ {
99
+ key: "reset",
100
+ value: (
101
+ // reset routes matcher
102
+ function reset(specs) {
103
+ this.specs = specs;
104
+ var matchers = specs.reduce(function(ms, spec) {
105
+ ms.push(new RouteMatcher(spec));
106
+ return ms;
107
+ }, []);
108
+ this.matchers = matchers;
109
+ }
110
+ )
111
+ },
112
+ {
113
+ key: "match",
114
+ value: (
115
+ // get best match from all matcher in manager
116
+ function match(pathname) {
117
+ var matches = this.filter(pathname);
118
+ var best = this.best(pathname, matches);
119
+ return best;
130
120
  }
131
- ]);
132
- return RouteMatchManager;
121
+ )
122
+ },
123
+ {
124
+ key: "matchEntry",
125
+ value: function matchEntry(entryname) {
126
+ return this.matchers.find(function(matcher) {
127
+ return matcher.matchEntry(entryname);
128
+ });
129
+ }
130
+ },
131
+ {
132
+ key: "getBundles",
133
+ value: function getBundles() {
134
+ var bundles = this.specs.filter(function(route) {
135
+ return route.isSSR;
136
+ }).map(function(route) {
137
+ return route.bundle;
138
+ });
139
+ return bundles;
140
+ }
141
+ }
142
+ ]);
143
+ return RouteMatchManager2;
133
144
  }();
134
- export { RouteMatchManager, RouteMatcher };
145
+ export { RouteMatcher };
@@ -1,147 +1,157 @@
1
- function _classCallCheck(instance, Constructor) {
2
- if (!(instance instanceof Constructor)) {
3
- throw new TypeError("Cannot call a class as a function");
4
- }
1
+ function _class_call_check(instance, Constructor) {
2
+ if (!(instance instanceof Constructor)) {
3
+ throw new TypeError("Cannot call a class as a function");
4
+ }
5
5
  }
6
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
- }
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)
12
+ descriptor.writable = true;
13
+ Object.defineProperty(target, descriptor.key, descriptor);
14
+ }
14
15
  }
15
- function _createClass(Constructor, protoProps, staticProps) {
16
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
17
- if (staticProps) _defineProperties(Constructor, staticProps);
18
- return Constructor;
16
+ function _create_class(Constructor, protoProps, staticProps) {
17
+ if (protoProps)
18
+ _defineProperties(Constructor.prototype, protoProps);
19
+ if (staticProps)
20
+ _defineProperties(Constructor, staticProps);
21
+ return Constructor;
19
22
  }
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;
23
+ function _define_property(obj, key, value) {
24
+ if (key in obj) {
25
+ Object.defineProperty(obj, key, {
26
+ value,
27
+ enumerable: true,
28
+ configurable: true,
29
+ writable: true
30
+ });
31
+ } else {
32
+ obj[key] = value;
33
+ }
34
+ return obj;
32
35
  }
33
36
  import { match, pathToRegexp, compile } from "path-to-regexp";
34
37
  import { ModernRoute } from "./route";
35
38
  var removeTailSlash = function(s) {
36
- return s.replace(/\/+$/, "");
39
+ return s.replace(/\/+$/, "");
37
40
  };
38
41
  var removeHtmlSuffix = function(url) {
39
- if (url.endsWith(".html")) {
40
- return url.slice(0, -5);
41
- }
42
- return url;
42
+ if (url.endsWith(".html")) {
43
+ return url.slice(0, -5);
44
+ }
45
+ return url;
43
46
  };
44
47
  var toPath = function(reg, params) {
45
- var fn = compile(reg, {
46
- encode: encodeURIComponent
47
- });
48
- return fn(params);
48
+ var fn = compile(reg, {
49
+ encode: encodeURIComponent
50
+ });
51
+ return fn(params);
49
52
  };
50
53
  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
- // generate modern route object
65
- key: "generate",
66
- value: function generate(url) {
67
- var route = new ModernRoute(this.spec);
68
- if (this.urlPath) {
69
- var params = this.parseURLParams(url);
70
- route.urlPath = toPath(route.urlPath, params);
71
- route.params = params;
72
- }
73
- return route;
74
- }
75
- },
76
- {
77
- key: "parseURLParams",
78
- value: function parseURLParams(pathname) {
79
- if (!this.urlMatcher) {
80
- return {};
81
- } else {
82
- var matchResult = this.urlMatcher(pathname);
83
- return matchResult.params;
84
- }
85
- }
86
- },
87
- {
88
- // get match url length
89
- key: "matchLength",
90
- value: function matchLength(pathname) {
91
- if (!this.urlReg) {
92
- return this.urlPath.length;
93
- } else {
94
- var _result_;
95
- var result = this.urlReg.exec(pathname);
96
- return (result === null || result === void 0 ? void 0 : (_result_ = result[0]) === null || _result_ === void 0 ? void 0 : _result_.length) || null;
97
- }
98
- }
99
- },
100
- {
101
- // if match url path
102
- key: "matchUrlPath",
103
- value: function matchUrlPath(requestUrl) {
104
- var urlWithoutSlash = requestUrl.endsWith("/") && requestUrl !== "/" ? requestUrl.slice(0, -1) : requestUrl;
105
- urlWithoutSlash = removeHtmlSuffix(urlWithoutSlash);
106
- if (this.urlMatcher) {
107
- return Boolean(this.urlMatcher(urlWithoutSlash));
108
- } else {
109
- var urlPath = removeHtmlSuffix(this.urlPath);
110
- if (urlWithoutSlash.startsWith(urlPath)) {
111
- if (urlPath !== "/" && urlWithoutSlash.length > urlPath.length && !urlWithoutSlash.startsWith("".concat(urlPath, "/"))) {
112
- return false;
113
- }
114
- return true;
115
- }
116
- return false;
117
- }
118
- }
119
- },
120
- {
121
- key: "matchEntry",
122
- value: function matchEntry(entryName) {
123
- return this.spec.entryName === entryName;
124
- }
125
- },
126
- {
127
- // compiler urlPath to regexp if necessary
128
- key: "setupUrlPath",
129
- value: function setupUrlPath() {
130
- var urlPath = this.spec.urlPath;
131
- this.urlPath = urlPath === "/" ? urlPath : removeTailSlash(urlPath);
132
- var useReg = regCharsDetector.test(urlPath);
133
- if (useReg) {
134
- this.urlMatcher = match(urlPath, {
135
- end: false,
136
- decode: decodeURIComponent
137
- });
138
- this.urlReg = pathToRegexp(urlPath, [], {
139
- end: false
140
- });
141
- }
54
+ export var RouteMatcher = /* @__PURE__ */ function() {
55
+ "use strict";
56
+ function RouteMatcher2(spec) {
57
+ _class_call_check(this, RouteMatcher2);
58
+ _define_property(this, "spec", void 0);
59
+ _define_property(this, "urlPath", "");
60
+ _define_property(this, "urlMatcher", void 0);
61
+ _define_property(this, "urlReg", void 0);
62
+ this.spec = spec;
63
+ this.setupUrlPath();
64
+ }
65
+ _create_class(RouteMatcher2, [
66
+ {
67
+ key: "generate",
68
+ value: (
69
+ // generate modern route object
70
+ function generate(url) {
71
+ var route = new ModernRoute(this.spec);
72
+ if (this.urlPath) {
73
+ var params = this.parseURLParams(url);
74
+ route.urlPath = toPath(route.urlPath, params);
75
+ route.params = params;
76
+ }
77
+ return route;
78
+ }
79
+ )
80
+ },
81
+ {
82
+ key: "parseURLParams",
83
+ value: function parseURLParams(pathname) {
84
+ if (!this.urlMatcher) {
85
+ return {};
86
+ } else {
87
+ var matchResult = this.urlMatcher(pathname);
88
+ return matchResult.params;
89
+ }
90
+ }
91
+ },
92
+ {
93
+ key: "matchLength",
94
+ value: (
95
+ // get match url length
96
+ function matchLength(pathname) {
97
+ if (!this.urlReg) {
98
+ return this.urlPath.length;
99
+ } else {
100
+ var _result_;
101
+ var result = this.urlReg.exec(pathname);
102
+ return (result === null || result === void 0 ? void 0 : (_result_ = result[0]) === null || _result_ === void 0 ? void 0 : _result_.length) || null;
103
+ }
104
+ }
105
+ )
106
+ },
107
+ {
108
+ key: "matchUrlPath",
109
+ value: (
110
+ // if match url path
111
+ function matchUrlPath(requestUrl) {
112
+ var urlWithoutSlash = requestUrl.endsWith("/") && requestUrl !== "/" ? requestUrl.slice(0, -1) : requestUrl;
113
+ urlWithoutSlash = removeHtmlSuffix(urlWithoutSlash);
114
+ if (this.urlMatcher) {
115
+ return Boolean(this.urlMatcher(urlWithoutSlash));
116
+ } else {
117
+ var urlPath = removeHtmlSuffix(this.urlPath);
118
+ if (urlWithoutSlash.startsWith(urlPath)) {
119
+ if (urlPath !== "/" && urlWithoutSlash.length > urlPath.length && !urlWithoutSlash.startsWith("".concat(urlPath, "/"))) {
120
+ return false;
121
+ }
122
+ return true;
142
123
  }
124
+ return false;
125
+ }
143
126
  }
144
- ]);
145
- return RouteMatcher;
127
+ )
128
+ },
129
+ {
130
+ key: "matchEntry",
131
+ value: function matchEntry(entryName) {
132
+ return this.spec.entryName === entryName;
133
+ }
134
+ },
135
+ {
136
+ key: "setupUrlPath",
137
+ value: (
138
+ // compiler urlPath to regexp if necessary
139
+ function setupUrlPath() {
140
+ var urlPath = this.spec.urlPath;
141
+ this.urlPath = urlPath === "/" ? urlPath : removeTailSlash(urlPath);
142
+ var useReg = regCharsDetector.test(urlPath);
143
+ if (useReg) {
144
+ this.urlMatcher = match(urlPath, {
145
+ end: false,
146
+ decode: decodeURIComponent
147
+ });
148
+ this.urlReg = pathToRegexp(urlPath, [], {
149
+ end: false
150
+ });
151
+ }
152
+ }
153
+ )
154
+ }
155
+ ]);
156
+ return RouteMatcher2;
146
157
  }();
147
- export { RouteMatcher };
@@ -1,40 +1,39 @@
1
- function _classCallCheck(instance, Constructor) {
2
- if (!(instance instanceof Constructor)) {
3
- throw new TypeError("Cannot call a class as a function");
4
- }
1
+ function _class_call_check(instance, Constructor) {
2
+ if (!(instance instanceof Constructor)) {
3
+ throw new TypeError("Cannot call a class as a function");
4
+ }
5
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;
6
+ function _define_property(obj, key, value) {
7
+ if (key in obj) {
8
+ Object.defineProperty(obj, key, {
9
+ value,
10
+ enumerable: true,
11
+ configurable: true,
12
+ writable: true
13
+ });
14
+ } else {
15
+ obj[key] = value;
16
+ }
17
+ return obj;
18
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;
19
+ export var ModernRoute = function ModernRoute2(routeSpec) {
20
+ "use strict";
21
+ _class_call_check(this, ModernRoute2);
22
+ _define_property(this, "entryName", void 0);
23
+ _define_property(this, "urlPath", void 0);
24
+ _define_property(this, "entryPath", void 0);
25
+ _define_property(this, "bundle", void 0);
26
+ _define_property(this, "isApi", void 0);
27
+ _define_property(this, "isSSR", void 0);
28
+ _define_property(this, "isSPA", void 0);
29
+ _define_property(this, "params", {});
30
+ _define_property(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
39
  };
40
- export { ModernRoute };