hono 4.0.1 â 4.0.2
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/README.md +3 -3
- package/dist/cjs/client/utils.js +1 -1
- package/dist/cjs/helper/dev/index.js +4 -8
- package/dist/cjs/helper/ssg/index.js +18 -19
- package/dist/cjs/helper/ssg/utils.js +13 -0
- package/dist/cjs/jsx/dom/render.js +3 -2
- package/dist/cjs/router/linear-router/router.js +1 -1
- package/dist/cjs/router/pattern-router/router.js +1 -1
- package/dist/cjs/utils/handler.js +34 -0
- package/dist/client/utils.js +1 -1
- package/dist/helper/dev/index.js +1 -5
- package/dist/helper/ssg/index.js +17 -18
- package/dist/helper/ssg/utils.js +12 -0
- package/dist/jsx/dom/render.js +3 -2
- package/dist/router/linear-router/router.js +1 -1
- package/dist/router/pattern-router/router.js +1 -1
- package/dist/types/helper/factory/index.d.ts +2 -2
- package/dist/types/helper/ssg/index.d.ts +7 -2
- package/dist/types/helper/ssg/utils.d.ts +7 -0
- package/dist/types/utils/handler.d.ts +2 -0
- package/dist/utils/handler.js +10 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
<p align="center">
|
|
10
10
|
<a href="https://hono.dev"><b>Documentation :point_right: hono.dev</b></a><br />
|
|
11
|
-
<i>
|
|
11
|
+
<i>v4 has been released!</i> <a href="docs/MIGRATION.md">Migration guide</b>
|
|
12
12
|
</p>
|
|
13
13
|
|
|
14
14
|
<hr />
|
|
@@ -42,13 +42,13 @@ export default app
|
|
|
42
42
|
## Quick Start
|
|
43
43
|
|
|
44
44
|
```
|
|
45
|
-
npm create hono@latest
|
|
45
|
+
npm create hono@latest
|
|
46
46
|
```
|
|
47
47
|
|
|
48
48
|
## Features
|
|
49
49
|
|
|
50
50
|
- **Ultrafast** ð - The router `RegExpRouter` is really fast. Not using linear loops. Fast.
|
|
51
|
-
- **Lightweight** ðŠķ - The `hono/tiny` preset is under
|
|
51
|
+
- **Lightweight** ðŠķ - The `hono/tiny` preset is under 13kB. Hono has zero dependencies and uses only the Web Standard API.
|
|
52
52
|
- **Multi-runtime** ð - Works on Cloudflare Workers, Fastly Compute, Deno, Bun, AWS Lambda, Lambda@Edge, or Node.js. The same code runs on all platforms.
|
|
53
53
|
- **Batteries Included** ð - Hono has built-in middleware, custom middleware, and third-party middleware. Batteries included.
|
|
54
54
|
- **Delightful DX** ð - Super clean APIs. First-class TypeScript support. Now, we've got "Types".
|
package/dist/cjs/client/utils.js
CHANGED
|
@@ -32,7 +32,7 @@ const mergePath = (base, path) => {
|
|
|
32
32
|
};
|
|
33
33
|
const replaceUrlParam = (urlString, params) => {
|
|
34
34
|
for (const [k, v] of Object.entries(params)) {
|
|
35
|
-
const reg = new RegExp("/:" + k + "({[
|
|
35
|
+
const reg = new RegExp("/:" + k + "(?:{[^/]+})?");
|
|
36
36
|
urlString = urlString.replace(reg, `/${v}`);
|
|
37
37
|
}
|
|
38
38
|
return urlString;
|
|
@@ -23,22 +23,18 @@ __export(dev_exports, {
|
|
|
23
23
|
showRoutes: () => showRoutes
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(dev_exports);
|
|
26
|
-
var
|
|
27
|
-
const isMiddleware = (handler) => handler.length > 1;
|
|
26
|
+
var import_handler = require("../../utils/handler");
|
|
28
27
|
const handlerName = (handler) => {
|
|
29
|
-
return handler.name || (isMiddleware(handler) ? "[middleware]" : "[handler]");
|
|
30
|
-
};
|
|
31
|
-
const findTargetHandler = (handler) => {
|
|
32
|
-
return handler[import_hono_base.COMPOSED_HANDLER] ? findTargetHandler(handler[import_hono_base.COMPOSED_HANDLER]) : handler;
|
|
28
|
+
return handler.name || ((0, import_handler.isMiddleware)(handler) ? "[middleware]" : "[handler]");
|
|
33
29
|
};
|
|
34
30
|
const inspectRoutes = (hono) => {
|
|
35
31
|
return hono.routes.map(({ path, method, handler }) => {
|
|
36
|
-
const targetHandler = findTargetHandler(handler);
|
|
32
|
+
const targetHandler = (0, import_handler.findTargetHandler)(handler);
|
|
37
33
|
return {
|
|
38
34
|
path,
|
|
39
35
|
method,
|
|
40
36
|
name: handlerName(targetHandler),
|
|
41
|
-
isMiddleware: isMiddleware(targetHandler)
|
|
37
|
+
isMiddleware: (0, import_handler.isMiddleware)(targetHandler)
|
|
42
38
|
};
|
|
43
39
|
});
|
|
44
40
|
};
|
|
@@ -18,10 +18,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var ssg_exports = {};
|
|
20
20
|
__export(ssg_exports, {
|
|
21
|
-
|
|
22
|
-
X_HONO_SSG_HEADER_KEY: () => X_HONO_SSG_HEADER_KEY,
|
|
21
|
+
SSG_DISABLED_RESPONSE: () => SSG_DISABLED_RESPONSE,
|
|
23
22
|
disableSSG: () => disableSSG,
|
|
24
23
|
fetchRoutesContent: () => fetchRoutesContent,
|
|
24
|
+
isSSGContext: () => isSSGContext,
|
|
25
25
|
onlySSG: () => onlySSG,
|
|
26
26
|
saveContentToFiles: () => saveContentToFiles,
|
|
27
27
|
ssgParams: () => ssgParams,
|
|
@@ -29,12 +29,11 @@ __export(ssg_exports, {
|
|
|
29
29
|
});
|
|
30
30
|
module.exports = __toCommonJS(ssg_exports);
|
|
31
31
|
var import_utils = require("../../client/utils");
|
|
32
|
-
var import_dev = require("../../helper/dev");
|
|
33
32
|
var import_buffer = require("../../utils/buffer");
|
|
34
33
|
var import_mime = require("../../utils/mime");
|
|
35
34
|
var import_utils2 = require("./utils");
|
|
36
|
-
const
|
|
37
|
-
const
|
|
35
|
+
const SSG_CONTEXT = "HONO_SSG_CONTEXT";
|
|
36
|
+
const SSG_DISABLED_RESPONSE = new Response("SSG is disabled", { status: 404 });
|
|
38
37
|
const generateFilePath = (routePath, outDir, mimeType) => {
|
|
39
38
|
const extension = determineExtension(mimeType);
|
|
40
39
|
if (routePath === "/") {
|
|
@@ -79,13 +78,9 @@ const ssgParams = (params) => async (c, next) => {
|
|
|
79
78
|
const fetchRoutesContent = async (app, beforeRequestHook, afterResponseHook) => {
|
|
80
79
|
const htmlMap = /* @__PURE__ */ new Map();
|
|
81
80
|
const baseURL = "http://localhost";
|
|
82
|
-
for (const route of (0,
|
|
83
|
-
if (route.isMiddleware) {
|
|
84
|
-
continue;
|
|
85
|
-
}
|
|
81
|
+
for (const route of (0, import_utils2.filterStaticGenerateRoutes)(app)) {
|
|
86
82
|
const thisRouteBaseURL = new URL(route.path, baseURL).toString();
|
|
87
83
|
let forGetInfoURLRequest = new Request(thisRouteBaseURL);
|
|
88
|
-
forGetInfoURLRequest.headers.set(X_HONO_SSG_HEADER_KEY, "true");
|
|
89
84
|
if (beforeRequestHook) {
|
|
90
85
|
const maybeRequest = beforeRequestHook(forGetInfoURLRequest);
|
|
91
86
|
if (!maybeRequest) {
|
|
@@ -106,8 +101,10 @@ const fetchRoutesContent = async (app, beforeRequestHook, afterResponseHook) =>
|
|
|
106
101
|
};
|
|
107
102
|
for (const param of forGetInfoURLRequest.ssgParams) {
|
|
108
103
|
const replacedUrlParam = (0, import_utils.replaceUrlParam)(route.path, param);
|
|
109
|
-
let response = await app.request(replacedUrlParam, requestInit
|
|
110
|
-
|
|
104
|
+
let response = await app.request(replacedUrlParam, requestInit, {
|
|
105
|
+
[SSG_CONTEXT]: true
|
|
106
|
+
});
|
|
107
|
+
if (response === SSG_DISABLED_RESPONSE) {
|
|
111
108
|
continue;
|
|
112
109
|
}
|
|
113
110
|
if (afterResponseHook) {
|
|
@@ -163,23 +160,25 @@ const toSSG = async (app, fs, options) => {
|
|
|
163
160
|
await options?.afterGenerateHook?.(result);
|
|
164
161
|
return result;
|
|
165
162
|
};
|
|
163
|
+
const isSSGContext = (c) => !!c.env?.[SSG_CONTEXT];
|
|
166
164
|
const disableSSG = () => async function disableSSG2(c, next) {
|
|
165
|
+
if (isSSGContext(c)) {
|
|
166
|
+
return SSG_DISABLED_RESPONSE;
|
|
167
|
+
}
|
|
167
168
|
await next();
|
|
168
|
-
c.header(X_HONO_DISABLE_SSG_HEADER_KEY, "true");
|
|
169
169
|
};
|
|
170
170
|
const onlySSG = () => async function onlySSG2(c, next) {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
await next();
|
|
171
|
+
if (!isSSGContext(c)) {
|
|
172
|
+
return c.notFound();
|
|
174
173
|
}
|
|
175
|
-
|
|
174
|
+
await next();
|
|
176
175
|
};
|
|
177
176
|
// Annotate the CommonJS export names for ESM import in node:
|
|
178
177
|
0 && (module.exports = {
|
|
179
|
-
|
|
180
|
-
X_HONO_SSG_HEADER_KEY,
|
|
178
|
+
SSG_DISABLED_RESPONSE,
|
|
181
179
|
disableSSG,
|
|
182
180
|
fetchRoutesContent,
|
|
181
|
+
isSSGContext,
|
|
183
182
|
onlySSG,
|
|
184
183
|
saveContentToFiles,
|
|
185
184
|
ssgParams,
|
|
@@ -19,9 +19,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
var utils_exports = {};
|
|
20
20
|
__export(utils_exports, {
|
|
21
21
|
dirname: () => dirname,
|
|
22
|
+
filterStaticGenerateRoutes: () => filterStaticGenerateRoutes,
|
|
22
23
|
joinPaths: () => joinPaths
|
|
23
24
|
});
|
|
24
25
|
module.exports = __toCommonJS(utils_exports);
|
|
26
|
+
var import_router = require("../../router");
|
|
27
|
+
var import_handler = require("../../utils/handler");
|
|
25
28
|
const dirname = (path) => {
|
|
26
29
|
const splitedPath = path.split(/[\/\\]/);
|
|
27
30
|
return splitedPath.slice(0, -1).join("/");
|
|
@@ -57,8 +60,18 @@ const joinPaths = (...paths) => {
|
|
|
57
60
|
handleSegments(paths.join("/").split("/"), resultPaths);
|
|
58
61
|
return (paths[0][0] === "/" ? "/" : "") + resultPaths.join("/");
|
|
59
62
|
};
|
|
63
|
+
const filterStaticGenerateRoutes = (hono) => {
|
|
64
|
+
return hono.routes.reduce((acc, { method, handler, path }) => {
|
|
65
|
+
const targetHandler = (0, import_handler.findTargetHandler)(handler);
|
|
66
|
+
if (["GET", import_router.METHOD_NAME_ALL].includes(method) && !(0, import_handler.isMiddleware)(targetHandler)) {
|
|
67
|
+
acc.push({ path });
|
|
68
|
+
}
|
|
69
|
+
return acc;
|
|
70
|
+
}, []);
|
|
71
|
+
};
|
|
60
72
|
// Annotate the CommonJS export names for ESM import in node:
|
|
61
73
|
0 && (module.exports = {
|
|
62
74
|
dirname,
|
|
75
|
+
filterStaticGenerateRoutes,
|
|
63
76
|
joinPaths
|
|
64
77
|
});
|
|
@@ -193,6 +193,7 @@ const applyNodeObject = (node, container) => {
|
|
|
193
193
|
}
|
|
194
194
|
}
|
|
195
195
|
}
|
|
196
|
+
const childNodes = container.childNodes;
|
|
196
197
|
for (let i = 0, len = next.length; i < len; i++, offset++) {
|
|
197
198
|
const child = next[i];
|
|
198
199
|
let el;
|
|
@@ -206,8 +207,8 @@ const applyNodeObject = (node, container) => {
|
|
|
206
207
|
applyProps(el, child.props, child.pP);
|
|
207
208
|
applyNode(child, el);
|
|
208
209
|
}
|
|
209
|
-
if (
|
|
210
|
-
container.insertBefore(el,
|
|
210
|
+
if (childNodes[offset] !== el && childNodes[offset - 1] !== child.e) {
|
|
211
|
+
container.insertBefore(el, childNodes[offset] || null);
|
|
211
212
|
}
|
|
212
213
|
}
|
|
213
214
|
remove.forEach(removeNode);
|
|
@@ -24,7 +24,7 @@ module.exports = __toCommonJS(router_exports);
|
|
|
24
24
|
var import_router = require("../../router");
|
|
25
25
|
var import_url = require("../../utils/url");
|
|
26
26
|
const emptyParams = {};
|
|
27
|
-
const splitPathRe = /\/(:\w+(?:{[^}]+})?)|\/[^\/\?]+|(\?)/g;
|
|
27
|
+
const splitPathRe = /\/(:\w+(?:{(?:(?:{[\d,]+})|[^}])+})?)|\/[^\/\?]+|(\?)/g;
|
|
28
28
|
const splitByStarRe = /\*/;
|
|
29
29
|
class LinearRouter {
|
|
30
30
|
constructor() {
|
|
@@ -32,7 +32,7 @@ class PatternRouter {
|
|
|
32
32
|
if (endsWithWildcard) {
|
|
33
33
|
path = path.slice(0, -2);
|
|
34
34
|
}
|
|
35
|
-
const parts = path.match(/\/?(:\w+(?:{[^}]+})?)|\/?[^\/\?]+|(\?)/g) || [];
|
|
35
|
+
const parts = path.match(/\/?(:\w+(?:{(?:(?:{[\d,]+})|[^}])+})?)|\/?[^\/\?]+|(\?)/g) || [];
|
|
36
36
|
if (parts[parts.length - 1] === "?") {
|
|
37
37
|
this.add(method, parts.slice(0, parts.length - 2).join(""), handler);
|
|
38
38
|
parts.pop();
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var handler_exports = {};
|
|
20
|
+
__export(handler_exports, {
|
|
21
|
+
findTargetHandler: () => findTargetHandler,
|
|
22
|
+
isMiddleware: () => isMiddleware
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(handler_exports);
|
|
25
|
+
var import_hono_base = require("../hono-base");
|
|
26
|
+
const isMiddleware = (handler) => handler.length > 1;
|
|
27
|
+
const findTargetHandler = (handler) => {
|
|
28
|
+
return handler[import_hono_base.COMPOSED_HANDLER] ? findTargetHandler(handler[import_hono_base.COMPOSED_HANDLER]) : handler;
|
|
29
|
+
};
|
|
30
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
31
|
+
0 && (module.exports = {
|
|
32
|
+
findTargetHandler,
|
|
33
|
+
isMiddleware
|
|
34
|
+
});
|
package/dist/client/utils.js
CHANGED
|
@@ -7,7 +7,7 @@ var mergePath = (base, path) => {
|
|
|
7
7
|
};
|
|
8
8
|
var replaceUrlParam = (urlString, params) => {
|
|
9
9
|
for (const [k, v] of Object.entries(params)) {
|
|
10
|
-
const reg = new RegExp("/:" + k + "({[
|
|
10
|
+
const reg = new RegExp("/:" + k + "(?:{[^/]+})?");
|
|
11
11
|
urlString = urlString.replace(reg, `/${v}`);
|
|
12
12
|
}
|
|
13
13
|
return urlString;
|
package/dist/helper/dev/index.js
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
// src/helper/dev/index.ts
|
|
2
|
-
import {
|
|
3
|
-
var isMiddleware = (handler) => handler.length > 1;
|
|
2
|
+
import { findTargetHandler, isMiddleware } from "../../utils/handler.js";
|
|
4
3
|
var handlerName = (handler) => {
|
|
5
4
|
return handler.name || (isMiddleware(handler) ? "[middleware]" : "[handler]");
|
|
6
5
|
};
|
|
7
|
-
var findTargetHandler = (handler) => {
|
|
8
|
-
return handler[COMPOSED_HANDLER] ? findTargetHandler(handler[COMPOSED_HANDLER]) : handler;
|
|
9
|
-
};
|
|
10
6
|
var inspectRoutes = (hono) => {
|
|
11
7
|
return hono.routes.map(({ path, method, handler }) => {
|
|
12
8
|
const targetHandler = findTargetHandler(handler);
|
package/dist/helper/ssg/index.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
// src/helper/ssg/index.ts
|
|
2
2
|
import { replaceUrlParam } from "../../client/utils.js";
|
|
3
|
-
import { inspectRoutes } from "../../helper/dev/index.js";
|
|
4
3
|
import { bufferToString } from "../../utils/buffer.js";
|
|
5
4
|
import { getExtension } from "../../utils/mime.js";
|
|
6
|
-
import { joinPaths, dirname } from "./utils.js";
|
|
7
|
-
var
|
|
8
|
-
var
|
|
5
|
+
import { joinPaths, dirname, filterStaticGenerateRoutes } from "./utils.js";
|
|
6
|
+
var SSG_CONTEXT = "HONO_SSG_CONTEXT";
|
|
7
|
+
var SSG_DISABLED_RESPONSE = new Response("SSG is disabled", { status: 404 });
|
|
9
8
|
var generateFilePath = (routePath, outDir, mimeType) => {
|
|
10
9
|
const extension = determineExtension(mimeType);
|
|
11
10
|
if (routePath === "/") {
|
|
@@ -50,13 +49,9 @@ var ssgParams = (params) => async (c, next) => {
|
|
|
50
49
|
var fetchRoutesContent = async (app, beforeRequestHook, afterResponseHook) => {
|
|
51
50
|
const htmlMap = /* @__PURE__ */ new Map();
|
|
52
51
|
const baseURL = "http://localhost";
|
|
53
|
-
for (const route of
|
|
54
|
-
if (route.isMiddleware) {
|
|
55
|
-
continue;
|
|
56
|
-
}
|
|
52
|
+
for (const route of filterStaticGenerateRoutes(app)) {
|
|
57
53
|
const thisRouteBaseURL = new URL(route.path, baseURL).toString();
|
|
58
54
|
let forGetInfoURLRequest = new Request(thisRouteBaseURL);
|
|
59
|
-
forGetInfoURLRequest.headers.set(X_HONO_SSG_HEADER_KEY, "true");
|
|
60
55
|
if (beforeRequestHook) {
|
|
61
56
|
const maybeRequest = beforeRequestHook(forGetInfoURLRequest);
|
|
62
57
|
if (!maybeRequest) {
|
|
@@ -77,8 +72,10 @@ var fetchRoutesContent = async (app, beforeRequestHook, afterResponseHook) => {
|
|
|
77
72
|
};
|
|
78
73
|
for (const param of forGetInfoURLRequest.ssgParams) {
|
|
79
74
|
const replacedUrlParam = replaceUrlParam(route.path, param);
|
|
80
|
-
let response = await app.request(replacedUrlParam, requestInit
|
|
81
|
-
|
|
75
|
+
let response = await app.request(replacedUrlParam, requestInit, {
|
|
76
|
+
[SSG_CONTEXT]: true
|
|
77
|
+
});
|
|
78
|
+
if (response === SSG_DISABLED_RESPONSE) {
|
|
82
79
|
continue;
|
|
83
80
|
}
|
|
84
81
|
if (afterResponseHook) {
|
|
@@ -134,22 +131,24 @@ var toSSG = async (app, fs, options) => {
|
|
|
134
131
|
await options?.afterGenerateHook?.(result);
|
|
135
132
|
return result;
|
|
136
133
|
};
|
|
134
|
+
var isSSGContext = (c) => !!c.env?.[SSG_CONTEXT];
|
|
137
135
|
var disableSSG = () => async function disableSSG2(c, next) {
|
|
136
|
+
if (isSSGContext(c)) {
|
|
137
|
+
return SSG_DISABLED_RESPONSE;
|
|
138
|
+
}
|
|
138
139
|
await next();
|
|
139
|
-
c.header(X_HONO_DISABLE_SSG_HEADER_KEY, "true");
|
|
140
140
|
};
|
|
141
141
|
var onlySSG = () => async function onlySSG2(c, next) {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
await next();
|
|
142
|
+
if (!isSSGContext(c)) {
|
|
143
|
+
return c.notFound();
|
|
145
144
|
}
|
|
146
|
-
|
|
145
|
+
await next();
|
|
147
146
|
};
|
|
148
147
|
export {
|
|
149
|
-
|
|
150
|
-
X_HONO_SSG_HEADER_KEY,
|
|
148
|
+
SSG_DISABLED_RESPONSE,
|
|
151
149
|
disableSSG,
|
|
152
150
|
fetchRoutesContent,
|
|
151
|
+
isSSGContext,
|
|
153
152
|
onlySSG,
|
|
154
153
|
saveContentToFiles,
|
|
155
154
|
ssgParams,
|
package/dist/helper/ssg/utils.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
// src/helper/ssg/utils.ts
|
|
2
|
+
import { METHOD_NAME_ALL } from "../../router.js";
|
|
3
|
+
import { findTargetHandler, isMiddleware } from "../../utils/handler.js";
|
|
2
4
|
var dirname = (path) => {
|
|
3
5
|
const splitedPath = path.split(/[\/\\]/);
|
|
4
6
|
return splitedPath.slice(0, -1).join("/");
|
|
@@ -34,7 +36,17 @@ var joinPaths = (...paths) => {
|
|
|
34
36
|
handleSegments(paths.join("/").split("/"), resultPaths);
|
|
35
37
|
return (paths[0][0] === "/" ? "/" : "") + resultPaths.join("/");
|
|
36
38
|
};
|
|
39
|
+
var filterStaticGenerateRoutes = (hono) => {
|
|
40
|
+
return hono.routes.reduce((acc, { method, handler, path }) => {
|
|
41
|
+
const targetHandler = findTargetHandler(handler);
|
|
42
|
+
if (["GET", METHOD_NAME_ALL].includes(method) && !isMiddleware(targetHandler)) {
|
|
43
|
+
acc.push({ path });
|
|
44
|
+
}
|
|
45
|
+
return acc;
|
|
46
|
+
}, []);
|
|
47
|
+
};
|
|
37
48
|
export {
|
|
38
49
|
dirname,
|
|
50
|
+
filterStaticGenerateRoutes,
|
|
39
51
|
joinPaths
|
|
40
52
|
};
|
package/dist/jsx/dom/render.js
CHANGED
|
@@ -168,6 +168,7 @@ var applyNodeObject = (node, container) => {
|
|
|
168
168
|
}
|
|
169
169
|
}
|
|
170
170
|
}
|
|
171
|
+
const childNodes = container.childNodes;
|
|
171
172
|
for (let i = 0, len = next.length; i < len; i++, offset++) {
|
|
172
173
|
const child = next[i];
|
|
173
174
|
let el;
|
|
@@ -181,8 +182,8 @@ var applyNodeObject = (node, container) => {
|
|
|
181
182
|
applyProps(el, child.props, child.pP);
|
|
182
183
|
applyNode(child, el);
|
|
183
184
|
}
|
|
184
|
-
if (
|
|
185
|
-
container.insertBefore(el,
|
|
185
|
+
if (childNodes[offset] !== el && childNodes[offset - 1] !== child.e) {
|
|
186
|
+
container.insertBefore(el, childNodes[offset] || null);
|
|
186
187
|
}
|
|
187
188
|
}
|
|
188
189
|
remove.forEach(removeNode);
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { METHOD_NAME_ALL, UnsupportedPathError } from "../../router.js";
|
|
3
3
|
import { checkOptionalParameter } from "../../utils/url.js";
|
|
4
4
|
var emptyParams = {};
|
|
5
|
-
var splitPathRe = /\/(:\w+(?:{[^}]+})?)|\/[^\/\?]+|(\?)/g;
|
|
5
|
+
var splitPathRe = /\/(:\w+(?:{(?:(?:{[\d,]+})|[^}])+})?)|\/[^\/\?]+|(\?)/g;
|
|
6
6
|
var splitByStarRe = /\*/;
|
|
7
7
|
var LinearRouter = class {
|
|
8
8
|
constructor() {
|
|
@@ -10,7 +10,7 @@ var PatternRouter = class {
|
|
|
10
10
|
if (endsWithWildcard) {
|
|
11
11
|
path = path.slice(0, -2);
|
|
12
12
|
}
|
|
13
|
-
const parts = path.match(/\/?(:\w+(?:{[^}]+})?)|\/?[^\/\?]+|(\?)/g) || [];
|
|
13
|
+
const parts = path.match(/\/?(:\w+(?:{(?:(?:{[\d,]+})|[^}])+})?)|\/?[^\/\?]+|(\?)/g) || [];
|
|
14
14
|
if (parts[parts.length - 1] === "?") {
|
|
15
15
|
this.add(method, parts.slice(0, parts.length - 2).join(""), handler);
|
|
16
16
|
parts.pop();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { Env,
|
|
1
|
+
import type { Env, H, HandlerResponse, Input, MiddlewareHandler } from '../../types';
|
|
2
2
|
export declare class Factory<E extends Env = any, P extends string = any> {
|
|
3
3
|
createMiddleware: <I extends Input = {}>(middleware: MiddlewareHandler<E, P, I>) => MiddlewareHandler<E, P, I>;
|
|
4
|
-
createHandlers<I extends Input = {}>(handler1: H<E, P, I>): [H<E, P, I>];
|
|
4
|
+
createHandlers<I extends Input = {}, R extends HandlerResponse<any> = any>(handler1: H<E, P, I, R>): [H<E, P, I, R>];
|
|
5
5
|
createHandlers<I extends Input = {}, I2 extends Input = I, R extends HandlerResponse<any> = any>(handler1: H<E, P, I, R>, handler2: H<E, P, I2, R>): [H<E, P, I, R>, H<E, P, I2, R>];
|
|
6
6
|
createHandlers<I extends Input = {}, I2 extends Input = I, I3 extends Input = I & I2, R extends HandlerResponse<any> = any>(handler1: H<E, P, I, R>, handler2: H<E, P, I2, R>, handler3: H<E, P, I3, R>): [H<E, P, I, R>, H<E, P, I2, R>, H<E, P, I3, R>];
|
|
7
7
|
createHandlers<I extends Input = {}, I2 extends Input = I, I3 extends Input = I & I2, I4 extends Input = I & I2 & I3, R extends HandlerResponse<any> = any>(handler1: H<E, P, I, R>, handler2: H<E, P, I2, R>, handler3: H<E, P, I3, R>, handler4: H<E, P, I4, R>): [H<E, P, I, R>, H<E, P, I2, R>, H<E, P, I3, R>, H<E, P, I4, R>];
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import type { Context } from '../../context';
|
|
2
2
|
import type { Hono } from '../../hono';
|
|
3
3
|
import type { Env, MiddlewareHandler, Schema } from '../../types';
|
|
4
|
-
export declare const
|
|
5
|
-
export declare const X_HONO_DISABLE_SSG_HEADER_KEY = "x-hono-disable-ssg";
|
|
4
|
+
export declare const SSG_DISABLED_RESPONSE: Response;
|
|
6
5
|
/**
|
|
7
6
|
* @experimental
|
|
8
7
|
* `FileSystemModule` is an experimental feature.
|
|
@@ -85,6 +84,12 @@ export interface ToSSGAdaptorInterface<E extends Env = Env, S extends Schema = {
|
|
|
85
84
|
* The API might be changed.
|
|
86
85
|
*/
|
|
87
86
|
export declare const toSSG: ToSSGInterface;
|
|
87
|
+
/**
|
|
88
|
+
* @experimental
|
|
89
|
+
* `isSSGContext` is an experimental feature.
|
|
90
|
+
* The API might be changed.
|
|
91
|
+
*/
|
|
92
|
+
export declare const isSSGContext: (c: Context) => boolean;
|
|
88
93
|
/**
|
|
89
94
|
* @experimental
|
|
90
95
|
* `disableSSG` is an experimental feature.
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { Hono } from '../../hono';
|
|
2
|
+
import type { Env } from '../../types';
|
|
1
3
|
/**
|
|
2
4
|
* Get dirname
|
|
3
5
|
* @param path File Path
|
|
@@ -5,3 +7,8 @@
|
|
|
5
7
|
*/
|
|
6
8
|
export declare const dirname: (path: string) => string;
|
|
7
9
|
export declare const joinPaths: (...paths: string[]) => string;
|
|
10
|
+
interface FilterStaticGenerateRouteData {
|
|
11
|
+
path: string;
|
|
12
|
+
}
|
|
13
|
+
export declare const filterStaticGenerateRoutes: <E extends Env>(hono: Hono<E, import("../../types").BlankSchema, "/">) => FilterStaticGenerateRouteData[];
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// src/utils/handler.ts
|
|
2
|
+
import { COMPOSED_HANDLER } from "../hono-base.js";
|
|
3
|
+
var isMiddleware = (handler) => handler.length > 1;
|
|
4
|
+
var findTargetHandler = (handler) => {
|
|
5
|
+
return handler[COMPOSED_HANDLER] ? findTargetHandler(handler[COMPOSED_HANDLER]) : handler;
|
|
6
|
+
};
|
|
7
|
+
export {
|
|
8
|
+
findTargetHandler,
|
|
9
|
+
isMiddleware
|
|
10
|
+
};
|