Skip to content

Commit 948f05d

Browse files
authored
chore: enable oxfmt (#602)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added TypeScript declarations for FormStream methods (headers, file, field). * **Chores** * Enforced pnpm@10.24.0 and started versioning pnpm-lock.yaml. * Added formatting/typecheck scripts (fmt, fmtcheck, typecheck) and oxfmt dev dependency. * CI/workflow and formatter configuration updated for consistent formatting and quality checks. * **Documentation** * README formatting updated for improved argument styling. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 00d2439 commit 948f05d

File tree

83 files changed

+5305
-1132
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+5305
-1132
lines changed

.github/workflows/nodejs-16.yml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,25 @@ name: Node.js 16 CI
22

33
on:
44
push:
5-
branches: [ master ]
5+
branches: [master]
66
pull_request:
7-
branches: [ master ]
7+
branches: [master]
88

99
jobs:
10-
build:
11-
10+
test:
1211
runs-on: ubuntu-latest
12+
concurrency:
13+
group: typecheck-${{ github.workflow }}-#${{ github.event.pull_request.number || github.head_ref || github.ref }}
14+
cancel-in-progress: true
1315

1416
steps:
1517
- uses: actions/checkout@v4
1618
- name: Use Node.js
1719
uses: actions/setup-node@v4
1820
with:
19-
node-version: '16.x'
21+
node-version: 16
2022
- run: npm install
23+
- run: npm run ci
2124
- run: npm run prepublishOnly
2225
- run: node -v
23-
- run: npm run test-node16
26+
- run: npm run test-node16

.github/workflows/nodejs.yml

Lines changed: 78 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,85 @@ name: CI
22

33
on:
44
push:
5-
branches: [ master ]
5+
branches: [master]
66
pull_request:
7-
branches: [ master ]
7+
branches: [master]
88
merge_group:
99

1010
jobs:
11-
Job:
12-
name: Node.js
13-
uses: node-modules/github-actions/.github/workflows/node-test.yml@master
14-
with:
15-
os: 'ubuntu-latest, macos-latest, windows-latest'
16-
version: '16, 18, 20, 22, 24'
17-
secrets:
18-
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
11+
typecheck:
12+
runs-on: ubuntu-latest
13+
concurrency:
14+
group: typecheck-${{ github.workflow }}-#${{ github.event.pull_request.number || github.head_ref || github.ref }}
15+
cancel-in-progress: true
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
19+
20+
- name: Install pnpm
21+
uses: pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061 # v4
22+
23+
- name: Set up Node.js
24+
uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6
25+
with:
26+
node-version: '24'
27+
cache: 'pnpm'
28+
29+
- name: Install dependencies
30+
run: pnpm install --frozen-lockfile
31+
32+
- name: Run lint
33+
run: pnpm run lint
34+
35+
- name: Check dedupe
36+
run: pnpm dedupe --check
37+
38+
- name: Run typecheck
39+
run: pnpm run typecheck
40+
41+
- name: Run format check
42+
run: pnpm run fmtcheck
43+
44+
- name: Run build
45+
run: pnpm run build
46+
47+
test:
48+
strategy:
49+
fail-fast: false
50+
matrix:
51+
os: ['ubuntu-latest', 'macos-latest', 'windows-latest']
52+
node: ['18', '20', '22', '24']
53+
54+
name: Test (${{ matrix.os }}, ${{ matrix.node }})
55+
runs-on: ${{ matrix.os }}
56+
57+
concurrency:
58+
group: test-${{ github.workflow }}-#${{ github.event.pull_request.number || github.head_ref || github.ref }}-(${{ matrix.os }}, ${{ matrix.node }})
59+
cancel-in-progress: true
60+
61+
permissions:
62+
id-token: write
63+
64+
steps:
65+
- name: Checkout repository
66+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
67+
68+
- name: Install pnpm
69+
uses: pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061 # v4
70+
71+
- name: Set up Node.js
72+
uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6
73+
with:
74+
node-version: ${{ matrix.node }}
75+
cache: 'pnpm'
76+
77+
- name: Install dependencies
78+
run: pnpm install --frozen-lockfile
79+
80+
- name: Run tests
81+
run: pnpm run ci
82+
83+
- name: Code Coverage
84+
uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7 # v5
85+
with:
86+
use_oidc: true

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Release
22

33
on:
44
push:
5-
branches: [ master ]
5+
branches: [master]
66

77
jobs:
88
release:

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,3 @@ test/fixtures/ts-esm/*.js
1717
.eslintcache
1818
.tshy*
1919
.idea/
20-
pnpm-lock.yaml

.oxfmtrc.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"$schema": "./node_modules/oxfmt/configuration_schema.json",
3+
"printWidth": 120,
4+
"singleQuote": true,
5+
"ignorePatterns": ["CHANGELOG.md", "pnpm-lock.yaml"],
6+
"experimentalSortImports": {
7+
"groups": [
8+
["type-import"],
9+
["type-builtin", "value-builtin"],
10+
["type-external", "value-external", "type-internal", "value-internal"],
11+
["type-parent", "type-sibling", "type-index", "value-parent", "value-sibling", "value-index"],
12+
["ts-equals-import"],
13+
["unknown"]
14+
],
15+
"newlinesBetween": true,
16+
"order": "asc"
17+
}
18+
}

.oxlintrc.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
"env": {
44
"node": true
55
},
6-
"extends": [
7-
"./node_modules/@eggjs/oxlint-config/.oxlintrc.json"
8-
],
6+
"extends": ["./node_modules/@eggjs/oxlint-config/.oxlintrc.json"],
97
"categories": {
108
"correctness": "allow",
119
"suspicious": "allow",
@@ -126,4 +124,4 @@
126124
"arrow-body-style": "allow",
127125
"prefer-destructuring": "allow"
128126
}
129-
}
127+
}

README.md

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -56,30 +56,30 @@ console.log('status: %s, body size: %d, headers: %j', res.status, data.length, r
5656
#### Arguments
5757

5858
- **url** String | Object - The URL to request, either a String or a Object that return by [url.parse](https://nodejs.org/api/url.html#url_url_parse_urlstr_parsequerystring_slashesdenotehost).
59-
- ***options*** Object - Optional
60-
- ***method*** String - Request method, defaults to `GET`. Could be `GET`, `POST`, `DELETE` or `PUT`. Alias 'type'.
61-
- ***data*** Object - Data to be sent. Will be stringify automatically.
62-
- ***content*** String | [Buffer](https://nodejs.org/api/buffer.html) - Manually set the content of payload. If set, `data` will be ignored.
63-
- ***stream*** [stream.Readable](https://nodejs.org/api/stream.html#stream_class_stream_readable) - Stream to be pipe to the remote. If set, `data` and `content` will be ignored.
64-
- ***writeStream*** [stream.Writable](https://nodejs.org/api/stream.html#stream_class_stream_writable) - A writable stream to be piped by the response stream. Responding data will be write to this stream and `callback` will be called with `data` set `null` after finished writing.
65-
- ***files*** {Array<ReadStream|Buffer|String> | Object | ReadStream | Buffer | String - The files will send with `multipart/form-data` format, base on `formstream`. If `method` not set, will use `POST` method by default.
66-
- ***contentType*** String - Type of request data. Could be `json` (**Notes**: not use `application/json` here). If it's `json`, will auto set `Content-Type: application/json` header.
67-
- ***dataType*** String - Type of response data. Could be `text` or `json`. If it's `text`, the `callback`ed `data` would be a String. If it's `json`, the `data` of callback would be a parsed JSON Object and will auto set `Accept: application/json` header. Default `callback`ed `data` would be a `Buffer`.
68-
- ***fixJSONCtlChars*** Boolean - Fix the control characters (U+0000 through U+001F) before JSON parse response. Default is `false`.
69-
- ***headers*** Object - Request headers.
70-
- ***timeout*** Number | Array - Request timeout in milliseconds for connecting phase and response receiving phase. Default is `5000`. You can use `timeout: 5000` to tell urllib use same timeout on two phase or set them separately such as `timeout: [3000, 5000]`, which will set connecting timeout to 3s and response 5s.
71-
- ***keepAliveTimeout*** `number | null` - Default is `4000`, 4 seconds - The timeout after which a socket without active requests will time out. Monitors time between activity on a connected socket. This value may be overridden by *keep-alive* hints from the server. See [MDN: HTTP - Headers - Keep-Alive directives](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Keep-Alive#directives) for more details.
72-
- ***auth*** String - `username:password` used in HTTP Basic Authorization.
73-
- ***digestAuth*** String - `username:password` used in HTTP [Digest Authorization](https://en.wikipedia.org/wiki/Digest_access_authentication).
74-
- ***followRedirect*** Boolean - follow HTTP 3xx responses as redirects. defaults to true.
75-
- ***maxRedirects*** Number - The maximum number of redirects to follow, defaults to 10.
76-
- ***formatRedirectUrl*** Function - Format the redirect url by yourself. Default is `url.resolve(from, to)`.
77-
- ***beforeRequest*** Function - Before request hook, you can change every thing here.
78-
- ***streaming*** Boolean - lets you get the `res` object when request connected, default `false`. alias `customResponse`
79-
- ***compressed*** Boolean - Accept `gzip, br` response content and auto decode it, default is `false`.
80-
- ***timing*** Boolean - Enable timing or not, default is `true`.
81-
- ***socketPath*** String | null - request a unix socket service, default is `null`.
82-
- ***highWaterMark*** Number - default is `67108864`, 64 KiB.
59+
- **_options_** Object - Optional
60+
- **_method_** String - Request method, defaults to `GET`. Could be `GET`, `POST`, `DELETE` or `PUT`. Alias 'type'.
61+
- **_data_** Object - Data to be sent. Will be stringify automatically.
62+
- **_content_** String | [Buffer](https://nodejs.org/api/buffer.html) - Manually set the content of payload. If set, `data` will be ignored.
63+
- **_stream_** [stream.Readable](https://nodejs.org/api/stream.html#stream_class_stream_readable) - Stream to be pipe to the remote. If set, `data` and `content` will be ignored.
64+
- **_writeStream_** [stream.Writable](https://nodejs.org/api/stream.html#stream_class_stream_writable) - A writable stream to be piped by the response stream. Responding data will be write to this stream and `callback` will be called with `data` set `null` after finished writing.
65+
- **_files_** {Array<ReadStream|Buffer|String> | Object | ReadStream | Buffer | String - The files will send with `multipart/form-data` format, base on `formstream`. If `method` not set, will use `POST` method by default.
66+
- **_contentType_** String - Type of request data. Could be `json` (**Notes**: not use `application/json` here). If it's `json`, will auto set `Content-Type: application/json` header.
67+
- **_dataType_** String - Type of response data. Could be `text` or `json`. If it's `text`, the `callback`ed `data` would be a String. If it's `json`, the `data` of callback would be a parsed JSON Object and will auto set `Accept: application/json` header. Default `callback`ed `data` would be a `Buffer`.
68+
- **_fixJSONCtlChars_** Boolean - Fix the control characters (U+0000 through U+001F) before JSON parse response. Default is `false`.
69+
- **_headers_** Object - Request headers.
70+
- **_timeout_** Number | Array - Request timeout in milliseconds for connecting phase and response receiving phase. Default is `5000`. You can use `timeout: 5000` to tell urllib use same timeout on two phase or set them separately such as `timeout: [3000, 5000]`, which will set connecting timeout to 3s and response 5s.
71+
- **_keepAliveTimeout_** `number | null` - Default is `4000`, 4 seconds - The timeout after which a socket without active requests will time out. Monitors time between activity on a connected socket. This value may be overridden by _keep-alive_ hints from the server. See [MDN: HTTP - Headers - Keep-Alive directives](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Keep-Alive#directives) for more details.
72+
- **_auth_** String - `username:password` used in HTTP Basic Authorization.
73+
- **_digestAuth_** String - `username:password` used in HTTP [Digest Authorization](https://en.wikipedia.org/wiki/Digest_access_authentication).
74+
- **_followRedirect_** Boolean - follow HTTP 3xx responses as redirects. defaults to true.
75+
- **_maxRedirects_** Number - The maximum number of redirects to follow, defaults to 10.
76+
- **_formatRedirectUrl_** Function - Format the redirect url by yourself. Default is `url.resolve(from, to)`.
77+
- **_beforeRequest_** Function - Before request hook, you can change every thing here.
78+
- **_streaming_** Boolean - lets you get the `res` object when request connected, default `false`. alias `customResponse`
79+
- **_compressed_** Boolean - Accept `gzip, br` response content and auto decode it, default is `false`.
80+
- **_timing_** Boolean - Enable timing or not, default is `true`.
81+
- **_socketPath_** String | null - request a unix socket service, default is `null`.
82+
- **_highWaterMark_** Number - default is `67108864`, 64 KiB.
8383

8484
#### Options: `options.data`
8585

examples/h2-other-side-closed-exit-0-fetch.cjs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
const { fetch, setGlobalDispatcher, Agent } = require('..');
22

3-
setGlobalDispatcher(new Agent({
4-
allowH2: true,
5-
}));
3+
setGlobalDispatcher(
4+
new Agent({
5+
allowH2: true,
6+
}),
7+
);
68

79
async function main() {
810
for (let i = 0; i < 100; i++) {
@@ -21,13 +23,15 @@ async function main() {
2123
}
2224
}
2325

24-
main().then(() => {
25-
console.log('main end');
26-
}).catch(err => {
27-
console.error('main error throw: %s', err);
28-
// console.error(err);
29-
process.exit(1);
30-
});
26+
main()
27+
.then(() => {
28+
console.log('main end');
29+
})
30+
.catch((err) => {
31+
console.error('main error throw: %s', err);
32+
// console.error(err);
33+
process.exit(1);
34+
});
3135

3236
process.on('beforeExit', (...args) => {
3337
console.error('beforeExit', args);

examples/h2-other-side-closed-exit-0.cjs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
const { request, Agent, setGlobalDispatcher } = require('undici');
22

3-
setGlobalDispatcher(new Agent({
4-
allowH2: true,
5-
}));
3+
setGlobalDispatcher(
4+
new Agent({
5+
allowH2: true,
6+
}),
7+
);
68

79
async function main() {
810
for (let i = 0; i < 100; i++) {
@@ -21,13 +23,15 @@ async function main() {
2123
}
2224
}
2325

24-
main().then(() => {
25-
console.log('main end');
26-
}).catch(err => {
27-
console.error('main error throw: %s', err);
28-
// console.error(err);
29-
process.exit(1);
30-
});
26+
main()
27+
.then(() => {
28+
console.log('main end');
29+
})
30+
.catch((err) => {
31+
console.error('main error throw: %s', err);
32+
// console.error(err);
33+
process.exit(1);
34+
});
3135

3236
process.on('beforeExit', (...args) => {
3337
console.error('beforeExit', args);

examples/httpclient.cjs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,20 @@ function tryHttpclient(HttpClient, name) {
99
timing: true,
1010
};
1111
const urllib = new HttpClient();
12-
urllib.on('response', function(info) {
12+
urllib.on('response', function (info) {
1313
// console.log(name, httpAgent, httpAgent.getCurrentStatus());
1414
// console.log(name, httpsAgent, httpsAgent.getCurrentStatus());
1515
console.log('response', name, info.res);
1616
});
17-
urllib.request('https://nodejs.org', options)
18-
.then(function() {
17+
urllib
18+
.request('https://nodejs.org', options)
19+
.then(function () {
1920
return urllib.request('https://nodejs.org', options);
2021
})
21-
.then(function() {
22+
.then(function () {
2223
return urllib.request('https://nodejs.org/en/', options);
2324
})
24-
.catch(function(err) {
25+
.catch(function (err) {
2526
console.error('catch', err);
2627
});
2728
}

0 commit comments

Comments
 (0)