Skip to content
Open

v2 #316

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:

strategy:
matrix:
node-version: [18.x, 20.x, 22.x, 24.x]
node-version: [20.x, 22.x, 24.x]

steps:
- uses: actions/checkout@v4
Expand All @@ -27,9 +27,21 @@ jobs:
- run: bun install
- run: bun run format
- run: bun run lint
- run: bun run build
- run: bun run test

ci-build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Use Node.js 24.x
uses: actions/setup-node@v4
with:
node-version: 24.x
- uses: oven-sh/setup-bun@v2
- run: bun install
- run: bun run build

ci-windows:
runs-on: windows-latest

Expand Down
8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,7 @@ Statistics Avg Stdev Max

## Requirements

It works on Node.js versions greater than 18.x. The specific required Node.js versions are as follows:

- 18.x => 18.14.1+
- 19.x => 19.7.0+
- 20.x => 20.0.0+

Essentially, you can simply use the latest version of each major release.
It works on Node.js versions greater than 20.x.

## Installation

Expand Down
912 changes: 342 additions & 570 deletions bun.lock

Large diffs are not rendered by default.

9 changes: 0 additions & 9 deletions jest.config.js

This file was deleted.

16 changes: 7 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@
}
},
"scripts": {
"test": "node --expose-gc node_modules/jest/bin/jest.js",
"build": "tsup --external hono",
"watch": "tsup --watch",
"test": "vitest",
"build": "tsdown --external hono",
"watch": "tsdown --watch",
"postbuild": "publint",
"prerelease": "bun run build && bun run test",
"release": "np",
Expand All @@ -77,24 +77,22 @@
"access": "public"
},
"engines": {
"node": ">=18.14.1"
"node": ">=20"
},
"devDependencies": {
"@hono/eslint-config": "^1.0.1",
"@types/jest": "^29.5.3",
"@types/node": "^20.10.0",
"@types/supertest": "^2.0.12",
"@whatwg-node/fetch": "^0.9.14",
"eslint": "^9.10.0",
"hono": "^4.4.10",
"jest": "^29.6.1",
"np": "^7.7.0",
"prettier": "^3.2.4",
"publint": "^0.1.16",
"supertest": "^6.3.3",
"ts-jest": "^29.1.1",
"tsup": "^7.2.0",
"typescript": "^5.3.2"
"tsdown": "^0.20.3",
"typescript": "^5.3.2",
"vitest": "^4.0.18"
},
"peerDependencies": {
"hono": "^4"
Expand Down
11 changes: 11 additions & 0 deletions src/error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export class RequestError extends Error {
constructor(
message: string,
options?: {
cause?: unknown
}
) {
super(message, options)
this.name = 'RequestError'
}
}
6 changes: 0 additions & 6 deletions src/globals.ts

This file was deleted.

18 changes: 9 additions & 9 deletions src/listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { Http2ServerResponse } from 'node:http2'
import type { Writable } from 'node:stream'
import type { IncomingMessageWithWrapBodyStream } from './request'
import {
abortControllerKey,
abortRequest,
newRequest,
Request as LightweightRequest,
wrapBodyStream,
Expand All @@ -20,7 +20,6 @@ import {
buildOutgoingHttpHeaders,
} from './utils'
import { X_ALREADY_SENT } from './utils/response/constants'
import './globals'

const outgoingEnded = Symbol('outgoingEnded')
type OutgoingHasOutgoingEnded = Http2ServerResponse & {
Expand Down Expand Up @@ -278,13 +277,14 @@ export const getRequestListener = (

// Detect if request was aborted.
outgoing.on('close', () => {
const abortController = req[abortControllerKey] as AbortController | undefined
if (abortController) {
if (incoming.errored) {
req[abortControllerKey].abort(incoming.errored.toString())
} else if (!outgoing.writableFinished) {
req[abortControllerKey].abort('Client connection prematurely closed.')
}
let abortReason: string | undefined
if (incoming.errored) {
abortReason = incoming.errored.toString()
} else if (!outgoing.writableFinished) {
abortReason = 'Client connection prematurely closed.'
}
if (abortReason !== undefined) {
req[abortRequest](abortReason)
}

// incoming is not consumed to the end
Expand Down
Loading
Loading