Skip to content

Commit 2264533

Browse files
committed
feat!: Drop compatibility with Node.js 20.
Signed-off-by: Paolo Insogna <paolo@cowtech.it>
1 parent c51d624 commit 2264533

File tree

12 files changed

+50
-70
lines changed

12 files changed

+50
-70
lines changed

.github/workflows/ci.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,19 @@ name: CI
33
on: [push, pull_request, workflow_dispatch]
44
jobs:
55
ci:
6-
runs-on: ubuntu-latest
6+
strategy:
7+
fail-fast: false
8+
matrix:
9+
os: [ubuntu-latest, windows-latest]
10+
node-version: [22, 24, 25]
11+
runs-on: ${{ matrix.os }}
712
steps:
813
- name: Checkout
9-
uses: actions/checkout@v3
14+
uses: actions/checkout@v4
1015
- name: Use supported Node.js Version
11-
uses: actions/setup-node@v3
16+
uses: actions/setup-node@v4
1217
with:
13-
node-version: 20.18.0
18+
node-version: ${{ matrix.node-version }}
1419
- name: Restore cached dependencies
1520
uses: actions/cache@v3
1621
with:

.swcrc

Lines changed: 0 additions & 10 deletions
This file was deleted.

package.json

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,39 +29,32 @@
2929
"exports": "./dist/index.js",
3030
"types": "./dist/index.d.ts",
3131
"scripts": {
32-
"dev": "swc --strip-leading-paths --delete-dir-on-start -s -w -d dist src",
33-
"build": "swc --strip-leading-paths --delete-dir-on-start -d dist src",
34-
"postbuild": "concurrently npm:lint npm:typecheck",
32+
"build": "rm -rf dist && tsc -p tsconfig.json && npm run lint",
3533
"format": "prettier -w src test",
3634
"lint": "eslint --cache",
37-
"typecheck": "tsc -p . --emitDeclarationOnly",
38-
"test": "c8 -c test/config/c8-local.json node --env-file=test.env --test test/*.test.ts",
39-
"test:ci": "c8 -c test/config/c8-ci.json node --env-file=test.env --test-reporter=tap --test test/*.test.ts",
40-
"ci": "npm run build && npm run test:ci",
35+
"test": "c8 -c test/config/c8-local.json node --test --test-reporter=cleaner-spec-reporter test/*.test.ts",
36+
"ci": "npm run build && npm run test",
4137
"prepublishOnly": "npm run ci",
4238
"postpublish": "git push origin && git push origin -f --tags"
4339
},
4440
"dependencies": {
4541
"ajv": "^8.17.1",
46-
"fastify-plugin": "^5.0.1",
47-
"http-errors-enhanced": "^3.0.2"
42+
"fastify-plugin": "^5.1.0",
43+
"http-errors-enhanced": "^4.0.1"
4844
},
4945
"devDependencies": {
50-
"@cowtech/eslint-config": "10.2.0",
51-
"@swc-node/register": "^1.10.9",
52-
"@swc/cli": "0.5.2",
53-
"@swc/core": "^1.10.3",
54-
"@types/node": "^22.10.2",
46+
"@cowtech/eslint-config": "^11.0.0",
47+
"@cowtech/typescript-config": "^0.2.2",
48+
"@types/node": "^24.10.1",
5549
"ajv-formats": "^3.0.1",
5650
"c8": "^10.1.3",
57-
"chokidar": "^4.0.3",
58-
"concurrently": "^9.1.1",
59-
"eslint": "^9.17.0",
60-
"fastify": "^5.2.0",
61-
"prettier": "^3.4.2",
62-
"typescript": "^5.7.2"
51+
"cleaner-spec-reporter": "^1.0.0",
52+
"eslint": "^9.39.1",
53+
"fastify": "^5.6.2",
54+
"prettier": "^3.6.2",
55+
"typescript": "^5.9.3"
6356
},
6457
"engines": {
65-
"node": ">= 20.18.0"
58+
"node": ">= 22.21.0"
6659
}
6760
}

src/handlers.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ import {
1616
type GenericObject,
1717
type NodeError,
1818
type RequestSection
19-
} from './interfaces.js'
20-
import { upperFirst } from './utils.js'
21-
import { convertValidationErrors, validationMessagesFormatters, type ValidationResult } from './validation.js'
19+
} from './interfaces.ts'
20+
import { upperFirst } from './utils.ts'
21+
import { convertValidationErrors, validationMessagesFormatters, type ValidationResult } from './validation.ts'
2222

2323
export function handleNotFoundError(request: FastifyRequest, reply: FastifyReply): void {
2424
handleErrors(new NotFoundError('Not found.'), request, reply)
@@ -72,6 +72,7 @@ export function handleErrors(error: FastifyError | Error, request: FastifyReques
7272
error = new BadRequestError(upperFirst(validationMessagesFormatters.jsonEmpty()))
7373
} else if (
7474
code === 'MALFORMED_JSON' ||
75+
code === 'FST_ERR_CTP_INVALID_JSON_BODY' ||
7576
error.name === 'SyntaxError' ||
7677
error.message === 'Invalid JSON' ||
7778
error.stack!.includes('at JSON.parse')

src/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import { type FastifyError, type FastifyInstance, type FastifyPluginOptions } from 'fastify'
22
import fastifyPlugin from 'fastify-plugin'
3-
import { handleErrors, handleNotFoundError } from './handlers.js'
3+
import { handleErrors, handleNotFoundError } from './handlers.ts'
44
import {
55
type Configuration,
66
kHttpErrorsEnhancedConfiguration,
77
kHttpErrorsEnhancedResponseValidations
8-
} from './interfaces.js'
9-
import { addResponseValidation, compileResponseValidationSchema } from './validation.js'
8+
} from './interfaces.ts'
9+
import { addResponseValidation, compileResponseValidationSchema } from './validation.ts'
1010

11-
export * from './handlers.js'
12-
export * from './interfaces.js'
13-
export { convertValidationErrors, niceJoin, validationMessagesFormatters } from './validation.js'
11+
export * from './handlers.ts'
12+
export * from './interfaces.ts'
13+
export { convertValidationErrors, niceJoin, validationMessagesFormatters } from './validation.ts'
1414

1515
export const plugin = fastifyPlugin(
1616
function (instance: FastifyInstance, options: FastifyPluginOptions, done: (error?: FastifyError) => void): void {

src/validation.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { Ajv, type Options } from 'ajv'
22
import addFormats from 'ajv-formats'
33
import {
4-
FastifyServerOptions,
54
type FastifyInstance,
65
type FastifyReply,
76
type FastifyRequest,
7+
type FastifyServerOptions,
88
type ValidationResult as FastifyValidationResult,
99
type RouteOptions
1010
} from 'fastify'
@@ -17,8 +17,8 @@ import {
1717
type ResponseSchemas,
1818
type ValidationFormatter,
1919
type Validations
20-
} from './interfaces.js'
21-
import { get } from './utils.js'
20+
} from './interfaces.ts'
21+
import { get } from './utils.ts'
2222

2323
// Fix CJS/ESM interoperability
2424

@@ -52,7 +52,9 @@ function buildAjv(options?: Options, plugins?: (Function | [Function, unknown])[
5252

5353
// Add plugins
5454
let formatPluginAdded = false
55+
/* c8 ignore next - else */
5556
for (const pluginSpec of plugins ?? []) {
57+
/* c8 ignore next - else */
5658
const [plugin, pluginOpts]: [Function, unknown] = Array.isArray(pluginSpec) ? pluginSpec : [pluginSpec, undefined]
5759

5860
if (plugin.name === 'formatsPlugin') {
@@ -330,6 +332,7 @@ export function compileResponseValidationSchema(this: FastifyInstance, configura
330332

331333
for (const [instance, validators, schemas] of this[kHttpErrorsEnhancedResponseValidations]) {
332334
// Create the compiler using exactly the same options as fastify
335+
/* c8 ignore next - else */
333336
const ajvOptions = (instance[kOptions as keyof FastifyInstance] as FastifyServerOptions)?.ajv ?? {}
334337
const compiler = buildAjv(ajvOptions.customOptions, ajvOptions.plugins)
335338

test.env

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/hooks.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import fastify, { type FastifyError, type FastifyInstance, type FastifyPluginOpt
22
import { INTERNAL_SERVER_ERROR } from 'http-errors-enhanced'
33
import { deepStrictEqual, match } from 'node:assert'
44
import { test } from 'node:test'
5-
import { plugin as fastifyHttpErrorsEnhanced } from '../src/index.js'
5+
import { plugin as fastifyHttpErrorsEnhanced } from '../src/index.ts'
66

77
async function buildServer(options: FastifyPluginOptions = {}): Promise<FastifyInstance> {
88
const server = fastify({

test/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
} from 'http-errors-enhanced'
1717
import { deepStrictEqual, match } from 'node:assert'
1818
import { test } from 'node:test'
19-
import { plugin as fastifyHttpErrorsEnhanced, handleErrors } from '../src/index.js'
19+
import { plugin as fastifyHttpErrorsEnhanced, handleErrors } from '../src/index.ts'
2020

2121
type Callback = () => void
2222

test/utils.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { deepStrictEqual, ifError } from 'node:assert'
22
import { test } from 'node:test'
3-
import { get, upperFirst } from '../src/utils.js'
3+
import { get, upperFirst } from '../src/utils.ts'
44

55
test('Utils', async () => {
66
await test('.upperFirst should correctly convert strings', () => {

0 commit comments

Comments
 (0)