@modern-js/prod-server 2.6.1-alpha.0 → 2.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/README.md +2 -2
  3. package/dist/cjs/libs/context/context.js +8 -9
  4. package/dist/cjs/libs/serveFile.js +3 -4
  5. package/dist/cjs/server/modernServer.js +25 -15
  6. package/dist/cjs/utils.js +4 -13
  7. package/dist/esm/libs/context/context.js +11 -12
  8. package/dist/esm/libs/serveFile.js +4 -5
  9. package/dist/esm/server/modernServer.js +50 -28
  10. package/dist/esm/utils.js +4 -8
  11. package/dist/esm-node/libs/context/context.js +8 -9
  12. package/dist/esm-node/libs/serveFile.js +3 -4
  13. package/dist/esm-node/server/modernServer.js +32 -16
  14. package/dist/esm-node/utils.js +4 -12
  15. package/dist/types/libs/context/context.d.ts +2 -4
  16. package/dist/types/libs/serveFile.d.ts +1 -2
  17. package/dist/types/server/modernServer.d.ts +1 -1
  18. package/dist/types/utils.d.ts +2 -3
  19. package/package.json +11 -11
  20. package/dist/js/modern/constants.js +0 -35
  21. package/dist/js/modern/index.js +0 -18
  22. package/dist/js/modern/libs/context/context.js +0 -160
  23. package/dist/js/modern/libs/context/index.js +0 -6
  24. package/dist/js/modern/libs/hook-api/index.js +0 -134
  25. package/dist/js/modern/libs/hook-api/route.js +0 -20
  26. package/dist/js/modern/libs/hook-api/template.js +0 -73
  27. package/dist/js/modern/libs/loadConfig.js +0 -62
  28. package/dist/js/modern/libs/logger.js +0 -111
  29. package/dist/js/modern/libs/metrics.js +0 -11
  30. package/dist/js/modern/libs/proxy.js +0 -92
  31. package/dist/js/modern/libs/render/cache/__tests__/cache.fun.test.js +0 -114
  32. package/dist/js/modern/libs/render/cache/__tests__/cache.test.js +0 -254
  33. package/dist/js/modern/libs/render/cache/__tests__/cacheable.js +0 -47
  34. package/dist/js/modern/libs/render/cache/__tests__/error-configuration.js +0 -37
  35. package/dist/js/modern/libs/render/cache/__tests__/matched-cache.js +0 -91
  36. package/dist/js/modern/libs/render/cache/index.js +0 -115
  37. package/dist/js/modern/libs/render/cache/page-caches/index.js +0 -32
  38. package/dist/js/modern/libs/render/cache/page-caches/lru.js +0 -29
  39. package/dist/js/modern/libs/render/cache/spr.js +0 -248
  40. package/dist/js/modern/libs/render/cache/type.js +0 -0
  41. package/dist/js/modern/libs/render/cache/util.js +0 -102
  42. package/dist/js/modern/libs/render/index.js +0 -86
  43. package/dist/js/modern/libs/render/measure.js +0 -68
  44. package/dist/js/modern/libs/render/reader.js +0 -107
  45. package/dist/js/modern/libs/render/ssr.js +0 -100
  46. package/dist/js/modern/libs/render/static.js +0 -60
  47. package/dist/js/modern/libs/render/type.js +0 -9
  48. package/dist/js/modern/libs/route/index.js +0 -54
  49. package/dist/js/modern/libs/route/matcher.js +0 -87
  50. package/dist/js/modern/libs/route/route.js +0 -16
  51. package/dist/js/modern/libs/serve-file.js +0 -67
  52. package/dist/js/modern/server/index.js +0 -208
  53. package/dist/js/modern/server/modern-server-split.js +0 -74
  54. package/dist/js/modern/server/modern-server.js +0 -554
  55. package/dist/js/modern/type.js +0 -0
  56. package/dist/js/modern/utils.js +0 -136
  57. package/dist/js/modern/worker-server.js +0 -89
  58. package/dist/js/node/constants.js +0 -62
  59. package/dist/js/node/index.js +0 -44
  60. package/dist/js/node/libs/context/context.js +0 -189
  61. package/dist/js/node/libs/context/index.js +0 -30
  62. package/dist/js/node/libs/hook-api/index.js +0 -164
  63. package/dist/js/node/libs/hook-api/route.js +0 -43
  64. package/dist/js/node/libs/hook-api/template.js +0 -97
  65. package/dist/js/node/libs/loadConfig.js +0 -91
  66. package/dist/js/node/libs/logger.js +0 -133
  67. package/dist/js/node/libs/metrics.js +0 -34
  68. package/dist/js/node/libs/proxy.js +0 -114
  69. package/dist/js/node/libs/render/cache/__tests__/cache.fun.test.js +0 -115
  70. package/dist/js/node/libs/render/cache/__tests__/cache.test.js +0 -245
  71. package/dist/js/node/libs/render/cache/__tests__/cacheable.js +0 -70
  72. package/dist/js/node/libs/render/cache/__tests__/error-configuration.js +0 -60
  73. package/dist/js/node/libs/render/cache/__tests__/matched-cache.js +0 -114
  74. package/dist/js/node/libs/render/cache/index.js +0 -134
  75. package/dist/js/node/libs/render/cache/page-caches/index.js +0 -55
  76. package/dist/js/node/libs/render/cache/page-caches/lru.js +0 -58
  77. package/dist/js/node/libs/render/cache/spr.js +0 -270
  78. package/dist/js/node/libs/render/cache/type.js +0 -15
  79. package/dist/js/node/libs/render/cache/util.js +0 -138
  80. package/dist/js/node/libs/render/index.js +0 -115
  81. package/dist/js/node/libs/render/measure.js +0 -90
  82. package/dist/js/node/libs/render/reader.js +0 -140
  83. package/dist/js/node/libs/render/ssr.js +0 -123
  84. package/dist/js/node/libs/render/static.js +0 -89
  85. package/dist/js/node/libs/render/type.js +0 -32
  86. package/dist/js/node/libs/route/index.js +0 -78
  87. package/dist/js/node/libs/route/matcher.js +0 -106
  88. package/dist/js/node/libs/route/route.js +0 -39
  89. package/dist/js/node/libs/serve-file.js +0 -97
  90. package/dist/js/node/server/index.js +0 -219
  91. package/dist/js/node/server/modern-server-split.js +0 -97
  92. package/dist/js/node/server/modern-server.js +0 -559
  93. package/dist/js/node/type.js +0 -15
  94. package/dist/js/node/utils.js +0 -166
  95. package/dist/js/node/worker-server.js +0 -113
  96. package/dist/js/treeshaking/constants.js +0 -29
  97. package/dist/js/treeshaking/index.js +0 -13
  98. package/dist/js/treeshaking/libs/context/context.js +0 -274
  99. package/dist/js/treeshaking/libs/context/index.js +0 -5
  100. package/dist/js/treeshaking/libs/hook-api/index.js +0 -281
  101. package/dist/js/treeshaking/libs/hook-api/route.js +0 -68
  102. package/dist/js/treeshaking/libs/hook-api/template.js +0 -127
  103. package/dist/js/treeshaking/libs/loadConfig.js +0 -82
  104. package/dist/js/treeshaking/libs/logger.js +0 -205
  105. package/dist/js/treeshaking/libs/metrics.js +0 -6
  106. package/dist/js/treeshaking/libs/proxy.js +0 -244
  107. package/dist/js/treeshaking/libs/render/cache/__tests__/cache.fun.test.js +0 -291
  108. package/dist/js/treeshaking/libs/render/cache/__tests__/cache.test.js +0 -781
  109. package/dist/js/treeshaking/libs/render/cache/__tests__/cacheable.js +0 -67
  110. package/dist/js/treeshaking/libs/render/cache/__tests__/error-configuration.js +0 -45
  111. package/dist/js/treeshaking/libs/render/cache/__tests__/matched-cache.js +0 -147
  112. package/dist/js/treeshaking/libs/render/cache/index.js +0 -346
  113. package/dist/js/treeshaking/libs/render/cache/page-caches/index.js +0 -154
  114. package/dist/js/treeshaking/libs/render/cache/page-caches/lru.js +0 -84
  115. package/dist/js/treeshaking/libs/render/cache/spr.js +0 -492
  116. package/dist/js/treeshaking/libs/render/cache/type.js +0 -1
  117. package/dist/js/treeshaking/libs/render/cache/util.js +0 -280
  118. package/dist/js/treeshaking/libs/render/index.js +0 -234
  119. package/dist/js/treeshaking/libs/render/measure.js +0 -146
  120. package/dist/js/treeshaking/libs/render/reader.js +0 -339
  121. package/dist/js/treeshaking/libs/render/ssr.js +0 -223
  122. package/dist/js/treeshaking/libs/render/static.js +0 -216
  123. package/dist/js/treeshaking/libs/render/type.js +0 -7
  124. package/dist/js/treeshaking/libs/route/index.js +0 -130
  125. package/dist/js/treeshaking/libs/route/matcher.js +0 -143
  126. package/dist/js/treeshaking/libs/route/route.js +0 -40
  127. package/dist/js/treeshaking/libs/serve-file.js +0 -184
  128. package/dist/js/treeshaking/server/index.js +0 -505
  129. package/dist/js/treeshaking/server/modern-server-split.js +0 -360
  130. package/dist/js/treeshaking/server/modern-server.js +0 -1089
  131. package/dist/js/treeshaking/type.js +0 -1
  132. package/dist/js/treeshaking/utils.js +0 -147
  133. package/dist/js/treeshaking/worker-server.js +0 -233
@@ -1,140 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
- mod
22
- ));
23
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
24
- var __async = (__this, __arguments, generator) => {
25
- return new Promise((resolve, reject) => {
26
- var fulfilled = (value) => {
27
- try {
28
- step(generator.next(value));
29
- } catch (e) {
30
- reject(e);
31
- }
32
- };
33
- var rejected = (value) => {
34
- try {
35
- step(generator.throw(value));
36
- } catch (e) {
37
- reject(e);
38
- }
39
- };
40
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
41
- step((generator = generator.apply(__this, __arguments)).next());
42
- });
43
- };
44
- var reader_exports = {};
45
- __export(reader_exports, {
46
- LruReader: () => LruReader,
47
- close: () => close,
48
- init: () => init,
49
- readFile: () => readFile,
50
- updateFile: () => updateFile
51
- });
52
- module.exports = __toCommonJS(reader_exports);
53
- var import_utils = require("@modern-js/utils");
54
- var import_lru_cache = __toESM(require("lru-cache"));
55
- const Byte = 1;
56
- const KB = 1024 * Byte;
57
- const MB = 1024 * KB;
58
- const getContentLength = (cache) => cache.content.length;
59
- const createCacheItem = (filepath, mtime) => __async(void 0, null, function* () {
60
- const content = yield import_utils.fs.readFile(filepath);
61
- return {
62
- content,
63
- mtime
64
- };
65
- });
66
- class LruReader {
67
- constructor() {
68
- this.cache = new import_lru_cache.default({
69
- max: 256 * MB,
70
- length: getContentLength,
71
- maxAge: 5 * 60 * 5e3
72
- });
73
- }
74
- init() {
75
- }
76
- close() {
77
- }
78
- read(filepath) {
79
- return __async(this, null, function* () {
80
- if (this.cache.has(filepath)) {
81
- const { content } = this.cache.get(filepath);
82
- return { content };
83
- }
84
- if (!import_utils.fs.existsSync(filepath)) {
85
- return null;
86
- }
87
- const stat = import_utils.fs.statSync(filepath);
88
- if (stat.isDirectory()) {
89
- return null;
90
- }
91
- if (stat.size > 20 * MB) {
92
- return null;
93
- }
94
- const item = yield createCacheItem(filepath, stat.mtime);
95
- this.cache.set(filepath, item);
96
- return item;
97
- });
98
- }
99
- update() {
100
- const { cache } = this;
101
- const files = cache.keys();
102
- for (const filepath of files) {
103
- if (!import_utils.fs.existsSync(filepath)) {
104
- cache.del(filepath);
105
- }
106
- try {
107
- const item = cache.get(filepath);
108
- const stat = import_utils.fs.statSync(filepath);
109
- const { mtime } = stat;
110
- if (item.mtime < mtime) {
111
- cache.del(filepath);
112
- }
113
- } catch (e) {
114
- cache.del(filepath);
115
- }
116
- }
117
- }
118
- }
119
- const reader = new LruReader();
120
- const readFile = (filepath) => __async(void 0, null, function* () {
121
- const file = yield reader.read(filepath);
122
- return file == null ? void 0 : file.content;
123
- });
124
- const updateFile = () => {
125
- reader.update();
126
- };
127
- const init = () => {
128
- reader.init();
129
- };
130
- const close = () => {
131
- reader.close();
132
- };
133
- // Annotate the CommonJS export names for ESM import in node:
134
- 0 && (module.exports = {
135
- LruReader,
136
- close,
137
- init,
138
- readFile,
139
- updateFile
140
- });
@@ -1,123 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
- mod
22
- ));
23
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
24
- var __async = (__this, __arguments, generator) => {
25
- return new Promise((resolve, reject) => {
26
- var fulfilled = (value) => {
27
- try {
28
- step(generator.next(value));
29
- } catch (e) {
30
- reject(e);
31
- }
32
- };
33
- var rejected = (value) => {
34
- try {
35
- step(generator.throw(value));
36
- } catch (e) {
37
- reject(e);
38
- }
39
- };
40
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
41
- step((generator = generator.apply(__this, __arguments)).next());
42
- });
43
- };
44
- var ssr_exports = {};
45
- __export(ssr_exports, {
46
- render: () => render
47
- });
48
- module.exports = __toCommonJS(ssr_exports);
49
- var import_path = __toESM(require("path"));
50
- var import_utils = require("@modern-js/utils");
51
- var import_cookie = __toESM(require("cookie"));
52
- var import_cache = __toESM(require("./cache"));
53
- var import_measure = require("./measure");
54
- const render = (ctx, renderOptions, runner) => __async(void 0, null, function* () {
55
- var _a;
56
- const { urlPath, bundle, distDir, template, entryName, staticGenerate } = renderOptions;
57
- const bundleJS = import_path.default.join(distDir, bundle);
58
- const loadableUri = import_path.default.join(distDir, import_utils.LOADABLE_STATS_FILE);
59
- const loadableStats = import_utils.fs.existsSync(loadableUri) ? require(loadableUri) : "";
60
- const routesManifestUri = import_path.default.join(distDir, import_utils.ROUTE_MINIFEST_FILE);
61
- const routeManifest = import_utils.fs.existsSync(routesManifestUri) ? require(routesManifestUri) : void 0;
62
- const context = {
63
- request: {
64
- baseUrl: urlPath,
65
- params: ctx.params,
66
- pathname: ctx.path,
67
- host: ctx.host,
68
- query: ctx.query,
69
- url: ctx.href,
70
- cookieMap: import_cookie.default.parse(ctx.headers.cookie || ""),
71
- headers: ctx.headers
72
- },
73
- response: {
74
- setHeader: (key, value) => {
75
- return ctx.res.setHeader(key, value);
76
- },
77
- status: (code) => {
78
- ctx.res.statusCode = code;
79
- },
80
- locals: ((_a = ctx.res) == null ? void 0 : _a.locals) || {}
81
- },
82
- redirection: {},
83
- template,
84
- loadableStats,
85
- routeManifest,
86
- entryName,
87
- staticGenerate,
88
- logger: void 0,
89
- metrics: void 0,
90
- req: ctx.req,
91
- res: ctx.res
92
- };
93
- context.logger = (0, import_measure.createLogger)(context, ctx.logger);
94
- context.metrics = (0, import_measure.createMetrics)(context, ctx.metrics);
95
- runner.extendSSRContext(context);
96
- const serverRender = require(bundleJS)[import_utils.SERVER_RENDER_FUNCTION_NAME];
97
- const content = yield (0, import_cache.default)(serverRender, ctx)(context);
98
- const { url, status = 302 } = context.redirection;
99
- if (url) {
100
- return {
101
- content: url,
102
- contentType: "",
103
- statusCode: status,
104
- redirect: true
105
- };
106
- }
107
- if (typeof content === "string") {
108
- return {
109
- content,
110
- contentType: import_utils.mime.contentType("html")
111
- };
112
- } else {
113
- return {
114
- content: "",
115
- contentStream: content,
116
- contentType: import_utils.mime.contentType("html")
117
- };
118
- }
119
- });
120
- // Annotate the CommonJS export names for ESM import in node:
121
- 0 && (module.exports = {
122
- render
123
- });
@@ -1,89 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
- mod
22
- ));
23
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
24
- var __async = (__this, __arguments, generator) => {
25
- return new Promise((resolve, reject) => {
26
- var fulfilled = (value) => {
27
- try {
28
- step(generator.next(value));
29
- } catch (e) {
30
- reject(e);
31
- }
32
- };
33
- var rejected = (value) => {
34
- try {
35
- step(generator.throw(value));
36
- } catch (e) {
37
- reject(e);
38
- }
39
- };
40
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
41
- step((generator = generator.apply(__this, __arguments)).next());
42
- });
43
- };
44
- var static_exports = {};
45
- __export(static_exports, {
46
- handleDirectory: () => handleDirectory
47
- });
48
- module.exports = __toCommonJS(static_exports);
49
- var import_path = __toESM(require("path"));
50
- var import_utils = require("@modern-js/utils");
51
- var import_reader = require("./reader");
52
- function handleDirectory(ctx, entryPath, urlPath) {
53
- return __async(this, null, function* () {
54
- const { path: pathname } = ctx;
55
- const filepath = import_path.default.join(entryPath, trimLeft(pathname, urlPath));
56
- let content = yield (0, import_reader.readFile)(filepath);
57
- let contentType = import_utils.mime.contentType(import_path.default.extname(filepath) || "");
58
- if (!content) {
59
- if (pathname.endsWith("/")) {
60
- content = yield (0, import_reader.readFile)(`${filepath}index.html`);
61
- } else if (!pathname.includes(".")) {
62
- content = yield (0, import_reader.readFile)(`${filepath}.html`);
63
- if (!content) {
64
- content = yield (0, import_reader.readFile)(`${filepath}/index.html`);
65
- }
66
- }
67
- if (content) {
68
- contentType = import_utils.mime.contentType("html");
69
- }
70
- }
71
- if (!content) {
72
- return null;
73
- }
74
- return {
75
- content,
76
- contentType: contentType || ""
77
- };
78
- });
79
- }
80
- const trimLeft = (str, prefix) => {
81
- if (str.startsWith(prefix)) {
82
- return str.substring(prefix.length);
83
- }
84
- return str;
85
- };
86
- // Annotate the CommonJS export names for ESM import in node:
87
- 0 && (module.exports = {
88
- handleDirectory
89
- });
@@ -1,32 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var type_exports = {};
19
- __export(type_exports, {
20
- RenderLevel: () => RenderLevel
21
- });
22
- module.exports = __toCommonJS(type_exports);
23
- var RenderLevel = /* @__PURE__ */ ((RenderLevel2) => {
24
- RenderLevel2[RenderLevel2["CLIENT_RENDER"] = 0] = "CLIENT_RENDER";
25
- RenderLevel2[RenderLevel2["SERVER_PREFETCH"] = 1] = "SERVER_PREFETCH";
26
- RenderLevel2[RenderLevel2["SERVER_RENDER"] = 2] = "SERVER_RENDER";
27
- return RenderLevel2;
28
- })(RenderLevel || {});
29
- // Annotate the CommonJS export names for ESM import in node:
30
- 0 && (module.exports = {
31
- RenderLevel
32
- });
@@ -1,78 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var route_exports = {};
19
- __export(route_exports, {
20
- RouteMatchManager: () => RouteMatchManager,
21
- RouteMatcher: () => import_matcher.RouteMatcher
22
- });
23
- module.exports = __toCommonJS(route_exports);
24
- var import_matcher = require("./matcher");
25
- class RouteMatchManager {
26
- constructor() {
27
- this.specs = [];
28
- this.matchers = [];
29
- }
30
- filter(pathname) {
31
- return this.matchers.reduce((matches, matcher) => {
32
- if (matcher.matchUrlPath(pathname)) {
33
- matches.push(matcher);
34
- }
35
- return matches;
36
- }, []);
37
- }
38
- best(pathname, matches) {
39
- let best;
40
- let matchedLen = 0;
41
- for (const match of matches) {
42
- const len = match.matchLength(pathname);
43
- if (len === null) {
44
- continue;
45
- }
46
- if (len > matchedLen) {
47
- best = match;
48
- matchedLen = len;
49
- }
50
- }
51
- return best;
52
- }
53
- reset(specs) {
54
- this.specs = specs;
55
- const matchers = specs.reduce((ms, spec) => {
56
- ms.push(new import_matcher.RouteMatcher(spec));
57
- return ms;
58
- }, []);
59
- this.matchers = matchers;
60
- }
61
- match(pathname) {
62
- const matches = this.filter(pathname);
63
- const best = this.best(pathname, matches);
64
- return best;
65
- }
66
- matchEntry(entryname) {
67
- return this.matchers.find((matcher) => matcher.matchEntry(entryname));
68
- }
69
- getBundles() {
70
- const bundles = this.specs.filter((route) => route.isSSR).map((route) => route.bundle);
71
- return bundles;
72
- }
73
- }
74
- // Annotate the CommonJS export names for ESM import in node:
75
- 0 && (module.exports = {
76
- RouteMatchManager,
77
- RouteMatcher
78
- });
@@ -1,106 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var matcher_exports = {};
19
- __export(matcher_exports, {
20
- RouteMatcher: () => RouteMatcher
21
- });
22
- module.exports = __toCommonJS(matcher_exports);
23
- var import_path_to_regexp = require("path-to-regexp");
24
- var import_route = require("./route");
25
- const removeTailSlash = (s) => s.replace(/\/+$/, "");
26
- const removeHtmlSuffix = (url) => {
27
- if (url.endsWith(".html")) {
28
- return url.slice(0, -5);
29
- }
30
- return url;
31
- };
32
- const toPath = (reg, params) => {
33
- const fn = (0, import_path_to_regexp.compile)(reg, { encode: encodeURIComponent });
34
- return fn(params);
35
- };
36
- const regCharsDetector = /[^a-zA-Z\-_0-9\/\.]/;
37
- class RouteMatcher {
38
- constructor(spec) {
39
- this.urlPath = "";
40
- this.spec = spec;
41
- this.setupUrlPath();
42
- }
43
- generate(url) {
44
- const route = new import_route.ModernRoute(this.spec);
45
- if (this.urlPath) {
46
- const params = this.parseURLParams(url);
47
- route.urlPath = toPath(route.urlPath, params);
48
- route.params = params;
49
- }
50
- return route;
51
- }
52
- parseURLParams(pathname) {
53
- if (!this.urlMatcher) {
54
- return {};
55
- } else {
56
- const matchResult = this.urlMatcher(pathname);
57
- return matchResult.params;
58
- }
59
- }
60
- matchLength(pathname) {
61
- var _a;
62
- if (!this.urlReg) {
63
- return this.urlPath.length;
64
- } else {
65
- const result = this.urlReg.exec(pathname);
66
- return ((_a = result == null ? void 0 : result[0]) == null ? void 0 : _a.length) || null;
67
- }
68
- }
69
- matchUrlPath(requestUrl) {
70
- let urlWithoutSlash = requestUrl.endsWith("/") && requestUrl !== "/" ? requestUrl.slice(0, -1) : requestUrl;
71
- urlWithoutSlash = removeHtmlSuffix(urlWithoutSlash);
72
- if (this.urlMatcher) {
73
- return Boolean(this.urlMatcher(urlWithoutSlash));
74
- } else {
75
- const urlPath = removeHtmlSuffix(this.urlPath);
76
- if (urlWithoutSlash.startsWith(urlPath)) {
77
- if (urlPath !== "/" && urlWithoutSlash.length > urlPath.length && !urlWithoutSlash.startsWith(`${urlPath}/`)) {
78
- return false;
79
- }
80
- return true;
81
- }
82
- return false;
83
- }
84
- }
85
- matchEntry(entryName) {
86
- return this.spec.entryName === entryName;
87
- }
88
- setupUrlPath() {
89
- const { urlPath } = this.spec;
90
- this.urlPath = urlPath === "/" ? urlPath : removeTailSlash(urlPath);
91
- const useReg = regCharsDetector.test(urlPath);
92
- if (useReg) {
93
- this.urlMatcher = (0, import_path_to_regexp.match)(urlPath, {
94
- end: false,
95
- decode: decodeURIComponent
96
- });
97
- this.urlReg = (0, import_path_to_regexp.pathToRegexp)(urlPath, [], {
98
- end: false
99
- });
100
- }
101
- }
102
- }
103
- // Annotate the CommonJS export names for ESM import in node:
104
- 0 && (module.exports = {
105
- RouteMatcher
106
- });
@@ -1,39 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var route_exports = {};
19
- __export(route_exports, {
20
- ModernRoute: () => ModernRoute
21
- });
22
- module.exports = __toCommonJS(route_exports);
23
- class ModernRoute {
24
- constructor(routeSpec) {
25
- this.params = {};
26
- this.entryName = routeSpec.entryName || "";
27
- this.urlPath = routeSpec.urlPath;
28
- this.entryPath = routeSpec.entryPath || "";
29
- this.isSSR = routeSpec.isSSR || false;
30
- this.isSPA = routeSpec.isSPA || false;
31
- this.isApi = routeSpec.isApi || false;
32
- this.bundle = routeSpec.bundle || "";
33
- this.responseHeaders = routeSpec.responseHeaders;
34
- }
35
- }
36
- // Annotate the CommonJS export names for ESM import in node:
37
- 0 && (module.exports = {
38
- ModernRoute
39
- });