@modern-js/prod-server 2.47.0 → 2.47.1-alpha.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 (169) hide show
  1. package/README.md +20 -16
  2. package/dist/cjs/{libs/hook-api/route.js → error.js} +16 -25
  3. package/dist/cjs/index.js +46 -24
  4. package/dist/esm/error.js +15 -0
  5. package/dist/esm/index.js +105 -19
  6. package/dist/esm-node/error.js +14 -0
  7. package/dist/esm-node/index.js +44 -17
  8. package/dist/types/error.d.ts +6 -0
  9. package/dist/types/index.d.ts +21 -11
  10. package/package.json +18 -92
  11. package/dist/cjs/constants.js +0 -72
  12. package/dist/cjs/libs/context/context.js +0 -240
  13. package/dist/cjs/libs/context/index.js +0 -31
  14. package/dist/cjs/libs/hook-api/afterRenderForStream.js +0 -34
  15. package/dist/cjs/libs/hook-api/base.js +0 -107
  16. package/dist/cjs/libs/hook-api/index.js +0 -85
  17. package/dist/cjs/libs/hook-api/index.worker.js +0 -119
  18. package/dist/cjs/libs/hook-api/template.js +0 -74
  19. package/dist/cjs/libs/hook-api/templateForStream.js +0 -52
  20. package/dist/cjs/libs/loadConfig.js +0 -70
  21. package/dist/cjs/libs/metrics.js +0 -33
  22. package/dist/cjs/libs/preload/flushServerHeader.js +0 -49
  23. package/dist/cjs/libs/preload/index.js +0 -24
  24. package/dist/cjs/libs/preload/parseLinks.js +0 -124
  25. package/dist/cjs/libs/preload/shouldFlushServerHeader.js +0 -52
  26. package/dist/cjs/libs/preload/transformLinks2String.js +0 -150
  27. package/dist/cjs/libs/proxy.js +0 -99
  28. package/dist/cjs/libs/render/index.js +0 -109
  29. package/dist/cjs/libs/render/measure.js +0 -74
  30. package/dist/cjs/libs/render/ssr.js +0 -126
  31. package/dist/cjs/libs/render/ssrCache/cacheMod.js +0 -56
  32. package/dist/cjs/libs/render/ssrCache/index.js +0 -83
  33. package/dist/cjs/libs/render/ssrCache/manager.js +0 -106
  34. package/dist/cjs/libs/render/static.js +0 -72
  35. package/dist/cjs/libs/render/type.js +0 -33
  36. package/dist/cjs/libs/render/utils.js +0 -41
  37. package/dist/cjs/libs/reporter.js +0 -39
  38. package/dist/cjs/libs/route/index.js +0 -85
  39. package/dist/cjs/libs/route/matcher.js +0 -117
  40. package/dist/cjs/libs/route/route.js +0 -49
  41. package/dist/cjs/libs/serveFile.js +0 -84
  42. package/dist/cjs/libs/serverTiming.js +0 -44
  43. package/dist/cjs/renderHtml.js +0 -72
  44. package/dist/cjs/server/index.js +0 -229
  45. package/dist/cjs/server/modernServer.js +0 -532
  46. package/dist/cjs/server/modernServerSplit.js +0 -67
  47. package/dist/cjs/type.js +0 -16
  48. package/dist/cjs/utils.js +0 -164
  49. package/dist/cjs/workerServer.js +0 -264
  50. package/dist/esm/constants.js +0 -43
  51. package/dist/esm/libs/context/context.js +0 -292
  52. package/dist/esm/libs/context/index.js +0 -8
  53. package/dist/esm/libs/hook-api/afterRenderForStream.js +0 -33
  54. package/dist/esm/libs/hook-api/base.js +0 -108
  55. package/dist/esm/libs/hook-api/index.js +0 -55
  56. package/dist/esm/libs/hook-api/index.worker.js +0 -113
  57. package/dist/esm/libs/hook-api/route.js +0 -41
  58. package/dist/esm/libs/hook-api/template.js +0 -84
  59. package/dist/esm/libs/hook-api/templateForStream.js +0 -35
  60. package/dist/esm/libs/loadConfig.js +0 -36
  61. package/dist/esm/libs/metrics.js +0 -9
  62. package/dist/esm/libs/preload/flushServerHeader.js +0 -50
  63. package/dist/esm/libs/preload/index.js +0 -2
  64. package/dist/esm/libs/preload/parseLinks.js +0 -172
  65. package/dist/esm/libs/preload/shouldFlushServerHeader.js +0 -27
  66. package/dist/esm/libs/preload/transformLinks2String.js +0 -140
  67. package/dist/esm/libs/proxy.js +0 -160
  68. package/dist/esm/libs/render/index.js +0 -175
  69. package/dist/esm/libs/render/measure.js +0 -69
  70. package/dist/esm/libs/render/ssr.js +0 -129
  71. package/dist/esm/libs/render/ssrCache/cacheMod.js +0 -33
  72. package/dist/esm/libs/render/ssrCache/index.js +0 -151
  73. package/dist/esm/libs/render/ssrCache/manager.js +0 -170
  74. package/dist/esm/libs/render/static.js +0 -100
  75. package/dist/esm/libs/render/type.js +0 -9
  76. package/dist/esm/libs/render/utils.js +0 -16
  77. package/dist/esm/libs/reporter.js +0 -15
  78. package/dist/esm/libs/route/index.js +0 -116
  79. package/dist/esm/libs/route/matcher.js +0 -128
  80. package/dist/esm/libs/route/route.js +0 -26
  81. package/dist/esm/libs/serveFile.js +0 -68
  82. package/dist/esm/libs/serverTiming.js +0 -30
  83. package/dist/esm/renderHtml.js +0 -150
  84. package/dist/esm/server/index.js +0 -426
  85. package/dist/esm/server/modernServer.js +0 -1018
  86. package/dist/esm/server/modernServerSplit.js +0 -138
  87. package/dist/esm/type.js +0 -0
  88. package/dist/esm/utils.js +0 -103
  89. package/dist/esm/workerServer.js +0 -347
  90. package/dist/esm-node/constants.js +0 -43
  91. package/dist/esm-node/libs/context/context.js +0 -206
  92. package/dist/esm-node/libs/context/index.js +0 -6
  93. package/dist/esm-node/libs/hook-api/afterRenderForStream.js +0 -10
  94. package/dist/esm-node/libs/hook-api/base.js +0 -72
  95. package/dist/esm-node/libs/hook-api/index.js +0 -57
  96. package/dist/esm-node/libs/hook-api/index.worker.js +0 -92
  97. package/dist/esm-node/libs/hook-api/route.js +0 -24
  98. package/dist/esm-node/libs/hook-api/template.js +0 -49
  99. package/dist/esm-node/libs/hook-api/templateForStream.js +0 -28
  100. package/dist/esm-node/libs/loadConfig.js +0 -34
  101. package/dist/esm-node/libs/metrics.js +0 -9
  102. package/dist/esm-node/libs/preload/flushServerHeader.js +0 -25
  103. package/dist/esm-node/libs/preload/index.js +0 -2
  104. package/dist/esm-node/libs/preload/parseLinks.js +0 -90
  105. package/dist/esm-node/libs/preload/shouldFlushServerHeader.js +0 -27
  106. package/dist/esm-node/libs/preload/transformLinks2String.js +0 -126
  107. package/dist/esm-node/libs/proxy.js +0 -74
  108. package/dist/esm-node/libs/render/index.js +0 -75
  109. package/dist/esm-node/libs/render/measure.js +0 -49
  110. package/dist/esm-node/libs/render/ssr.js +0 -92
  111. package/dist/esm-node/libs/render/ssrCache/cacheMod.js +0 -22
  112. package/dist/esm-node/libs/render/ssrCache/index.js +0 -59
  113. package/dist/esm-node/libs/render/ssrCache/manager.js +0 -82
  114. package/dist/esm-node/libs/render/static.js +0 -38
  115. package/dist/esm-node/libs/render/type.js +0 -9
  116. package/dist/esm-node/libs/render/utils.js +0 -16
  117. package/dist/esm-node/libs/reporter.js +0 -15
  118. package/dist/esm-node/libs/route/index.js +0 -60
  119. package/dist/esm-node/libs/route/matcher.js +0 -93
  120. package/dist/esm-node/libs/route/route.js +0 -25
  121. package/dist/esm-node/libs/serveFile.js +0 -49
  122. package/dist/esm-node/libs/serverTiming.js +0 -20
  123. package/dist/esm-node/renderHtml.js +0 -80
  124. package/dist/esm-node/server/index.js +0 -195
  125. package/dist/esm-node/server/modernServer.js +0 -498
  126. package/dist/esm-node/server/modernServerSplit.js +0 -43
  127. package/dist/esm-node/type.js +0 -0
  128. package/dist/esm-node/utils.js +0 -132
  129. package/dist/esm-node/workerServer.js +0 -239
  130. package/dist/types/constants.d.ts +0 -30
  131. package/dist/types/libs/context/context.d.ts +0 -62
  132. package/dist/types/libs/context/index.d.ts +0 -7
  133. package/dist/types/libs/hook-api/afterRenderForStream.d.ts +0 -4
  134. package/dist/types/libs/hook-api/base.d.ts +0 -53
  135. package/dist/types/libs/hook-api/index.d.ts +0 -6
  136. package/dist/types/libs/hook-api/index.worker.d.ts +0 -19
  137. package/dist/types/libs/hook-api/route.d.ts +0 -9
  138. package/dist/types/libs/hook-api/template.d.ts +0 -22
  139. package/dist/types/libs/hook-api/templateForStream.d.ts +0 -8
  140. package/dist/types/libs/loadConfig.d.ts +0 -13
  141. package/dist/types/libs/metrics.d.ts +0 -3
  142. package/dist/types/libs/preload/flushServerHeader.d.ts +0 -14
  143. package/dist/types/libs/preload/index.d.ts +0 -2
  144. package/dist/types/libs/preload/parseLinks.d.ts +0 -13
  145. package/dist/types/libs/preload/shouldFlushServerHeader.d.ts +0 -3
  146. package/dist/types/libs/preload/transformLinks2String.d.ts +0 -3
  147. package/dist/types/libs/proxy.d.ts +0 -13
  148. package/dist/types/libs/render/index.d.ts +0 -21
  149. package/dist/types/libs/render/measure.d.ts +0 -10
  150. package/dist/types/libs/render/ssr.d.ts +0 -12
  151. package/dist/types/libs/render/ssrCache/cacheMod.d.ts +0 -8
  152. package/dist/types/libs/render/ssrCache/index.d.ts +0 -7
  153. package/dist/types/libs/render/ssrCache/manager.d.ts +0 -14
  154. package/dist/types/libs/render/static.d.ts +0 -3
  155. package/dist/types/libs/render/type.d.ts +0 -36
  156. package/dist/types/libs/render/utils.d.ts +0 -5
  157. package/dist/types/libs/reporter.d.ts +0 -2
  158. package/dist/types/libs/route/index.d.ts +0 -15
  159. package/dist/types/libs/route/matcher.d.ts +0 -15
  160. package/dist/types/libs/route/route.d.ts +0 -14
  161. package/dist/types/libs/serveFile.d.ts +0 -9
  162. package/dist/types/libs/serverTiming.d.ts +0 -13
  163. package/dist/types/renderHtml.d.ts +0 -23
  164. package/dist/types/server/index.d.ts +0 -55
  165. package/dist/types/server/modernServer.d.ts +0 -71
  166. package/dist/types/server/modernServerSplit.d.ts +0 -2
  167. package/dist/types/type.d.ts +0 -77
  168. package/dist/types/utils.d.ts +0 -24
  169. package/dist/types/workerServer.d.ts +0 -59
@@ -1,151 +0,0 @@
1
- import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
- import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
3
- import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
4
- import { Transform } from "stream";
5
- import { createMemoryStorage } from "@modern-js/runtime-utils/storer";
6
- import { cacheMod } from "./cacheMod";
7
- import { CacheManager } from "./manager";
8
- var cacheStorage = createMemoryStorage("__ssr__cache");
9
- function ssrCache(req, render, ssrContext) {
10
- return _ssrCache.apply(this, arguments);
11
- }
12
- function _ssrCache() {
13
- _ssrCache = _async_to_generator(function(req, render, ssrContext) {
14
- var customContainer, cacheOption, cacheControl, cacheManager, renderResult, stream;
15
- return _ts_generator(this, function(_state) {
16
- switch (_state.label) {
17
- case 0:
18
- customContainer = cacheMod.customContainer, cacheOption = cacheMod.cacheOption;
19
- return [
20
- 4,
21
- matchCacheControl(req, cacheOption)
22
- ];
23
- case 1:
24
- cacheControl = _state.sent();
25
- cacheManager = new CacheManager(customContainer ? customContainer : cacheStorage);
26
- if (!cacheControl)
27
- return [
28
- 3,
29
- 2
30
- ];
31
- return [
32
- 2,
33
- cacheManager.getCacheResult(req, cacheControl, render, ssrContext)
34
- ];
35
- case 2:
36
- return [
37
- 4,
38
- render(ssrContext)
39
- ];
40
- case 3:
41
- renderResult = _state.sent();
42
- if (!renderResult) {
43
- return [
44
- 2,
45
- ""
46
- ];
47
- } else if (typeof renderResult === "string") {
48
- return [
49
- 2,
50
- renderResult
51
- ];
52
- } else {
53
- stream = new Transform({
54
- write: function write(chunk, _, callback) {
55
- this.push(chunk);
56
- callback();
57
- }
58
- });
59
- return [
60
- 2,
61
- renderResult(stream)
62
- ];
63
- }
64
- _state.label = 4;
65
- case 4:
66
- return [
67
- 2
68
- ];
69
- }
70
- });
71
- });
72
- return _ssrCache.apply(this, arguments);
73
- }
74
- function matchCacheControl(req, cacheOption) {
75
- return _matchCacheControl.apply(this, arguments);
76
- }
77
- function _matchCacheControl() {
78
- _matchCacheControl = _async_to_generator(function(req, cacheOption) {
79
- var url, options, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _step_value, key, option;
80
- function isCacheOptionProvider(option2) {
81
- return typeof option2 === "function";
82
- }
83
- function isCacheControl(option2) {
84
- return typeof option2 === "object" && option2 !== null && "maxAge" in option2;
85
- }
86
- return _ts_generator(this, function(_state) {
87
- if (!cacheOption) {
88
- return [
89
- 2,
90
- void 0
91
- ];
92
- } else if (isCacheControl(cacheOption)) {
93
- return [
94
- 2,
95
- cacheOption
96
- ];
97
- } else if (isCacheOptionProvider(cacheOption)) {
98
- return [
99
- 2,
100
- cacheOption(req)
101
- ];
102
- } else {
103
- url = req.url;
104
- options = Object.entries(cacheOption);
105
- _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
106
- try {
107
- for (_iterator = options[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
108
- _step_value = _sliced_to_array(_step.value, 2), key = _step_value[0], option = _step_value[1];
109
- if (key === "*" || new RegExp(key).test(url)) {
110
- if (typeof option === "function") {
111
- return [
112
- 2,
113
- option(req)
114
- ];
115
- } else {
116
- return [
117
- 2,
118
- option
119
- ];
120
- }
121
- }
122
- }
123
- } catch (err) {
124
- _didIteratorError = true;
125
- _iteratorError = err;
126
- } finally {
127
- try {
128
- if (!_iteratorNormalCompletion && _iterator.return != null) {
129
- _iterator.return();
130
- }
131
- } finally {
132
- if (_didIteratorError) {
133
- throw _iteratorError;
134
- }
135
- }
136
- }
137
- return [
138
- 2,
139
- void 0
140
- ];
141
- }
142
- return [
143
- 2
144
- ];
145
- });
146
- });
147
- return _matchCacheControl.apply(this, arguments);
148
- }
149
- export {
150
- ssrCache
151
- };
@@ -1,170 +0,0 @@
1
- import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
- import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
3
- import { _ as _create_class } from "@swc/helpers/_/_create_class";
4
- import { _ as _define_property } from "@swc/helpers/_/_define_property";
5
- import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
6
- import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
7
- import { Transform } from "stream";
8
- var CacheManager = /* @__PURE__ */ function() {
9
- "use strict";
10
- function CacheManager2(container) {
11
- _class_call_check(this, CacheManager2);
12
- _define_property(this, "container", void 0);
13
- this.container = container;
14
- }
15
- _create_class(CacheManager2, [
16
- {
17
- key: "getCacheResult",
18
- value: function getCacheResult(req, cacheControl, render, ssrContext) {
19
- var _this = this;
20
- return _async_to_generator(function() {
21
- var key, value, maxAge, staleWhileRevalidate, ttl, cache, interval;
22
- return _ts_generator(this, function(_state) {
23
- switch (_state.label) {
24
- case 0:
25
- key = _this.computedKey(req, cacheControl);
26
- return [
27
- 4,
28
- _this.container.get(key)
29
- ];
30
- case 1:
31
- value = _state.sent();
32
- maxAge = cacheControl.maxAge, staleWhileRevalidate = cacheControl.staleWhileRevalidate;
33
- ttl = maxAge + staleWhileRevalidate;
34
- if (value) {
35
- cache = JSON.parse(value);
36
- interval = Date.now() - cache.cursor;
37
- if (interval <= maxAge) {
38
- return [
39
- 2,
40
- cache.val
41
- ];
42
- } else if (interval <= staleWhileRevalidate + maxAge) {
43
- _this.processCache(key, render, ssrContext, ttl);
44
- return [
45
- 2,
46
- cache.val
47
- ];
48
- } else {
49
- return [
50
- 2,
51
- _this.processCache(key, render, ssrContext, ttl)
52
- ];
53
- }
54
- } else {
55
- return [
56
- 2,
57
- _this.processCache(key, render, ssrContext, ttl)
58
- ];
59
- }
60
- return [
61
- 2
62
- ];
63
- }
64
- });
65
- })();
66
- }
67
- },
68
- {
69
- key: "processCache",
70
- value: function processCache(key, render, ssrContext, ttl) {
71
- var _this = this;
72
- return _async_to_generator(function() {
73
- var renderResult, current, cache, html, stream;
74
- return _ts_generator(this, function(_state) {
75
- switch (_state.label) {
76
- case 0:
77
- return [
78
- 4,
79
- render(ssrContext)
80
- ];
81
- case 1:
82
- renderResult = _state.sent();
83
- if (!!renderResult)
84
- return [
85
- 3,
86
- 2
87
- ];
88
- return [
89
- 2,
90
- ""
91
- ];
92
- case 2:
93
- if (!(typeof renderResult === "string"))
94
- return [
95
- 3,
96
- 4
97
- ];
98
- current = Date.now();
99
- cache = {
100
- val: renderResult,
101
- cursor: current
102
- };
103
- return [
104
- 4,
105
- _this.container.set(key, JSON.stringify(cache), {
106
- ttl
107
- })
108
- ];
109
- case 3:
110
- _state.sent();
111
- return [
112
- 2,
113
- renderResult
114
- ];
115
- case 4:
116
- html = "";
117
- stream = new Transform({
118
- write: function write(chunk, _, callback) {
119
- html += chunk.toString();
120
- this.push(chunk);
121
- callback();
122
- }
123
- });
124
- stream.on("close", function() {
125
- var current2 = Date.now();
126
- var cache2 = {
127
- val: html,
128
- cursor: current2
129
- };
130
- _this.container.set(key, JSON.stringify(cache2), {
131
- ttl
132
- });
133
- });
134
- return [
135
- 2,
136
- renderResult(stream)
137
- ];
138
- case 5:
139
- return [
140
- 2
141
- ];
142
- }
143
- });
144
- })();
145
- }
146
- },
147
- {
148
- key: "computedKey",
149
- value: function computedKey(req, cacheControl) {
150
- var url = req.url;
151
- var _url_split = _sliced_to_array(url.split("?"), 1), pathname = _url_split[0];
152
- var customKey = cacheControl.customKey;
153
- var defaultKey = pathname.replace(/.+\/+$/, "");
154
- if (customKey) {
155
- if (typeof customKey === "string") {
156
- return customKey;
157
- } else {
158
- return customKey(defaultKey);
159
- }
160
- } else {
161
- return defaultKey;
162
- }
163
- }
164
- }
165
- ]);
166
- return CacheManager2;
167
- }();
168
- export {
169
- CacheManager
170
- };
@@ -1,100 +0,0 @@
1
- import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
- import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
- import path from "path";
4
- import { mime } from "@modern-js/utils";
5
- import { fileReader } from "@modern-js/runtime-utils/fileReader";
6
- function handleDirectory(ctx, entryPath, urlPath) {
7
- return _handleDirectory.apply(this, arguments);
8
- }
9
- function _handleDirectory() {
10
- _handleDirectory = _async_to_generator(function(ctx, entryPath, urlPath) {
11
- var pathname, filepath, content, contentType;
12
- return _ts_generator(this, function(_state) {
13
- switch (_state.label) {
14
- case 0:
15
- pathname = ctx.path;
16
- filepath = path.join(entryPath, trimLeft(pathname, urlPath));
17
- return [
18
- 4,
19
- fileReader.readFile(filepath)
20
- ];
21
- case 1:
22
- content = _state.sent();
23
- contentType = mime.contentType(path.extname(filepath) || "");
24
- if (!!content)
25
- return [
26
- 3,
27
- 7
28
- ];
29
- if (!pathname.endsWith("/"))
30
- return [
31
- 3,
32
- 3
33
- ];
34
- return [
35
- 4,
36
- fileReader.readFile("".concat(filepath, "index.html"))
37
- ];
38
- case 2:
39
- content = _state.sent();
40
- return [
41
- 3,
42
- 6
43
- ];
44
- case 3:
45
- if (!!pathname.includes("."))
46
- return [
47
- 3,
48
- 6
49
- ];
50
- return [
51
- 4,
52
- fileReader.readFile("".concat(filepath, ".html"))
53
- ];
54
- case 4:
55
- content = _state.sent();
56
- if (!!content)
57
- return [
58
- 3,
59
- 6
60
- ];
61
- return [
62
- 4,
63
- fileReader.readFile("".concat(filepath, "/index.html"))
64
- ];
65
- case 5:
66
- content = _state.sent();
67
- _state.label = 6;
68
- case 6:
69
- if (content) {
70
- contentType = mime.contentType("html");
71
- }
72
- _state.label = 7;
73
- case 7:
74
- if (!content) {
75
- return [
76
- 2,
77
- null
78
- ];
79
- }
80
- return [
81
- 2,
82
- {
83
- content,
84
- contentType: contentType || ""
85
- }
86
- ];
87
- }
88
- });
89
- });
90
- return _handleDirectory.apply(this, arguments);
91
- }
92
- var trimLeft = function(str, prefix) {
93
- if (str.startsWith(prefix)) {
94
- return str.substring(prefix.length);
95
- }
96
- return str;
97
- };
98
- export {
99
- handleDirectory
100
- };
@@ -1,9 +0,0 @@
1
- var RenderLevel;
2
- (function(RenderLevel2) {
3
- RenderLevel2[RenderLevel2["CLIENT_RENDER"] = 0] = "CLIENT_RENDER";
4
- RenderLevel2[RenderLevel2["SERVER_PREFETCH"] = 1] = "SERVER_PREFETCH";
5
- RenderLevel2[RenderLevel2["SERVER_RENDER"] = 2] = "SERVER_RENDER";
6
- })(RenderLevel || (RenderLevel = {}));
7
- export {
8
- RenderLevel
9
- };
@@ -1,16 +0,0 @@
1
- import { TemplateAPI } from "../hook-api/template";
2
- import { templateInjectableStream } from "../hook-api/templateForStream";
3
- var injectServerData = function(content, context) {
4
- var template = new TemplateAPI(content);
5
- template.prependHead('<script type="application/json" id="__MODERN_SERVER_DATA__">'.concat(JSON.stringify(context.serverData), "</script>"));
6
- return template.get();
7
- };
8
- var injectServerDataStream = function(content, context) {
9
- return content.pipe(templateInjectableStream({
10
- prependHead: '<script type="application/json" id="__MODERN_SERVER_DATA__">'.concat(JSON.stringify(context.serverData), "</script>")
11
- }));
12
- };
13
- export {
14
- injectServerData,
15
- injectServerDataStream
16
- };
@@ -1,15 +0,0 @@
1
- var defaultReporter = {
2
- init: function init() {
3
- },
4
- reportError: function reportError() {
5
- },
6
- reportTiming: function reportTiming() {
7
- },
8
- reportInfo: function reportInfo() {
9
- },
10
- reportWarn: function reportWarn() {
11
- }
12
- };
13
- export {
14
- defaultReporter
15
- };
@@ -1,116 +0,0 @@
1
- import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
2
- import { _ as _create_class } from "@swc/helpers/_/_create_class";
3
- import { _ as _define_property } from "@swc/helpers/_/_define_property";
4
- import { RouteMatcher } from "./matcher";
5
- var RouteMatchManager = /* @__PURE__ */ function() {
6
- "use strict";
7
- function RouteMatchManager2() {
8
- _class_call_check(this, RouteMatchManager2);
9
- _define_property(this, "matchers", void 0);
10
- _define_property(this, "specs", []);
11
- this.matchers = [];
12
- }
13
- _create_class(RouteMatchManager2, [
14
- {
15
- key: "filter",
16
- value: (
17
- // get all routes matches pathname
18
- function filter(pathname) {
19
- return this.matchers.reduce(function(matches, matcher) {
20
- if (matcher.matchUrlPath(pathname)) {
21
- matches.push(matcher);
22
- }
23
- return matches;
24
- }, []);
25
- }
26
- )
27
- },
28
- {
29
- key: "best",
30
- value: (
31
- // get best match from a set of matches
32
- function best(pathname, matches) {
33
- var best2;
34
- var matchedLen = 0;
35
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
36
- try {
37
- for (var _iterator = matches[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
38
- var match = _step.value;
39
- var len = match.matchLength(pathname);
40
- if (len === null) {
41
- continue;
42
- }
43
- if (len > matchedLen) {
44
- best2 = match;
45
- matchedLen = len;
46
- }
47
- }
48
- } catch (err) {
49
- _didIteratorError = true;
50
- _iteratorError = err;
51
- } finally {
52
- try {
53
- if (!_iteratorNormalCompletion && _iterator.return != null) {
54
- _iterator.return();
55
- }
56
- } finally {
57
- if (_didIteratorError) {
58
- throw _iteratorError;
59
- }
60
- }
61
- }
62
- return best2;
63
- }
64
- )
65
- },
66
- {
67
- key: "reset",
68
- value: (
69
- // reset routes matcher
70
- function reset(specs) {
71
- this.specs = specs;
72
- var matchers = specs.reduce(function(ms, spec) {
73
- ms.push(new RouteMatcher(spec));
74
- return ms;
75
- }, []);
76
- this.matchers = matchers;
77
- }
78
- )
79
- },
80
- {
81
- key: "match",
82
- value: (
83
- // get best match from all matcher in manager
84
- function match(pathname) {
85
- var matches = this.filter(pathname);
86
- var best = this.best(pathname, matches);
87
- return best;
88
- }
89
- )
90
- },
91
- {
92
- key: "matchEntry",
93
- value: function matchEntry(entryname) {
94
- return this.matchers.find(function(matcher) {
95
- return matcher.matchEntry(entryname);
96
- });
97
- }
98
- },
99
- {
100
- key: "getBundles",
101
- value: function getBundles() {
102
- var bundles = this.specs.filter(function(route) {
103
- return route.isSSR;
104
- }).map(function(route) {
105
- return route.bundle;
106
- });
107
- return bundles;
108
- }
109
- }
110
- ]);
111
- return RouteMatchManager2;
112
- }();
113
- export {
114
- RouteMatchManager,
115
- RouteMatcher
116
- };
@@ -1,128 +0,0 @@
1
- import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
2
- import { _ as _create_class } from "@swc/helpers/_/_create_class";
3
- import { _ as _define_property } from "@swc/helpers/_/_define_property";
4
- import { match, pathToRegexp, compile } from "path-to-regexp";
5
- import { ModernRoute } from "./route";
6
- var removeTailSlash = function(s) {
7
- return s.replace(/\/+$/, "");
8
- };
9
- var removeHtmlSuffix = function(url) {
10
- if (url.endsWith(".html")) {
11
- return url.slice(0, -5);
12
- }
13
- return url;
14
- };
15
- var toPath = function(reg, params) {
16
- var fn = compile(reg, {
17
- encode: encodeURIComponent
18
- });
19
- return fn(params);
20
- };
21
- var regCharsDetector = /[^a-zA-Z\-_0-9\/\.]/;
22
- var RouteMatcher = /* @__PURE__ */ function() {
23
- "use strict";
24
- function RouteMatcher2(spec) {
25
- _class_call_check(this, RouteMatcher2);
26
- _define_property(this, "spec", void 0);
27
- _define_property(this, "urlPath", "");
28
- _define_property(this, "urlMatcher", void 0);
29
- _define_property(this, "urlReg", void 0);
30
- this.spec = spec;
31
- this.setupUrlPath();
32
- }
33
- _create_class(RouteMatcher2, [
34
- {
35
- key: "generate",
36
- value: (
37
- // generate modern route object
38
- function generate(url) {
39
- var route = new ModernRoute(this.spec);
40
- if (this.urlPath) {
41
- var params = this.parseURLParams(url);
42
- route.urlPath = toPath(route.urlPath, params);
43
- route.params = params;
44
- }
45
- return route;
46
- }
47
- )
48
- },
49
- {
50
- key: "parseURLParams",
51
- value: function parseURLParams(pathname) {
52
- if (!this.urlMatcher) {
53
- return {};
54
- } else {
55
- var matchResult = this.urlMatcher(pathname);
56
- return matchResult.params;
57
- }
58
- }
59
- },
60
- {
61
- key: "matchLength",
62
- value: (
63
- // get match url length
64
- function matchLength(pathname) {
65
- if (!this.urlReg) {
66
- return this.urlPath.length;
67
- } else {
68
- var _result_;
69
- var result = this.urlReg.exec(pathname);
70
- return (result === null || result === void 0 ? void 0 : (_result_ = result[0]) === null || _result_ === void 0 ? void 0 : _result_.length) || null;
71
- }
72
- }
73
- )
74
- },
75
- {
76
- key: "matchUrlPath",
77
- value: (
78
- // if match url path
79
- function matchUrlPath(requestUrl) {
80
- var urlWithoutSlash = requestUrl.endsWith("/") && requestUrl !== "/" ? requestUrl.slice(0, -1) : requestUrl;
81
- urlWithoutSlash = removeHtmlSuffix(urlWithoutSlash);
82
- if (this.urlMatcher) {
83
- return Boolean(this.urlMatcher(urlWithoutSlash));
84
- } else {
85
- var urlPath = removeHtmlSuffix(this.urlPath);
86
- if (urlWithoutSlash.startsWith(urlPath)) {
87
- if (urlPath !== "/" && urlWithoutSlash.length > urlPath.length && !urlWithoutSlash.startsWith("".concat(urlPath, "/"))) {
88
- return false;
89
- }
90
- return true;
91
- }
92
- return false;
93
- }
94
- }
95
- )
96
- },
97
- {
98
- key: "matchEntry",
99
- value: function matchEntry(entryName) {
100
- return this.spec.entryName === entryName;
101
- }
102
- },
103
- {
104
- key: "setupUrlPath",
105
- value: (
106
- // compiler urlPath to regexp if necessary
107
- function setupUrlPath() {
108
- var urlPath = this.spec.urlPath;
109
- this.urlPath = urlPath === "/" ? urlPath : removeTailSlash(urlPath);
110
- var useReg = regCharsDetector.test(urlPath);
111
- if (useReg) {
112
- this.urlMatcher = match(urlPath, {
113
- end: false,
114
- decode: decodeURIComponent
115
- });
116
- this.urlReg = pathToRegexp(urlPath, [], {
117
- end: false
118
- });
119
- }
120
- }
121
- )
122
- }
123
- ]);
124
- return RouteMatcher2;
125
- }();
126
- export {
127
- RouteMatcher
128
- };