-
-
Notifications
You must be signed in to change notification settings - Fork 664
fix(hono): refresh handler preamble and fix import paths for hono.handlers option #3292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
melloware
merged 7 commits into
orval-labs:master
from
zeriong:fix/hono-handlers-imports-and-overwrite-2989
May 6, 2026
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
dfdccb8
fix(hono): refresh handler preamble and resolve correct import paths …
zeriong 2e3da05
test(hono): cover hono.handlers option across split, tags, and tags-s…
zeriong 863b582
docs(hono): note that handler preamble is refreshed and bodies preser…
zeriong cada5bd
test(hono): regenerate sample handlers and snapshots after import-pat…
zeriong b30eaa1
fix(hono): preserve only handler bodies and short-circuit zValidator …
zeriong c550674
test(hono): regenerate samples and snapshots after preservation refac…
zeriong 1e50a78
fix(hono): handle keyword-led regex literals and nested arrows in bod…
zeriong File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| import { describe, expect, it } from 'vitest'; | ||
|
|
||
| import { extractExistingHandlerBodies } from './index'; | ||
|
|
||
| describe('extractExistingHandlerBodies', () => { | ||
| it('returns the body of each handler keyed by name', () => { | ||
| const source = ` | ||
| import { createFactory } from 'hono/factory'; | ||
|
|
||
| const factory = createFactory(); | ||
| export const listPetsHandlers = factory.createHandlers( | ||
| async (c: ListPetsContext) => { | ||
| return c.json([]); | ||
| }, | ||
| ); | ||
| export const createPetsHandlers = factory.createHandlers( | ||
| zValidator('json', CreatePetsBody), | ||
| async (c: CreatePetsContext) => {}, | ||
| ); | ||
| `; | ||
|
|
||
| const bodies = extractExistingHandlerBodies(source); | ||
|
|
||
| expect([...bodies.keys()]).toEqual([ | ||
| 'listPetsHandlers', | ||
| 'createPetsHandlers', | ||
| ]); | ||
| expect(bodies.get('listPetsHandlers')).toContain('return c.json([]);'); | ||
| expect(bodies.get('createPetsHandlers')).toBe(''); | ||
| }); | ||
|
|
||
| it('preserves nested syntax inside the handler body', () => { | ||
| const source = `export const listPetsHandlers = factory.createHandlers( | ||
| async (c: ListPetsContext) => { | ||
| const limit = Number(c.req.query('limit') ?? 10); | ||
| if (limit > 0) { return c.json({ items: pets.slice(0, limit) }); } | ||
| }, | ||
| );`; | ||
|
|
||
| const body = extractExistingHandlerBodies(source).get('listPetsHandlers'); | ||
| expect(body).toContain("Number(c.req.query('limit') ?? 10)"); | ||
| expect(body).toContain('{ items: pets.slice(0, limit) }'); | ||
| }); | ||
|
|
||
| it('is not confused by parentheses or braces inside strings, templates, comments, and regex', () => { | ||
| const source = `export const trickyHandlers = factory.createHandlers( | ||
| async (c: TrickyContext) => { | ||
| const a = ")"; // a paren in a string — must not close the call | ||
| const b = '}'; | ||
| const c1 = \`tpl ) { } \${'} )'} end\`; | ||
| const re = /\\)\\}\\(/g; | ||
| /* block comment with ) and } and ( */ | ||
| // line comment with ) } | ||
| return c.text(a + b + c1); | ||
| }, | ||
| );`; | ||
|
|
||
| const body = extractExistingHandlerBodies(source).get('trickyHandlers'); | ||
| expect(body).toBeDefined(); | ||
| expect(body).toContain('return c.text(a + b + c1);'); | ||
| expect(body).toContain('/* block comment with ) and } and ( */'); | ||
| }); | ||
|
|
||
| it('preserves bodies containing nested arrow functions', () => { | ||
| const source = `export const listPetsHandlers = factory.createHandlers( | ||
| async (c: ListPetsContext) => { | ||
| const ids = pets.map((p) => p.id); | ||
| return c.json(ids); | ||
| }, | ||
| );`; | ||
|
|
||
| const body = extractExistingHandlerBodies(source).get('listPetsHandlers'); | ||
| expect(body).toContain('pets.map((p) => p.id)'); | ||
| expect(body).toContain('return c.json(ids);'); | ||
| }); | ||
|
|
||
| it('preserves bodies containing regex literals after keywords', () => { | ||
| const source = `export const listPetsHandlers = factory.createHandlers( | ||
| async (c: ListPetsContext) => { | ||
| return /[)]/.test(c.req.query('q') ?? ''); | ||
| }, | ||
| );`; | ||
|
|
||
| const body = extractExistingHandlerBodies(source).get('listPetsHandlers'); | ||
| expect(body).toContain('/[)]/.test'); | ||
| }); | ||
|
|
||
| it('returns an empty map when no handlers are present', () => { | ||
| expect(extractExistingHandlerBodies('// nothing here').size).toBe(0); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.