{"_id":"@axel669/hono-file-routes","_rev":"3-d21414d6b1d01e0bda3cbbd800be2265","name":"@axel669/hono-file-routes","dist-tags":{"latest":"1.0.2"},"versions":{"1.0.0":{"name":"@axel669/hono-file-routes","version":"1.0.0","keywords":[],"author":{"name":"Axel"},"license":"MIT","_id":"@axel669/hono-file-routes@1.0.0","maintainers":[{"name":"axel669","email":"axel@axel669.net"}],"homepage":"https://github.com/axel669/lib.hono-file-routes#readme","bugs":{"url":"https://github.com/axel669/lib.hono-file-routes/issues"},"dist":{"shasum":"2b7f627d382b8de58157708528169cb229cca18d","tarball":"https://registry.npmjs.org/@axel669/hono-file-routes/-/hono-file-routes-1.0.0.tgz","fileCount":6,"integrity":"sha512-m9WJiJaYSDNuUsQxH8ncYSYA16I3ZdtC27/cx0amgZyK2/Ud7pbGioEX/v1rmj4I0FaY0LtEsMSOX9JFs/pACA==","signatures":[{"sig":"MEQCIBdIwc/7FxFBvxN9tLGQIV6qF+ho6j5/ktbVIju5C0RIAiBRF+ECBbP91AzpS5fKc/Vmk3hX3FSMff9XWeVW3wBaPg==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":12780},"main":"./lib/main.js","type":"module","exports":{".":"./lib/main.js"},"gitHead":"d9616e6e3d311fa383a24193b03667ac5c8da85c","scripts":{},"_npmUser":{"name":"axel669","email":"axel@axel669.net"},"repository":{"url":"git+https://github.com/axel669/lib.hono-file-routes.git","type":"git"},"_npmVersion":"10.2.3","description":"A small library for adding file-based routing into hono routes at bundle time\r using rollup. The goal was to bring file-based routing to places like Cloudflare\r Workers and AWS Lambda with a simple, consistent interface.","directories":{},"_nodeVersion":"20.10.0","dependencies":{"fast-glob":"^3.3.2"},"_hasShrinkwrap":false,"devDependencies":{"hono":"^4.4.13","rollup":"^4.18.1","@hono/node-server":"^1.12.0","@rollup/plugin-node-resolve":"^15.2.3"},"peerDependencies":{"hono":"^4.4.13"},"_npmOperationalInternal":{"tmp":"tmp/hono-file-routes_1.0.0_1753600860386_0.9253137922090588","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"@axel669/hono-file-routes","version":"1.0.1","keywords":[],"author":{"name":"Axel"},"license":"MIT","_id":"@axel669/hono-file-routes@1.0.1","maintainers":[{"name":"axel669","email":"axel@axel669.net"}],"homepage":"https://github.com/axel669/lib.hono-file-routes#readme","bugs":{"url":"https://github.com/axel669/lib.hono-file-routes/issues"},"dist":{"shasum":"ca7249e4fe2570ffa0611b79b7fb573cec55f17f","tarball":"https://registry.npmjs.org/@axel669/hono-file-routes/-/hono-file-routes-1.0.1.tgz","fileCount":6,"integrity":"sha512-J8x5bCvXThgp/JLC5lzY0Ht6aJAbwvm16dTvvJAQYMXbsaP2vhwpy9DGw3zlINYsiXDMXkGSUIel9y0nLjxAXA==","signatures":[{"sig":"MEQCIAVno3k5LScV1UED0rYVmpNlLhAjkqr8sYxQTk+6EjD8AiAGr155DWwSLs8eMbDT8D6cGHga56bgBcNwYeHH6cBVvA==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":12781},"main":"./lib/main.js","type":"module","exports":{".":"./lib/main.js"},"gitHead":"d9616e6e3d311fa383a24193b03667ac5c8da85c","scripts":{},"_npmUser":{"name":"axel669","email":"axel@axel669.net"},"repository":{"url":"git+https://github.com/axel669/lib.hono-file-routes.git","type":"git"},"_npmVersion":"11.5.1","description":"A small library for adding file-based routing into hono routes at bundle time\r using rollup. The goal was to bring file-based routing to places like Cloudflare\r Workers and AWS Lambda with a simple, consistent interface.","directories":{},"_nodeVersion":"24.6.0","dependencies":{"fast-glob":"^3.3.2"},"_hasShrinkwrap":false,"devDependencies":{"hono":"^4.4.13","rollup":"^4.18.1","@hono/node-server":"^1.12.0","@rollup/plugin-node-resolve":"^15.2.3"},"peerDependencies":{"hono":"^4.4.13"},"_npmOperationalInternal":{"tmp":"tmp/hono-file-routes_1.0.1_1757648856831_0.9070676029452225","host":"s3://npm-registry-packages-npm-production"}},"1.0.2":{"name":"@axel669/hono-file-routes","version":"1.0.2","description":"A small library for adding file-based routing into hono routes at bundle time\r using rollup. The goal was to bring file-based routing to places like Cloudflare\r Workers and AWS Lambda with a simple, consistent interface.","main":"./lib/main.js","type":"module","scripts":{},"keywords":[],"author":{"name":"Axel"},"license":"MIT","exports":{".":"./lib/main.js"},"devDependencies":{"@hono/node-server":"^1.12.0","@rollup/plugin-node-resolve":"^15.2.3","hono":"^4.4.13","rollup":"^4.18.1"},"dependencies":{"fast-glob":"^3.3.2"},"peerDependencies":{"hono":"^4.4.13"},"repository":{"type":"git","url":"git+https://github.com/axel669/lib.hono-file-routes.git"},"gitHead":"51829fbd8033c5b431814aa9c59a51eeb8409aae","_id":"@axel669/hono-file-routes@1.0.2","bugs":{"url":"https://github.com/axel669/lib.hono-file-routes/issues"},"homepage":"https://github.com/axel669/lib.hono-file-routes#readme","_nodeVersion":"24.6.0","_npmVersion":"11.7.0","dist":{"integrity":"sha512-LrFt1BzEVQoid3srVsJAyJVne3SzVHeg/sZLL+CqAn09bUxwe3KJvHFcNnpJOQNw41onYWn5rTsQqqLWCwgZuw==","shasum":"710ad3455fcdf73fcabd85a44f602affc81a5763","tarball":"https://registry.npmjs.org/@axel669/hono-file-routes/-/hono-file-routes-1.0.2.tgz","fileCount":6,"unpackedSize":12876,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDLgm0G6jfxgSKZJ87TG/XaK2y/s2dPXkfE0wFjsnQ16wIhAKS2egsIsRvd9kzF3+dcSl+1AVu8XKJWsrYos8Ga0nef"}]},"_npmUser":{"name":"axel669","email":"axel@axel669.net"},"directories":{},"maintainers":[{"name":"axel669","email":"axel@axel669.net"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/hono-file-routes_1.0.2_1775341653125_0.7021755049256209"},"_hasShrinkwrap":false}},"time":{"created":"2025-07-27T07:21:00.115Z","modified":"2026-04-04T22:27:33.377Z","1.0.0":"2025-07-27T07:21:00.559Z","1.0.1":"2025-09-12T03:47:36.993Z","1.0.2":"2026-04-04T22:27:33.261Z"},"bugs":{"url":"https://github.com/axel669/lib.hono-file-routes/issues"},"author":{"name":"Axel"},"license":"MIT","homepage":"https://github.com/axel669/lib.hono-file-routes#readme","keywords":[],"repository":{"type":"git","url":"git+https://github.com/axel669/lib.hono-file-routes.git"},"description":"A small library for adding file-based routing into hono routes at bundle time\r using rollup. The goal was to bring file-based routing to places like Cloudflare\r Workers and AWS Lambda with a simple, consistent interface.","maintainers":[{"name":"axel669","email":"axel@axel669.net"}],"readme":"# Hono File Routes\r\nA small library for adding file-based routing into hono routes at bundle time\r\nusing rollup. The goal was to bring file-based routing to places like Cloudflare\r\nWorkers and AWS Lambda with a simple, consistent interface.\r\n\r\n## Installation\r\nAvailable in the standard package managers\r\n```bash\r\npnpm add @axel669/hono-file-routes\r\n```\r\n\r\n## Usage\r\n1. Configure the plugin with rollup\r\n2. Create the routes directory with the desired routes\r\n3. Import the route directory into your code\r\n\r\nThe examples directory of the repo contains a NodeJS and a Cloudflare Workers\r\nexample that can be run, and a Bruno collection for each of the routes.\r\n\r\n### Importing in Code\r\nImporting with the `file-routes@` prefix on the directory to import will have\r\nthe plugin create a hono router from the routes in the directory. Normal import\r\nresolution rules apply to the location (relative vs absolute file paths).\r\n```js\r\nimport router from \"file-routes@./routes\"\r\n```\r\n\r\n### Rollup Config\r\n```js\r\nimport fileRoutes from \"@axel669/hono-file-routes\"\r\n\r\nexport default {\r\n    input: \"main.js\",\r\n    output: {\r\n        file: \"your-output-file\",\r\n        format: \"esm\"\r\n    },\r\n    plugins: [\r\n        fileRoutes({\r\n            debug: true\r\n        })\r\n    ]\r\n}\r\n```\r\nIf `debug` is `true` the library will console.log information on what routes\r\nare being imported and setup when the script begins.\r\n\r\n### File Routes\r\nThere are 4 route types that can be defined by the files and their locations.\r\nAn example of the order these run is provided after all the descriptions.\r\n\r\nIn order for a file to register a route action, it needs to export variables\r\nnamed `$<method>` and / or `$any`. Specific methods will always match before\r\n`$any` handlers (ex: if `$get` matches, `$any` in the same file won't).\r\n\r\nThe exported value for any handlers should be either a function, or an array of\r\nfunctions that are used as [Hono routing](https://hono.dev/docs/api/routing)\r\nfunctions. If the exported value is an array, all the handlers are added for the\r\nsame route/verb in the order they appear in the array. Additionally, if any of\r\nthem in the list returns it will make the route return and not go to subsequent\r\nhandlers, just like\r\n[middleware in Hono](https://hono.dev/docs/guides/middleware).\r\n\r\n> The library doesn't modify how any of the\r\n> [Hono context](https://hono.dev/docs/api/context) functions work, it just\r\n> makes it easier to setup routes based on file paths, so all context functions\r\n> are available as-is per the Hono docs.\r\n\r\n#### Middleware\r\nMiddleware Routes are files named `_middleware.js` in a folder. Middleware runs\r\nbefore any routes in a folder, in a top down fashion (examples later).\r\n\r\n#### Wildcard Routes\r\nWildcard routes match any route not defined in a directory and are defined by\r\nnaming a file as `[[<name>]].js`.\r\n\r\n#### Parameter Routes\r\nParameter routes are routes that have parameters in them and are defined by\r\nnaming a file or folder as `[<param name>]`. Any valid part of a path can match\r\nagainst a parameter, and more than one parameter can exist on a route.\r\n\r\n### Static routes\r\nAny route that isn't formatted as one of the previous types will be\r\ntreated as a static route. The files and directories don't have any special\r\nsyntax required (other than being `.js` files).\r\n\r\n### Routing Example\r\n```\r\nroutes/\r\n├─ dir/\r\n│  ├─ _middleware.js\r\n│  ├─ static.js\r\n│  ├─ [[nested-wildcard]].js\r\n├─ user/\r\n│  ├─ _middleware.js\r\n│  ├─ logout.js\r\n│  ├─ [userID].js\r\n├─ [param1]/\r\n│  ├─ [param2]/\r\n│  │  ├─ thing.js\r\n│  ├─ [file-param].js\r\n├─ _middleware.js\r\n├─ [[no-route]].js\r\n```\r\n\r\nThis set of files will generate the following Hono routes:\r\n```\r\n/dir/static\r\n/dir/*\r\n/user/logout\r\n/user/:userID\r\n/:param1/:file-param\r\n/:param1/:param2/thing\r\n/*\r\n```\r\nRoutes are added to Hono in such a way that the resolution order is\r\nalways the same:\r\n1. static routes\r\n2. parameterized routes\r\n3. wildcards\r\n\r\n### Routing Resolution\r\nUsing the previous set of routes, this is what the execution will look\r\nlike given some example requests.\r\n\r\n```\r\n/dir/static\r\n-> run /_middleware.js\r\n-> run /dir/_middleware.js\r\n-> match /dir/static.js\r\n\r\n/dir/random-thing\r\n-> run /_middleware.js\r\n-> run /dir/_middleware.js\r\n-> match /dir/[[nested-wildcard]].js\r\n\r\n/user/logout\r\n-> run /_middleware.js\r\n-> run /user/_middleware.js\r\n-> match /user/logout.js\r\n\r\n/user/id-123\r\n-> run /_middleware.js\r\n-> run /user/_middleware.js\r\n-> match /user/[userID].js\r\n\r\n/user/not/valid\r\n-> run /_middleware.js\r\n-> run /user/_middleware.js\r\n-> match /[[no-route]].js\r\n\r\n/first/second/thing\r\n-> run /_middleware.js\r\n-> match /[param1]/[param2]/thing.js\r\n\r\n/first/second\r\n-> run /_middleware.js\r\n-> match /[param1]/[file-param].js\r\n```\r\n","readmeFilename":"readme.md"}