diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 39bec85..52a3ddb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,9 +10,9 @@ jobs: strategy: matrix: node-version: - - 16 - 18 - 20 + - 22 steps: - uses: actions/checkout@v3 - name: Use Node.js ${{ matrix.node-version }} diff --git a/.xo-config.json b/.xo-config.json index d78ad10..31fb330 100644 --- a/.xo-config.json +++ b/.xo-config.json @@ -5,14 +5,16 @@ "xo-lass" ], "rules": { + "@typescript-eslint/restrict-template-expressions": "off", + "@typescript-eslint/naming-convention": "off", + "@typescript-eslint/prefer-nullish-coalescing": "off", + "@typescript-eslint/prefer-reduce-type-parameter": "off", "node/no-deprecated-api": "off", "no-unused-vars": "off", "no-prototype-builtins": "off", - "prefer-rest-params": "off", + "n/file-extension-in-import": "off", "n/prefer-global/process": "off", - "@typescript-eslint/restrict-template-expressions": "off", - "@typescript-eslint/naming-convention": "off", - "@typescript-eslint/prefer-nullish-coalescing": "off", + "prefer-rest-params": "off", "unicorn/no-array-reduce": "off" }, "ignores": [ diff --git a/package.json b/package.json index 2f6e4b0..0103c6d 100644 --- a/package.json +++ b/package.json @@ -49,31 +49,31 @@ "@types/jest": "^29.5.0", "@types/koa": "^2.13.6", "@types/lodash.merge": "^4.6.7", - "@types/node": "^18.15.11", - "@types/supertest": "^2.0.12", + "@types/node": "^22.15.21", + "@types/supertest": "^6.0.3", "@types/type-is": "^1.6.3", "eslint-config-xo-lass": "^2.0.1", - "husky": "^8.0.3", - "jest": "^29.5.0", - "koa": "^2.14.1", - "supertest": "^6.3.3", - "ts-jest": "^29.0.5", - "ts-node": "^10.9.1", - "tsup": "^6.7.0", - "typescript": "^5.0.3", - "xo": "^0.54.2" + "husky": "^9.1.7", + "jest": "^29.7.0", + "koa": "^3.0.0", + "supertest": "^7.1.1", + "ts-jest": "^29.3.4", + "ts-node": "^10.9.2", + "tsup": "^8.5.0", + "typescript": "^5.8.3", + "xo": "^0.60.0" }, "dependencies": { - "@types/co-body": "^6.1.0", - "co-body": "^6.1.0", + "@types/co-body": "^6.1.3", + "co-body": "^6.2.0", "lodash.merge": "^4.6.2", - "type-is": "^1.6.18" + "type-is": "^2.0.1" }, "peerDependencies": { - "koa": "^2.14.1" + "koa": ">=2" }, "engines": { - "node": ">= 16" + "node": ">= 18" }, "repository": { "type": "git", diff --git a/src/body-parser.ts b/src/body-parser.ts index 3092846..c6740b1 100644 --- a/src/body-parser.ts +++ b/src/body-parser.ts @@ -49,14 +49,12 @@ export function bodyParserWrapper(opts: BodyParserOptions = {}) { ); }; - const bodyType = - detectJSON?.(ctx) || shouldParseBodyAs('json') - ? 'json' - : shouldParseBodyAs('form') - ? 'form' - : shouldParseBodyAs('text') || shouldParseBodyAs('xml') - ? 'text' - : null; + const bodyType = (() => { + if (detectJSON?.(ctx) || shouldParseBodyAs('json')) return 'json'; + if (shouldParseBodyAs('form')) return 'form'; + if (shouldParseBodyAs('text') || shouldParseBodyAs('xml')) return 'text'; + return null; + })(); // eslint-disable-next-line @typescript-eslint/consistent-type-assertions if (!bodyType) return {} as Record; diff --git a/test/middleware.test.ts b/test/middleware.test.ts index 00af3ce..f8ea138 100644 --- a/test/middleware.test.ts +++ b/test/middleware.test.ts @@ -491,7 +491,7 @@ describe("test/body-parser.test.ts", () => { describe("onError", () => { const app = createApp({ onError({}, ctx) { - ctx.throw("custom parse error", 422); + ctx.throw(422, "custom parse error"); }, });