feat: add h3 v2 support#16
Merged
Merged
Conversation
h3 v2 makes the response an immutable web `Response`, removes the `send` utility and the `onBeforeResponse` app hook. This adds dual support for h3 v1 and v2: - access `send` (v1) / `toResponse` (v2) dynamically so the module loads under both versions; `compress` mutates the body when `send` is gone - add `compression()` / `compressionStream()` middleware for h3 v2 plus the low-level `compressResponse` / `compressResponseStream` helpers - widen the `h3` peer range to `^1.6.0 || ^2.0.0` - port tests to h3 v2 (mockEvent for the mutable/nitro path, a real H3 app for the middleware) and document v2 usage Closes #14 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Add an `h3: [1, 2]` matrix dimension and switch the installed h3 version per job. Tests are split by version: v1-only (app `onBeforeResponse` hook) and v2-only (mockEvent + middleware) suites are gated via `describe.runIf` and a `test/_version` feature-detect, with version-specific h3 symbols accessed lazily so every file loads under both versions. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
6e6b63e to
808f03f
Compare
The playground used `@nuxt/devtools: latest`. Re-resolving the lockfile for the h3 v2 devDep bumped it to a version pulling `@nuxt/kit@4.4.8` / `vite@8`, which import `styleText` from `node:util` (Node 20+). The playground's `nuxt prepare` postinstall then crashed the install on Node 18. Pin it to `^0.8.2` (the version main already resolved) so the playground tree stays Node-18 compatible. This also shrinks the lockfile diff to just the h3 v1 -> v2 swap. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Closes #14
Problem
h3 v2 fundamentally changes the response pipeline and breaks this package:
sendutility is removed, soimport { send } from 'h3'fails to load the module under v2.onBeforeResponseapp hook is gone (v2 only hasonRequest/onResponse/onError), andonResponse's return value is ignored (toResponsedoes.then(() => response)), so the body can no longer be replaced through a hook.Response.Solution — dual support for h3 v1 and v2
src/helper.ts: accesssend(v1) /toResponse(v2) dynamically via a namespace import so the module loads under both versions.compressfalls back to mutatingresponse.bodywhensendis unavailable. Adds web-ResponsehelperscompressResponse/compressResponseStreamand a stream-awaregetStreamCompression.src/middleware.ts(new):compression()andcompressionStream()middleware for h3 v2 — they callnext(), normalize the result withtoResponse, and return a compressedResponse. Optional forced method (e.g.compression('gzip')).src/index.ts: export the new middleware, helpers and types.h3to^1.6.0 || ^2.0.0(devDep pinned to the real v22.0.1-rc.22; npmh3@2.0.0is a deprecated stub).mockEventfor the mutable / Nitro path, a realnew H3()app + supertest for the middleware. gzip/deflate/br covered. 15 tests pass, ~97% coverage, lint + build green.Notes
sendpath (not reachable when tested under v2); it is byte-identical to the previously shipped code.h3: [1, 2]matrix dimension if preferred.🤖 Generated with Claude Code