Skip to content

Commit 8e64de0

Browse files
committed
feat: prepare @koa/bodyparser to v6.0.0
1 parent a3a9336 commit 8e64de0

File tree

5 files changed

+30
-30
lines changed

5 files changed

+30
-30
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ jobs:
1010
strategy:
1111
matrix:
1212
node-version:
13-
- 16
1413
- 18
1514
- 20
15+
- 22
1616
steps:
1717
- uses: actions/checkout@v3
1818
- name: Use Node.js ${{ matrix.node-version }}

.xo-config.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@
55
"xo-lass"
66
],
77
"rules": {
8+
"@typescript-eslint/restrict-template-expressions": "off",
9+
"@typescript-eslint/naming-convention": "off",
10+
"@typescript-eslint/prefer-nullish-coalescing": "off",
11+
"@typescript-eslint/prefer-reduce-type-parameter": "off",
812
"node/no-deprecated-api": "off",
913
"no-unused-vars": "off",
1014
"no-prototype-builtins": "off",
11-
"prefer-rest-params": "off",
15+
"n/file-extension-in-import": "off",
1216
"n/prefer-global/process": "off",
13-
"@typescript-eslint/restrict-template-expressions": "off",
14-
"@typescript-eslint/naming-convention": "off",
15-
"@typescript-eslint/prefer-nullish-coalescing": "off",
17+
"prefer-rest-params": "off",
1618
"unicorn/no-array-reduce": "off"
1719
},
1820
"ignores": [

package.json

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,31 +49,31 @@
4949
"@types/jest": "^29.5.0",
5050
"@types/koa": "^2.13.6",
5151
"@types/lodash.merge": "^4.6.7",
52-
"@types/node": "^18.15.11",
53-
"@types/supertest": "^2.0.12",
52+
"@types/node": "^22.15.21",
53+
"@types/supertest": "^6.0.3",
5454
"@types/type-is": "^1.6.3",
5555
"eslint-config-xo-lass": "^2.0.1",
56-
"husky": "^8.0.3",
57-
"jest": "^29.5.0",
58-
"koa": "^2.14.1",
59-
"supertest": "^6.3.3",
60-
"ts-jest": "^29.0.5",
61-
"ts-node": "^10.9.1",
62-
"tsup": "^6.7.0",
63-
"typescript": "^5.0.3",
64-
"xo": "^0.54.2"
56+
"husky": "^9.1.7",
57+
"jest": "^29.7.0",
58+
"koa": "^3.0.0",
59+
"supertest": "^7.1.1",
60+
"ts-jest": "^29.3.4",
61+
"ts-node": "^10.9.2",
62+
"tsup": "^8.5.0",
63+
"typescript": "^5.8.3",
64+
"xo": "^0.60.0"
6565
},
6666
"dependencies": {
67-
"@types/co-body": "^6.1.0",
68-
"co-body": "^6.1.0",
67+
"@types/co-body": "^6.1.3",
68+
"co-body": "^6.2.0",
6969
"lodash.merge": "^4.6.2",
70-
"type-is": "^1.6.18"
70+
"type-is": "^2.0.1"
7171
},
7272
"peerDependencies": {
73-
"koa": "^2.14.1"
73+
"koa": ">=2"
7474
},
7575
"engines": {
76-
"node": ">= 16"
76+
"node": ">= 18"
7777
},
7878
"repository": {
7979
"type": "git",

src/body-parser.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,12 @@ export function bodyParserWrapper(opts: BodyParserOptions = {}) {
4949
);
5050
};
5151

52-
const bodyType =
53-
detectJSON?.(ctx) || shouldParseBodyAs('json')
54-
? 'json'
55-
: shouldParseBodyAs('form')
56-
? 'form'
57-
: shouldParseBodyAs('text') || shouldParseBodyAs('xml')
58-
? 'text'
59-
: null;
52+
const bodyType = (() => {
53+
if (detectJSON?.(ctx) || shouldParseBodyAs('json')) return 'json';
54+
if (shouldParseBodyAs('form')) return 'form';
55+
if (shouldParseBodyAs('text') || shouldParseBodyAs('xml')) return 'text';
56+
return null;
57+
})();
6058

6159
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
6260
if (!bodyType) return {} as Record<string, string>;

test/middleware.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ describe("test/body-parser.test.ts", () => {
491491
describe("onError", () => {
492492
const app = createApp({
493493
onError({}, ctx) {
494-
ctx.throw("custom parse error", 422);
494+
ctx.throw(422, "custom parse error");
495495
},
496496
});
497497

0 commit comments

Comments
 (0)