@modern-js/prod-server 2.0.0-beta.3 → 2.0.0-beta.4
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.
- package/CHANGELOG.md +69 -0
- package/dist/js/modern/constants.js +32 -25
- package/dist/js/modern/index.js +11 -6
- package/dist/js/modern/libs/context/context.js +52 -84
- package/dist/js/modern/libs/context/index.js +5 -2
- package/dist/js/modern/libs/hook-api/index.js +42 -35
- package/dist/js/modern/libs/hook-api/route.js +6 -7
- package/dist/js/modern/libs/hook-api/template.js +20 -34
- package/dist/js/modern/libs/loadConfig.js +45 -24
- package/dist/js/modern/libs/metrics.js +3 -4
- package/dist/js/modern/libs/proxy.js +68 -37
- package/dist/js/modern/libs/render/cache/__tests__/cache.fun.test.js +112 -67
- package/dist/js/modern/libs/render/cache/__tests__/cache.test.js +246 -216
- package/dist/js/modern/libs/render/cache/__tests__/cacheable.js +43 -49
- package/dist/js/modern/libs/render/cache/__tests__/error-configuration.js +36 -34
- package/dist/js/modern/libs/render/cache/__tests__/matched-cache.js +83 -113
- package/dist/js/modern/libs/render/cache/index.js +88 -54
- package/dist/js/modern/libs/render/cache/page-caches/index.js +31 -8
- package/dist/js/modern/libs/render/cache/page-caches/lru.js +6 -6
- package/dist/js/modern/libs/render/cache/spr.js +133 -117
- package/dist/js/modern/libs/render/cache/type.js +0 -1
- package/dist/js/modern/libs/render/cache/util.js +71 -39
- package/dist/js/modern/libs/render/index.js +76 -56
- package/dist/js/modern/libs/render/measure.js +38 -27
- package/dist/js/modern/libs/render/reader.js +65 -62
- package/dist/js/modern/libs/render/ssr.js +50 -32
- package/dist/js/modern/libs/render/static.js +50 -33
- package/dist/js/modern/libs/render/type.js +9 -6
- package/dist/js/modern/libs/route/index.js +8 -15
- package/dist/js/modern/libs/route/matcher.js +20 -34
- package/dist/js/modern/libs/route/route.js +9 -18
- package/dist/js/modern/libs/serve-file.js +33 -20
- package/dist/js/modern/server/index.js +144 -145
- package/dist/js/modern/server/modern-server-split.js +46 -12
- package/dist/js/modern/server/modern-server.js +377 -417
- package/dist/js/modern/type.js +0 -1
- package/dist/js/modern/utils.js +62 -43
- package/dist/js/modern/worker-server.js +34 -14
- package/dist/js/node/constants.js +45 -30
- package/dist/js/node/index.js +31 -57
- package/dist/js/node/libs/context/context.js +79 -94
- package/dist/js/node/libs/context/index.js +23 -13
- package/dist/js/node/libs/hook-api/index.js +69 -48
- package/dist/js/node/libs/hook-api/route.js +22 -11
- package/dist/js/node/libs/hook-api/template.js +36 -39
- package/dist/js/node/libs/loadConfig.js +69 -35
- package/dist/js/node/libs/metrics.js +21 -9
- package/dist/js/node/libs/proxy.js +86 -44
- package/dist/js/node/libs/render/cache/__tests__/cache.fun.test.js +132 -70
- package/dist/js/node/libs/render/cache/__tests__/cache.test.js +268 -218
- package/dist/js/node/libs/render/cache/__tests__/cacheable.js +61 -55
- package/dist/js/node/libs/render/cache/__tests__/error-configuration.js +54 -40
- package/dist/js/node/libs/render/cache/__tests__/matched-cache.js +101 -119
- package/dist/js/node/libs/render/cache/index.js +110 -64
- package/dist/js/node/libs/render/cache/page-caches/index.js +50 -14
- package/dist/js/node/libs/render/cache/page-caches/lru.js +29 -12
- package/dist/js/node/libs/render/cache/spr.js +156 -129
- package/dist/js/node/libs/render/cache/type.js +0 -5
- package/dist/js/node/libs/render/cache/util.js +88 -45
- package/dist/js/node/libs/render/index.js +102 -67
- package/dist/js/node/libs/render/measure.js +55 -31
- package/dist/js/node/libs/render/reader.js +87 -70
- package/dist/js/node/libs/render/ssr.js +76 -47
- package/dist/js/node/libs/render/static.js +75 -40
- package/dist/js/node/libs/render/type.js +27 -12
- package/dist/js/node/libs/route/index.js +26 -26
- package/dist/js/node/libs/route/matcher.js +36 -41
- package/dist/js/node/libs/route/route.js +25 -22
- package/dist/js/node/libs/serve-file.js +61 -32
- package/dist/js/node/server/index.js +160 -160
- package/dist/js/node/server/modern-server-split.js +68 -22
- package/dist/js/node/server/modern-server.js +395 -441
- package/dist/js/node/type.js +0 -3
- package/dist/js/node/utils.js +74 -52
- package/dist/js/node/worker-server.js +53 -21
- package/dist/js/treeshaking/constants.js +26 -25
- package/dist/js/treeshaking/index.js +10 -10
- package/dist/js/treeshaking/libs/context/context.js +268 -237
- package/dist/js/treeshaking/libs/context/index.js +3 -3
- package/dist/js/treeshaking/libs/hook-api/index.js +265 -143
- package/dist/js/treeshaking/libs/hook-api/route.js +65 -30
- package/dist/js/treeshaking/libs/hook-api/template.js +121 -85
- package/dist/js/treeshaking/libs/loadConfig.js +80 -37
- package/dist/js/treeshaking/libs/metrics.js +4 -10
- package/dist/js/treeshaking/libs/proxy.js +240 -76
- package/dist/js/treeshaking/libs/render/cache/__tests__/cache.fun.test.js +288 -121
- package/dist/js/treeshaking/libs/render/cache/__tests__/cache.test.js +772 -455
- package/dist/js/treeshaking/libs/render/cache/__tests__/cacheable.js +65 -51
- package/dist/js/treeshaking/libs/render/cache/__tests__/error-configuration.js +45 -35
- package/dist/js/treeshaking/libs/render/cache/__tests__/matched-cache.js +144 -118
- package/dist/js/treeshaking/libs/render/cache/index.js +337 -175
- package/dist/js/treeshaking/libs/render/cache/page-caches/index.js +151 -27
- package/dist/js/treeshaking/libs/render/cache/page-caches/lru.js +80 -42
- package/dist/js/treeshaking/libs/render/cache/spr.js +470 -340
- package/dist/js/treeshaking/libs/render/cache/type.js +1 -1
- package/dist/js/treeshaking/libs/render/cache/util.js +271 -92
- package/dist/js/treeshaking/libs/render/index.js +228 -95
- package/dist/js/treeshaking/libs/render/measure.js +142 -57
- package/dist/js/treeshaking/libs/render/reader.js +325 -177
- package/dist/js/treeshaking/libs/render/ssr.js +220 -95
- package/dist/js/treeshaking/libs/render/static.js +210 -78
- package/dist/js/treeshaking/libs/render/type.js +7 -6
- package/dist/js/treeshaking/libs/route/index.js +125 -89
- package/dist/js/treeshaking/libs/route/matcher.js +132 -107
- package/dist/js/treeshaking/libs/route/route.js +40 -26
- package/dist/js/treeshaking/libs/serve-file.js +177 -68
- package/dist/js/treeshaking/server/index.js +468 -327
- package/dist/js/treeshaking/server/modern-server-split.js +352 -144
- package/dist/js/treeshaking/server/modern-server.js +1046 -909
- package/dist/js/treeshaking/type.js +1 -1
- package/dist/js/treeshaking/utils.js +138 -81
- package/dist/js/treeshaking/worker-server.js +176 -55
- package/dist/types/index.d.ts +2 -0
- package/dist/types/libs/context/context.d.ts +4 -1
- package/dist/types/libs/loadConfig.d.ts +1 -0
- package/dist/types/libs/render/cache/index.d.ts +2 -0
- package/dist/types/libs/render/cache/spr.d.ts +2 -0
- package/dist/types/libs/route/route.d.ts +0 -1
- package/dist/types/server/index.d.ts +3 -0
- package/dist/types/utils.d.ts +1 -1
- package/dist/types/worker-server.d.ts +1 -2
- package/package.json +7 -14
- package/dist/js/modern/libs/render/modern/browser-list.js +0 -7
- package/dist/js/modern/libs/render/modern/index.js +0 -37
- package/dist/js/node/libs/render/modern/browser-list.js +0 -14
- package/dist/js/node/libs/render/modern/index.js +0 -46
- package/dist/js/treeshaking/libs/render/modern/browser-list.js +0 -7
- package/dist/js/treeshaking/libs/render/modern/index.js +0 -39
- package/dist/types/libs/render/modern/browser-list.d.ts +0 -1
- package/dist/types/libs/render/modern/index.d.ts +0 -3
|
@@ -1,94 +1,130 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
5
|
-
import { RouteMatcher } from "./matcher";
|
|
6
|
-
export var RouteMatchManager = /*#__PURE__*/function () {
|
|
7
|
-
function RouteMatchManager() {
|
|
8
|
-
_classCallCheck(this, RouteMatchManager);
|
|
9
|
-
_defineProperty(this, "matchers", void 0);
|
|
10
|
-
_defineProperty(this, "specs", []);
|
|
11
|
-
this.matchers = [];
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
// get all routes matches pathname
|
|
15
|
-
_createClass(RouteMatchManager, [{
|
|
16
|
-
key: "filter",
|
|
17
|
-
value: function filter(pathname) {
|
|
18
|
-
return this.matchers.reduce(function (matches, matcher) {
|
|
19
|
-
if (matcher.matchUrlPath(pathname)) {
|
|
20
|
-
matches.push(matcher);
|
|
21
|
-
}
|
|
22
|
-
return matches;
|
|
23
|
-
}, []);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// get best match from a set of matches
|
|
27
|
-
}, {
|
|
28
|
-
key: "best",
|
|
29
|
-
value: function best(pathname, matches) {
|
|
30
|
-
var best;
|
|
31
|
-
var matchedLen = 0;
|
|
32
|
-
var _iterator = _createForOfIteratorHelper(matches),
|
|
33
|
-
_step;
|
|
34
|
-
try {
|
|
35
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
36
|
-
var match = _step.value;
|
|
37
|
-
var len = match.matchLength(pathname);
|
|
38
|
-
if (len === null) {
|
|
39
|
-
continue;
|
|
40
|
-
}
|
|
41
|
-
if (len > matchedLen) {
|
|
42
|
-
best = match;
|
|
43
|
-
matchedLen = len;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
} catch (err) {
|
|
47
|
-
_iterator.e(err);
|
|
48
|
-
} finally {
|
|
49
|
-
_iterator.f();
|
|
50
|
-
}
|
|
51
|
-
return best;
|
|
1
|
+
function _classCallCheck(instance, Constructor) {
|
|
2
|
+
if (!(instance instanceof Constructor)) {
|
|
3
|
+
throw new TypeError("Cannot call a class as a function");
|
|
52
4
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
return ms;
|
|
62
|
-
}, []);
|
|
63
|
-
this.matchers = matchers;
|
|
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);
|
|
64
13
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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;
|
|
73
30
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
var bundles = this.specs.filter(function (route) {
|
|
85
|
-
return route.isSSR;
|
|
86
|
-
}).map(function (route) {
|
|
87
|
-
return route.bundle;
|
|
88
|
-
});
|
|
89
|
-
return bundles;
|
|
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 = [];
|
|
90
41
|
}
|
|
91
|
-
|
|
92
|
-
|
|
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;
|
|
93
129
|
}();
|
|
94
|
-
export { RouteMatcher };
|
|
130
|
+
export { RouteMatchManager, RouteMatcher };
|
|
@@ -1,113 +1,138 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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";
|
|
5
34
|
import { ModernRoute } from "./route";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var removeTailSlash = function removeTailSlash(s) {
|
|
9
|
-
return s.replace(/\/+$/, '');
|
|
35
|
+
var removeTailSlash = function(s) {
|
|
36
|
+
return s.replace(/\/+$/, "");
|
|
10
37
|
};
|
|
11
|
-
var toPath = function
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
38
|
+
var toPath = function(reg, params) {
|
|
39
|
+
var fn = compile(reg, {
|
|
40
|
+
encode: encodeURIComponent
|
|
41
|
+
});
|
|
42
|
+
return fn(params);
|
|
16
43
|
};
|
|
17
|
-
|
|
18
|
-
// eslint-disable-next-line no-useless-escape
|
|
19
44
|
var regCharsDetector = /[^a-zA-Z\-_0-9\/\.]/;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
// generate modern route object
|
|
32
|
-
_createClass(RouteMatcher, [{
|
|
33
|
-
key: "generate",
|
|
34
|
-
value: function generate(url) {
|
|
35
|
-
var route = new ModernRoute(this.spec);
|
|
36
|
-
if (this.urlPath) {
|
|
37
|
-
var params = this.parseURLParams(url);
|
|
38
|
-
route.urlPath = toPath(route.urlPath, params);
|
|
39
|
-
route.params = params;
|
|
40
|
-
}
|
|
41
|
-
return route;
|
|
42
|
-
}
|
|
43
|
-
}, {
|
|
44
|
-
key: "parseURLParams",
|
|
45
|
-
value: function parseURLParams(pathname) {
|
|
46
|
-
if (!this.urlMatcher) {
|
|
47
|
-
return {};
|
|
48
|
-
} else {
|
|
49
|
-
var matchResult = this.urlMatcher(pathname);
|
|
50
|
-
return matchResult.params;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// get match url length
|
|
55
|
-
}, {
|
|
56
|
-
key: "matchLength",
|
|
57
|
-
value: function matchLength(pathname) {
|
|
58
|
-
if (!this.urlReg) {
|
|
59
|
-
return this.urlPath.length;
|
|
60
|
-
} else {
|
|
61
|
-
var _result$;
|
|
62
|
-
var result = this.urlReg.exec(pathname);
|
|
63
|
-
return (result === null || result === void 0 ? void 0 : (_result$ = result[0]) === null || _result$ === void 0 ? void 0 : _result$.length) || null;
|
|
64
|
-
}
|
|
45
|
+
var RouteMatcher = /*#__PURE__*/ function() {
|
|
46
|
+
"use strict";
|
|
47
|
+
function RouteMatcher(spec) {
|
|
48
|
+
_classCallCheck(this, RouteMatcher);
|
|
49
|
+
_defineProperty(this, "spec", void 0);
|
|
50
|
+
_defineProperty(this, "urlPath", "");
|
|
51
|
+
_defineProperty(this, "urlMatcher", void 0);
|
|
52
|
+
_defineProperty(this, "urlReg", void 0);
|
|
53
|
+
this.spec = spec;
|
|
54
|
+
this.setupUrlPath();
|
|
65
55
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
56
|
+
_createClass(RouteMatcher, [
|
|
57
|
+
{
|
|
58
|
+
key: "generate",
|
|
59
|
+
value: function generate(url) {
|
|
60
|
+
var route = new ModernRoute(this.spec);
|
|
61
|
+
if (this.urlPath) {
|
|
62
|
+
var params = this.parseURLParams(url);
|
|
63
|
+
route.urlPath = toPath(route.urlPath, params);
|
|
64
|
+
route.params = params;
|
|
65
|
+
}
|
|
66
|
+
return route;
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
key: "parseURLParams",
|
|
71
|
+
value: function parseURLParams(pathname) {
|
|
72
|
+
if (!this.urlMatcher) {
|
|
73
|
+
return {};
|
|
74
|
+
} else {
|
|
75
|
+
var matchResult = this.urlMatcher(pathname);
|
|
76
|
+
return matchResult.params;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
key: "matchLength",
|
|
82
|
+
value: function matchLength(pathname) {
|
|
83
|
+
if (!this.urlReg) {
|
|
84
|
+
return this.urlPath.length;
|
|
85
|
+
} else {
|
|
86
|
+
var ref;
|
|
87
|
+
var result = this.urlReg.exec(pathname);
|
|
88
|
+
return (result === null || result === void 0 ? void 0 : (ref = result[0]) === null || ref === void 0 ? void 0 : ref.length) || null;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
key: "matchUrlPath",
|
|
94
|
+
value: function matchUrlPath(requestUrl) {
|
|
95
|
+
var urlWithoutSlash = requestUrl.endsWith("/") && requestUrl !== "/" ? requestUrl.slice(0, -1) : requestUrl;
|
|
96
|
+
if (urlWithoutSlash.endsWith(".html")) {
|
|
97
|
+
urlWithoutSlash = urlWithoutSlash.slice(0, -5);
|
|
98
|
+
}
|
|
99
|
+
if (this.urlMatcher) {
|
|
100
|
+
return Boolean(this.urlMatcher(urlWithoutSlash));
|
|
101
|
+
} else {
|
|
102
|
+
if (urlWithoutSlash.startsWith(this.urlPath)) {
|
|
103
|
+
if (this.urlPath !== "/" && urlWithoutSlash.length > this.urlPath.length && !urlWithoutSlash.startsWith("".concat(this.urlPath, "/"))) {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
key: "matchEntry",
|
|
114
|
+
value: function matchEntry(entryName) {
|
|
115
|
+
return this.spec.entryName === entryName;
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
key: "setupUrlPath",
|
|
120
|
+
value: function setupUrlPath() {
|
|
121
|
+
var urlPath = this.spec.urlPath;
|
|
122
|
+
this.urlPath = urlPath === "/" ? urlPath : removeTailSlash(urlPath);
|
|
123
|
+
var useReg = regCharsDetector.test(urlPath);
|
|
124
|
+
if (useReg) {
|
|
125
|
+
this.urlMatcher = match(urlPath, {
|
|
126
|
+
end: false,
|
|
127
|
+
decode: decodeURIComponent
|
|
128
|
+
});
|
|
129
|
+
this.urlReg = pathToRegexp(urlPath, [], {
|
|
130
|
+
end: false
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
}
|
|
84
134
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
key: "matchEntry",
|
|
90
|
-
value: function matchEntry(entryName) {
|
|
91
|
-
return this.spec.entryName === entryName;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// compiler urlPath to regexp if necessary
|
|
95
|
-
}, {
|
|
96
|
-
key: "setupUrlPath",
|
|
97
|
-
value: function setupUrlPath() {
|
|
98
|
-
var urlPath = this.spec.urlPath;
|
|
99
|
-
this.urlPath = urlPath === '/' ? urlPath : removeTailSlash(urlPath);
|
|
100
|
-
var useReg = regCharsDetector.test(urlPath);
|
|
101
|
-
if (useReg) {
|
|
102
|
-
this.urlMatcher = match(urlPath, {
|
|
103
|
-
end: false,
|
|
104
|
-
decode: decodeURIComponent
|
|
105
|
-
});
|
|
106
|
-
this.urlReg = pathToRegexp(urlPath, [], {
|
|
107
|
-
end: false
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}]);
|
|
112
|
-
return RouteMatcher;
|
|
113
|
-
}();
|
|
135
|
+
]);
|
|
136
|
+
return RouteMatcher;
|
|
137
|
+
}();
|
|
138
|
+
export { RouteMatcher };
|
|
@@ -1,26 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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 };
|