feat!: migrate to h3 v2#4
Merged
Merged
Conversation
Bump the h3 catalog pin to 2.0.1-rc.22 and rewrite devframe's HTTP
plumbing onto h3 v2's web-standard primitives. The h3 v1 `App` type is
no longer exported in v2, so devframe's public surface — the optional
`app` on `CreateDevServerOptions` / `StartHttpAndWsOptions`, the `app`
field on `StartedServer`, and the `onReady({ app })` callback — switches
from `App` to `H3`. Devframe bumps to `0.2.0` to reflect the breaking
type rename.
Internally: `createApp()` → `new H3()`, `toNodeListener` →
`toNodeHandler`, `defineEventHandler` → `defineHandler`,
`setResponseStatus`/`setResponseHeader` → `event.res.status` /
`event.res.headers.set(...)`, and the static file stream returns via
`Readable.toWeb(...)` instead of `sendStream`. The connection-meta
handler in `adapters/dev.ts` collapses to a plain `() => ({...})` now
that h3 auto-serializes object returns.
The trickiest v2 behavior change is route matching: `app.use(base, h)`
in v2 only matches the exact `base` path (not subpaths) and does not
strip the prefix from `event.url.pathname`. Static-dir mounts need
both. To avoid spreading that quirk across every call site, add a new
`mountStaticHandler(app, base, dir, options?)` export in
`devframe/utils/serve-static` that bundles the `${base}/**` route and
`withBase(base, ...)` prefix stripping. All four production/test mount
sites switch to it; the existing `serveStaticHandler` (h3 event
handler) and `serveStaticNodeMiddleware` (Connect middleware) are
kept unchanged.
Snapshots in `tests/__snapshots__/tsnapi/` are regenerated to reflect
the renamed types and the new `mountStaticHandler` export.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Migrates devframe's HTTP plumbing from h3 v1 to h3 v2 (
2.0.1-rc.22, pinned), rewriting handlers onto v2's web-standardRequest/Response/Headersprimitives. h3 v2 no longer exports theApptype, so devframe's public surface (CreateDevServerOptions.app,StartHttpAndWsOptions.app,StartedServer.app,onReady({ app })) renamesApp→H3; devframe bumps to0.2.0to reflect the typed-API break.Adds a new
mountStaticHandler(app, base, dir, options?)export indevframe/utils/serve-staticto encapsulate h3 v2's route-matching change:app.use(base, handler)now matchesbaseexactly (not subpaths) and does not strip the prefix fromevent.url.pathname. The helper bundles the${base}/**route andwithBase(base, ...)prefix stripping so the four static-mount call sites (production + tests) stay clean.serveStaticHandlerandserveStaticNodeMiddlewareare kept; the connection-meta handler collapses to() => ({...})thanks to v2's auto JSON serialization.Test plan
pnpm typecheck— cleanpnpm exec vitest run— 283/283 tests pass across 27 files (incl. thestatic-servedeployed-SPA contract test at both root and sub-path mounts)pnpm lint— cleanexamples/devframe-files-inspector):/__devframe-files-inspector/→ 200 HTML;/__connection.json→{"backend":"websocket","websocket":...}; asset miss → 404; SPA fallback route → 200; POST → 405App→H3rename and the newmountStaticHandlerexport