Comparing version 4.0.1 to 4.0.2
@@ -35,3 +35,3 @@ "use strict"; | ||
for (const [k, v] of Object.entries(params)) { | ||
const reg = new RegExp("/:" + k + "({[^}]*})?"); | ||
const reg = new RegExp("/:" + k + "(?:{[^/]+})?"); | ||
urlString = urlString.replace(reg, `/${v}`); | ||
@@ -38,0 +38,0 @@ } |
@@ -26,13 +26,9 @@ "use strict"; | ||
module.exports = __toCommonJS(dev_exports); | ||
var import_hono_base = require("../../hono-base"); | ||
const isMiddleware = (handler) => handler.length > 1; | ||
var import_handler = require("../../utils/handler"); | ||
const handlerName = (handler) => { | ||
return handler.name || (isMiddleware(handler) ? "[middleware]" : "[handler]"); | ||
return handler.name || ((0, import_handler.isMiddleware)(handler) ? "[middleware]" : "[handler]"); | ||
}; | ||
const findTargetHandler = (handler) => { | ||
return handler[import_hono_base.COMPOSED_HANDLER] ? findTargetHandler(handler[import_hono_base.COMPOSED_HANDLER]) : handler; | ||
}; | ||
const inspectRoutes = (hono) => { | ||
return hono.routes.map(({ path, method, handler }) => { | ||
const targetHandler = findTargetHandler(handler); | ||
const targetHandler = (0, import_handler.findTargetHandler)(handler); | ||
return { | ||
@@ -42,3 +38,3 @@ path, | ||
name: handlerName(targetHandler), | ||
isMiddleware: isMiddleware(targetHandler) | ||
isMiddleware: (0, import_handler.isMiddleware)(targetHandler) | ||
}; | ||
@@ -45,0 +41,0 @@ }); |
@@ -21,6 +21,6 @@ "use strict"; | ||
__export(ssg_exports, { | ||
X_HONO_DISABLE_SSG_HEADER_KEY: () => X_HONO_DISABLE_SSG_HEADER_KEY, | ||
X_HONO_SSG_HEADER_KEY: () => X_HONO_SSG_HEADER_KEY, | ||
SSG_DISABLED_RESPONSE: () => SSG_DISABLED_RESPONSE, | ||
disableSSG: () => disableSSG, | ||
fetchRoutesContent: () => fetchRoutesContent, | ||
isSSGContext: () => isSSGContext, | ||
onlySSG: () => onlySSG, | ||
@@ -33,8 +33,7 @@ saveContentToFiles: () => saveContentToFiles, | ||
var import_utils = require("../../client/utils"); | ||
var import_dev = require("../../helper/dev"); | ||
var import_buffer = require("../../utils/buffer"); | ||
var import_mime = require("../../utils/mime"); | ||
var import_utils2 = require("./utils"); | ||
const X_HONO_SSG_HEADER_KEY = "x-hono-ssg"; | ||
const X_HONO_DISABLE_SSG_HEADER_KEY = "x-hono-disable-ssg"; | ||
const SSG_CONTEXT = "HONO_SSG_CONTEXT"; | ||
const SSG_DISABLED_RESPONSE = new Response("SSG is disabled", { status: 404 }); | ||
const generateFilePath = (routePath, outDir, mimeType) => { | ||
@@ -84,9 +83,5 @@ const extension = determineExtension(mimeType); | ||
const baseURL = "http://localhost"; | ||
for (const route of (0, import_dev.inspectRoutes)(app)) { | ||
if (route.isMiddleware) { | ||
continue; | ||
} | ||
for (const route of (0, import_utils2.filterStaticGenerateRoutes)(app)) { | ||
const thisRouteBaseURL = new URL(route.path, baseURL).toString(); | ||
let forGetInfoURLRequest = new Request(thisRouteBaseURL); | ||
forGetInfoURLRequest.headers.set(X_HONO_SSG_HEADER_KEY, "true"); | ||
if (beforeRequestHook) { | ||
@@ -112,4 +107,6 @@ const maybeRequest = beforeRequestHook(forGetInfoURLRequest); | ||
const replacedUrlParam = (0, import_utils.replaceUrlParam)(route.path, param); | ||
let response = await app.request(replacedUrlParam, requestInit); | ||
if (response.headers.get(X_HONO_DISABLE_SSG_HEADER_KEY)) { | ||
let response = await app.request(replacedUrlParam, requestInit, { | ||
[SSG_CONTEXT]: true | ||
}); | ||
if (response === SSG_DISABLED_RESPONSE) { | ||
continue; | ||
@@ -170,19 +167,21 @@ } | ||
}; | ||
const isSSGContext = (c) => !!c.env?.[SSG_CONTEXT]; | ||
const disableSSG = () => async function disableSSG2(c, next) { | ||
if (isSSGContext(c)) { | ||
return SSG_DISABLED_RESPONSE; | ||
} | ||
await next(); | ||
c.header(X_HONO_DISABLE_SSG_HEADER_KEY, "true"); | ||
}; | ||
const onlySSG = () => async function onlySSG2(c, next) { | ||
const headerValue = c.req.raw.headers.get(X_HONO_SSG_HEADER_KEY); | ||
if (headerValue) { | ||
await next(); | ||
if (!isSSGContext(c)) { | ||
return c.notFound(); | ||
} | ||
return c.notFound(); | ||
await next(); | ||
}; | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
X_HONO_DISABLE_SSG_HEADER_KEY, | ||
X_HONO_SSG_HEADER_KEY, | ||
SSG_DISABLED_RESPONSE, | ||
disableSSG, | ||
fetchRoutesContent, | ||
isSSGContext, | ||
onlySSG, | ||
@@ -189,0 +188,0 @@ saveContentToFiles, |
@@ -22,5 +22,8 @@ "use strict"; | ||
dirname: () => dirname, | ||
filterStaticGenerateRoutes: () => filterStaticGenerateRoutes, | ||
joinPaths: () => joinPaths | ||
}); | ||
module.exports = __toCommonJS(utils_exports); | ||
var import_router = require("../../router"); | ||
var import_handler = require("../../utils/handler"); | ||
const dirname = (path) => { | ||
@@ -61,6 +64,16 @@ const splitedPath = path.split(/[\/\\]/); | ||
}; | ||
const filterStaticGenerateRoutes = (hono) => { | ||
return hono.routes.reduce((acc, { method, handler, path }) => { | ||
const targetHandler = (0, import_handler.findTargetHandler)(handler); | ||
if (["GET", import_router.METHOD_NAME_ALL].includes(method) && !(0, import_handler.isMiddleware)(targetHandler)) { | ||
acc.push({ path }); | ||
} | ||
return acc; | ||
}, []); | ||
}; | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
dirname, | ||
filterStaticGenerateRoutes, | ||
joinPaths | ||
}); |
@@ -196,2 +196,3 @@ "use strict"; | ||
} | ||
const childNodes = container.childNodes; | ||
for (let i = 0, len = next.length; i < len; i++, offset++) { | ||
@@ -210,4 +211,4 @@ const child = next[i]; | ||
} | ||
if (container.childNodes[offset] !== el) { | ||
container.insertBefore(el, container.childNodes[offset] || null); | ||
if (childNodes[offset] !== el && childNodes[offset - 1] !== child.e) { | ||
container.insertBefore(el, childNodes[offset] || null); | ||
} | ||
@@ -214,0 +215,0 @@ } |
@@ -27,3 +27,3 @@ "use strict"; | ||
const emptyParams = {}; | ||
const splitPathRe = /\/(:\w+(?:{[^}]+})?)|\/[^\/\?]+|(\?)/g; | ||
const splitPathRe = /\/(:\w+(?:{(?:(?:{[\d,]+})|[^}])+})?)|\/[^\/\?]+|(\?)/g; | ||
const splitByStarRe = /\*/; | ||
@@ -30,0 +30,0 @@ class LinearRouter { |
@@ -35,3 +35,3 @@ "use strict"; | ||
} | ||
const parts = path.match(/\/?(:\w+(?:{[^}]+})?)|\/?[^\/\?]+|(\?)/g) || []; | ||
const parts = path.match(/\/?(:\w+(?:{(?:(?:{[\d,]+})|[^}])+})?)|\/?[^\/\?]+|(\?)/g) || []; | ||
if (parts[parts.length - 1] === "?") { | ||
@@ -38,0 +38,0 @@ this.add(method, parts.slice(0, parts.length - 2).join(""), handler); |
@@ -10,3 +10,3 @@ // src/client/utils.ts | ||
for (const [k, v] of Object.entries(params)) { | ||
const reg = new RegExp("/:" + k + "({[^}]*})?"); | ||
const reg = new RegExp("/:" + k + "(?:{[^/]+})?"); | ||
urlString = urlString.replace(reg, `/${v}`); | ||
@@ -13,0 +13,0 @@ } |
// src/helper/dev/index.ts | ||
import { COMPOSED_HANDLER } from "../../hono-base.js"; | ||
var isMiddleware = (handler) => handler.length > 1; | ||
import { findTargetHandler, isMiddleware } from "../../utils/handler.js"; | ||
var handlerName = (handler) => { | ||
return handler.name || (isMiddleware(handler) ? "[middleware]" : "[handler]"); | ||
}; | ||
var findTargetHandler = (handler) => { | ||
return handler[COMPOSED_HANDLER] ? findTargetHandler(handler[COMPOSED_HANDLER]) : handler; | ||
}; | ||
var inspectRoutes = (hono) => { | ||
@@ -11,0 +7,0 @@ return hono.routes.map(({ path, method, handler }) => { |
// src/helper/ssg/index.ts | ||
import { replaceUrlParam } from "../../client/utils.js"; | ||
import { inspectRoutes } from "../../helper/dev/index.js"; | ||
import { bufferToString } from "../../utils/buffer.js"; | ||
import { getExtension } from "../../utils/mime.js"; | ||
import { joinPaths, dirname } from "./utils.js"; | ||
var X_HONO_SSG_HEADER_KEY = "x-hono-ssg"; | ||
var X_HONO_DISABLE_SSG_HEADER_KEY = "x-hono-disable-ssg"; | ||
import { joinPaths, dirname, filterStaticGenerateRoutes } from "./utils.js"; | ||
var SSG_CONTEXT = "HONO_SSG_CONTEXT"; | ||
var SSG_DISABLED_RESPONSE = new Response("SSG is disabled", { status: 404 }); | ||
var generateFilePath = (routePath, outDir, mimeType) => { | ||
@@ -53,9 +52,5 @@ const extension = determineExtension(mimeType); | ||
const baseURL = "http://localhost"; | ||
for (const route of inspectRoutes(app)) { | ||
if (route.isMiddleware) { | ||
continue; | ||
} | ||
for (const route of filterStaticGenerateRoutes(app)) { | ||
const thisRouteBaseURL = new URL(route.path, baseURL).toString(); | ||
let forGetInfoURLRequest = new Request(thisRouteBaseURL); | ||
forGetInfoURLRequest.headers.set(X_HONO_SSG_HEADER_KEY, "true"); | ||
if (beforeRequestHook) { | ||
@@ -81,4 +76,6 @@ const maybeRequest = beforeRequestHook(forGetInfoURLRequest); | ||
const replacedUrlParam = replaceUrlParam(route.path, param); | ||
let response = await app.request(replacedUrlParam, requestInit); | ||
if (response.headers.get(X_HONO_DISABLE_SSG_HEADER_KEY)) { | ||
let response = await app.request(replacedUrlParam, requestInit, { | ||
[SSG_CONTEXT]: true | ||
}); | ||
if (response === SSG_DISABLED_RESPONSE) { | ||
continue; | ||
@@ -139,18 +136,20 @@ } | ||
}; | ||
var isSSGContext = (c) => !!c.env?.[SSG_CONTEXT]; | ||
var disableSSG = () => async function disableSSG2(c, next) { | ||
if (isSSGContext(c)) { | ||
return SSG_DISABLED_RESPONSE; | ||
} | ||
await next(); | ||
c.header(X_HONO_DISABLE_SSG_HEADER_KEY, "true"); | ||
}; | ||
var onlySSG = () => async function onlySSG2(c, next) { | ||
const headerValue = c.req.raw.headers.get(X_HONO_SSG_HEADER_KEY); | ||
if (headerValue) { | ||
await next(); | ||
if (!isSSGContext(c)) { | ||
return c.notFound(); | ||
} | ||
return c.notFound(); | ||
await next(); | ||
}; | ||
export { | ||
X_HONO_DISABLE_SSG_HEADER_KEY, | ||
X_HONO_SSG_HEADER_KEY, | ||
SSG_DISABLED_RESPONSE, | ||
disableSSG, | ||
fetchRoutesContent, | ||
isSSGContext, | ||
onlySSG, | ||
@@ -157,0 +156,0 @@ saveContentToFiles, |
// src/helper/ssg/utils.ts | ||
import { METHOD_NAME_ALL } from "../../router.js"; | ||
import { findTargetHandler, isMiddleware } from "../../utils/handler.js"; | ||
var dirname = (path) => { | ||
@@ -37,5 +39,15 @@ const splitedPath = path.split(/[\/\\]/); | ||
}; | ||
var filterStaticGenerateRoutes = (hono) => { | ||
return hono.routes.reduce((acc, { method, handler, path }) => { | ||
const targetHandler = findTargetHandler(handler); | ||
if (["GET", METHOD_NAME_ALL].includes(method) && !isMiddleware(targetHandler)) { | ||
acc.push({ path }); | ||
} | ||
return acc; | ||
}, []); | ||
}; | ||
export { | ||
dirname, | ||
filterStaticGenerateRoutes, | ||
joinPaths | ||
}; |
@@ -171,2 +171,3 @@ // src/jsx/dom/render.ts | ||
} | ||
const childNodes = container.childNodes; | ||
for (let i = 0, len = next.length; i < len; i++, offset++) { | ||
@@ -185,4 +186,4 @@ const child = next[i]; | ||
} | ||
if (container.childNodes[offset] !== el) { | ||
container.insertBefore(el, container.childNodes[offset] || null); | ||
if (childNodes[offset] !== el && childNodes[offset - 1] !== child.e) { | ||
container.insertBefore(el, childNodes[offset] || null); | ||
} | ||
@@ -189,0 +190,0 @@ } |
@@ -5,3 +5,3 @@ // src/router/linear-router/router.ts | ||
var emptyParams = {}; | ||
var splitPathRe = /\/(:\w+(?:{[^}]+})?)|\/[^\/\?]+|(\?)/g; | ||
var splitPathRe = /\/(:\w+(?:{(?:(?:{[\d,]+})|[^}])+})?)|\/[^\/\?]+|(\?)/g; | ||
var splitByStarRe = /\*/; | ||
@@ -8,0 +8,0 @@ var LinearRouter = class { |
@@ -13,3 +13,3 @@ // src/router/pattern-router/router.ts | ||
} | ||
const parts = path.match(/\/?(:\w+(?:{[^}]+})?)|\/?[^\/\?]+|(\?)/g) || []; | ||
const parts = path.match(/\/?(:\w+(?:{(?:(?:{[\d,]+})|[^}])+})?)|\/?[^\/\?]+|(\?)/g) || []; | ||
if (parts[parts.length - 1] === "?") { | ||
@@ -16,0 +16,0 @@ this.add(method, parts.slice(0, parts.length - 2).join(""), handler); |
@@ -1,5 +0,5 @@ | ||
import type { Env, Input, MiddlewareHandler, H, HandlerResponse } from '../../types'; | ||
import type { Env, H, HandlerResponse, Input, MiddlewareHandler } from '../../types'; | ||
export declare class Factory<E extends Env = any, P extends string = any> { | ||
createMiddleware: <I extends Input = {}>(middleware: MiddlewareHandler<E, P, I>) => MiddlewareHandler<E, P, I>; | ||
createHandlers<I extends Input = {}>(handler1: H<E, P, I>): [H<E, P, I>]; | ||
createHandlers<I extends Input = {}, R extends HandlerResponse<any> = any>(handler1: H<E, P, I, R>): [H<E, P, I, R>]; | ||
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,0 +6,0 @@ 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>]; |
import type { Context } from '../../context'; | ||
import type { Hono } from '../../hono'; | ||
import type { Env, MiddlewareHandler, Schema } from '../../types'; | ||
export declare const X_HONO_SSG_HEADER_KEY = "x-hono-ssg"; | ||
export declare const X_HONO_DISABLE_SSG_HEADER_KEY = "x-hono-disable-ssg"; | ||
export declare const SSG_DISABLED_RESPONSE: Response; | ||
/** | ||
@@ -90,2 +89,8 @@ * @experimental | ||
* @experimental | ||
* `isSSGContext` is an experimental feature. | ||
* The API might be changed. | ||
*/ | ||
export declare const isSSGContext: (c: Context) => boolean; | ||
/** | ||
* @experimental | ||
* `disableSSG` is an experimental feature. | ||
@@ -92,0 +97,0 @@ * The API might be changed. |
@@ -0,1 +1,3 @@ | ||
import type { Hono } from '../../hono'; | ||
import type { Env } from '../../types'; | ||
/** | ||
@@ -8,1 +10,6 @@ * Get dirname | ||
export declare const joinPaths: (...paths: string[]) => string; | ||
interface FilterStaticGenerateRouteData { | ||
path: string; | ||
} | ||
export declare const filterStaticGenerateRoutes: <E extends Env>(hono: Hono<E, import("../../types").BlankSchema, "/">) => FilterStaticGenerateRouteData[]; | ||
export {}; |
{ | ||
"name": "hono", | ||
"version": "4.0.1", | ||
"version": "4.0.2", | ||
"description": "Ultrafast web framework for the Edges", | ||
@@ -5,0 +5,0 @@ "main": "dist/cjs/index.js", |
@@ -11,3 +11,3 @@ <div align="center"> | ||
<a href="https://hono.dev"><b>Documentation :point_right: hono.dev</b></a><br /> | ||
<i>v3 has been released!</i> <a href="docs/MIGRATION.md">Migration guide</b> | ||
<i>v4 has been released!</i> <a href="docs/MIGRATION.md">Migration guide</b> | ||
</p> | ||
@@ -46,3 +46,3 @@ | ||
``` | ||
npm create hono@latest my-app | ||
npm create hono@latest | ||
``` | ||
@@ -53,3 +53,3 @@ | ||
- **Ultrafast** π - The router `RegExpRouter` is really fast. Not using linear loops. Fast. | ||
- **Lightweight** πͺΆ - The `hono/tiny` preset is under 14kB. Hono has zero dependencies and uses only the Web Standard API. | ||
- **Lightweight** πͺΆ - The `hono/tiny` preset is under 13kB. Hono has zero dependencies and uses only the Web Standard API. | ||
- **Multi-runtime** π - Works on Cloudflare Workers, Fastly Compute, Deno, Bun, AWS Lambda, Lambda@Edge, or Node.js. The same code runs on all platforms. | ||
@@ -56,0 +56,0 @@ - **Batteries Included** π - Hono has built-in middleware, custom middleware, and third-party middleware. Batteries included. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
693313
368
19042