npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@hono-filebased-route/runtime

v0.4.1

Published

A core utility for file-based routing in Hono applications.

Downloads

108

Readme

Hono File-Based Routing Runtime

一个基于 Hono 框架的文件路由系统运行时,使用 Turborepo 管理的 monorepo 项目,支持类似 Next.js 的文件路由模式。

特性

  • 🚀 文件路由系统: 基于文件结构自动生成路由
  • Bun 运行时: 快速的 JavaScript 运行时
  • 🔥 热重载: 开发时自动重新加载
  • 📁 动态路由: 支持动态参数和通配符路由
  • 🎯 类型安全: 完整的 TypeScript 支持
  • 🛠️ 自动生成: 路由配置自动生成,无需手动维护
  • 📦 Monorepo: 使用 Turborepo 管理多包项目
  • 构建缓存: 智能缓存和并行构建优化

路由规则

基本路由实例

| 文件路径 | 路由路径 | 说明 | | ---------------------------------- | ------------- | ------------ | | src/routes/index.ts | / | 根路由 | | src/routes/about.ts | /about | 静态路由 | | src/routes/users/index.ts | /users | 嵌套路由 | | src/routes/users/[id].ts | /users/:id | 动态参数路由 | | src/routes/articles/[...slug].ts | /articles/* | 通配符路由 |

安装

安装项目依赖:

npm install
# or
yarn add
# or
pnpm add
# or
bun add

使用方法

Turborepo 命令

本项目使用 Turborepo 进行 monorepo 管理,支持以下命令:

# 构建所有包
bun run build

# 启动所有开发服务
bun run dev

# 运行所有测试
bun run test

# 类型检查
bun run type-check

# 清理构建产物
bun run clean

开发模式

# 使用 Turborepo 启动开发服务器
bun run dev

# 或者直接启动示例项目
cd examples/bun
bun run dev

这将启动开发服务器,支持热重载,访问 http://localhost:3000

生产模式

# 先构建所有包
bun run build

# 启动示例应用
cd examples/bun
bun run start

手动生成路由

bun run generate-routes

创建路由

src/routes 目录下创建 TypeScript 文件,导出 HTTP 方法处理函数:

import { Context } from 'hono'

// GET 请求处理
export function GET(c: Context) {
 return c.json({ message: 'Hello from GET' })
}

// POST 请求处理
export function POST(c: Context) {
 return c.json({ message: 'Hello from POST' })
}

动态路由

使用方括号创建动态路由:

import { Context } from 'hono'

export function GET(c: Context) {
 const id = c.req.param('id')
 return c.json({ userId: id })
}

通配符路由

使用 [...slug] 创建通配符路由:

该项目通过 c.req.path 填充 slug 参数,自动为 GET/POST 函数提供第二个参数。

import { Context } from 'hono'

export function GET(c: Context, slug: string[]) {
 return c.json({ slug })
}

工作原理

  1. 路由扫描: scripts/generate-routes.ts 扫描 src/routes 目录
  2. 路径转换: 将文件路径转换为 Hono 路由路径
  3. 代码生成: 生成 src/generated-routes.ts 文件
  4. 自动注册: 主应用自动注册所有生成的路由

开发脚本

根目录脚本(Turborepo)

  • bun run build: 构建所有包(支持缓存和并行构建)
  • bun run dev: 启动所有开发服务
  • bun run test: 运行所有测试
  • bun run lint: 代码检查
  • bun run type-check: TypeScript 类型检查
  • bun run clean: 清理所有构建产物
  • bun run test:basic: 快速启动基础示例

包级别脚本

  • bun run build: 构建当前包
  • bun run dev: 开发模式(包含热重载)
  • bun run clean: 清理构建产物
  • bun run generate-routes: 生成路由配置(仅示例项目)

技术栈

  • Hono: 轻量级 Web 框架
  • bun: 快速的 JavaScript 运行时
  • Turborepo: 高性能 monorepo 构建系统
  • TypeScript: 类型安全的 JavaScript

许可证

MIT License

贡献

欢迎提交 Issue 和 Pull Request!


注意: src/generated-routes.ts 文件是自动生成的,请不要手动编辑。如需修改路由,请直接修改 src/routes 目录下的文件。