Skip to content

Commit 1f0b643

Browse files
authored
Update Node 24 (#2414)
1 parent 90385ae commit 1f0b643

18 files changed

+147
-157
lines changed

.changeset/stupid-candies-fetch.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@whatwg-node/node-fetch': patch
3+
---
4+
5+
Improvements for Node 24 and use `once` from `node:events` for Promise-based event handling whenever
6+
possible

.github/workflows/benchmarks.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
- name: Setup env
3131
uses: the-guild-org/shared-config/setup@main
3232
with:
33-
nodeVersion: 23
33+
nodeVersion: 24
3434
packageManager: yarn
3535
- name: Build Packages
3636
run: yarn build
@@ -74,7 +74,7 @@ jobs:
7474
- name: Setup env
7575
uses: the-guild-org/shared-config/setup@main
7676
with:
77-
nodeVersion: 23
77+
nodeVersion: 24
7878
packageManager: yarn
7979
- name: Setup K6
8080
run: |

.github/workflows/pr.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
with:
3232
npmTag: alpha
3333
buildScript: build
34-
nodeVersion: 22
34+
nodeVersion: 24
3535
secrets:
3636
githubToken: ${{ secrets.GITHUB_TOKEN }}
3737
npmToken: ${{ secrets.NODE_AUTH_TOKEN }}
@@ -48,7 +48,7 @@ jobs:
4848
with:
4949
npmTag: rc
5050
buildScript: build
51-
nodeVersion: 23
51+
nodeVersion: 24
5252
restoreDeletedChangesets: true
5353
secrets:
5454
githubToken: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
uses: the-guild-org/shared-config/.github/workflows/release-stable.yml@main
1919
with:
2020
releaseScript: release
21-
nodeVersion: 22
21+
nodeVersion: 24
2222
secrets:
2323
githubToken: ${{ secrets.GITHUB_TOKEN }}
2424
npmToken: ${{ secrets.NODE_AUTH_TOKEN }}

.github/workflows/tests.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
- name: Setup env
3030
uses: the-guild-org/shared-config/setup@main
3131
with:
32-
nodeVersion: 23
32+
nodeVersion: 24
3333
- name: Prettier Check
3434
run: yarn prettier:check
3535
lint:
@@ -43,7 +43,7 @@ jobs:
4343
- name: Setup env
4444
uses: the-guild-org/shared-config/setup@main
4545
with:
46-
nodeVersion: 23
46+
nodeVersion: 24
4747
- name: ESLint
4848
run: yarn lint
4949

@@ -58,7 +58,7 @@ jobs:
5858
- name: Setup env
5959
uses: the-guild-org/shared-config/setup@main
6060
with:
61-
nodeVersion: 23
61+
nodeVersion: 24
6262
- name: Type Check
6363
run: yarn ts:check
6464

@@ -72,7 +72,7 @@ jobs:
7272
- 8888:80
7373
strategy:
7474
matrix:
75-
node-version: [18, 20, 22, 23]
75+
node-version: [18, 20, 23, 24]
7676
fail-fast: false
7777
steps:
7878
- name: Checkout Master
@@ -119,7 +119,7 @@ jobs:
119119
- name: Setup env
120120
uses: the-guild-org/shared-config/setup@main
121121
with:
122-
nodeVersion: 23
122+
nodeVersion: 24
123123
- name: Test
124124
run: yarn test:bun --ci
125125

@@ -139,7 +139,7 @@ jobs:
139139
- name: Setup env
140140
uses: the-guild-org/shared-config/setup@main
141141
with:
142-
nodeVersion: 23
142+
nodeVersion: 24
143143
- name: Test
144144
uses: nick-fields/retry@ce71cc2ab81d554ebbe88c79ab5975992d79ba08 # v3
145145
with:
@@ -158,7 +158,7 @@ jobs:
158158
- name: Setup env
159159
uses: the-guild-org/shared-config/setup@main
160160
with:
161-
nodeVersion: 23
161+
nodeVersion: 24
162162
- name: Build Packages
163163
run: yarn build
164164
- name: Test ESM
@@ -200,7 +200,7 @@ jobs:
200200
- name: Setup Node
201201
uses: actions/setup-node@master
202202
with:
203-
node-version: 23
203+
node-version: 24
204204

205205
- name: Install Required Libraries
206206
run: sudo apt update && sudo apt install -y libcurl4-openssl-dev libssl-dev

.node-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v23
1+
v24

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"ts:check": "tsc --noEmit --skipLibCheck"
3030
},
3131
"optionalDependencies": {
32+
"node-libcurl": "4.1.0",
3233
"uWebSockets.js": "uNetworking/uWebSockets.js#v20.52.0"
3334
},
3435
"devDependencies": {
@@ -64,7 +65,6 @@
6465
"husky": "9.1.7",
6566
"jest": "29.7.0",
6667
"lint-staged": "16.0.0",
67-
"node-libcurl": "4.1.0",
6868
"patch-package": "8.0.0",
6969
"prettier": "3.5.3",
7070
"rimraf": "6.0.1",

packages/node-fetch/src/ReadableStream.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { Buffer } from 'node:buffer';
2+
import { once } from 'node:events';
23
import { Readable } from 'node:stream';
4+
import { pipeline } from 'node:stream/promises';
35
import { handleMaybePromise } from '@whatwg-node/promise-helpers';
46
import { fakePromise } from './utils.js';
57
import { PonyfillWritableStream } from './WritableStream.js';
@@ -144,7 +146,8 @@ export class PonyfillReadableStream<T> implements ReadableStream<T> {
144146

145147
cancel(reason?: any): Promise<void> {
146148
this.readable.destroy(reason);
147-
return new Promise(resolve => this.readable.once('end', resolve));
149+
// @ts-expect-error - we know it is void
150+
return once(this.readable, 'close');
148151
}
149152

150153
locked = false;
@@ -154,6 +157,7 @@ export class PonyfillReadableStream<T> implements ReadableStream<T> {
154157
getReader(_options?: ReadableStreamGetReaderOptions): ReadableStreamReader<T> {
155158
const iterator = this.readable[Symbol.asyncIterator]();
156159
this.locked = true;
160+
const thisReadable = this.readable;
157161
return {
158162
read() {
159163
return iterator.next() as Promise<ReadableStreamReadResult<T>>;
@@ -182,10 +186,12 @@ export class PonyfillReadableStream<T> implements ReadableStream<T> {
182186
this.locked = false;
183187
return fakePromise();
184188
},
185-
closed: new Promise((resolve, reject) => {
186-
this.readable.once('end', resolve);
187-
this.readable.once('error', reject);
188-
}),
189+
get closed() {
190+
return Promise.race([
191+
once(thisReadable, 'end'),
192+
once(thisReadable, 'error').then(err => Promise.reject(err)),
193+
]) as Promise<any>;
194+
},
189195
};
190196
}
191197

@@ -228,10 +234,8 @@ export class PonyfillReadableStream<T> implements ReadableStream<T> {
228234

229235
pipeTo(destination: WritableStream<T>): Promise<void> {
230236
if (isPonyfillWritableStream(destination)) {
231-
return new Promise((resolve, reject) => {
232-
this.readable.pipe(destination.writable);
233-
destination.writable.once('finish', resolve);
234-
destination.writable.once('error', reject);
237+
return pipeline(this.readable, destination.writable, {
238+
end: true,
235239
});
236240
} else {
237241
const writer = destination.getWriter();

packages/node-fetch/src/TextEncoderDecoderStream.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ export class PonyfillTextDecoderStream
88
private textDecoder: TextDecoder;
99
constructor(encoding?: BufferEncoding, options?: TextDecoderOptions) {
1010
super({
11-
transform: (chunk, controller) => {
12-
controller.enqueue(this.textDecoder.decode(chunk, { stream: true }));
13-
},
11+
transform: (chunk, controller) =>
12+
controller.enqueue(this.textDecoder.decode(chunk, { stream: true })),
1413
});
1514
this.textDecoder = new PonyfillTextDecoder(encoding, options);
1615
}
@@ -35,9 +34,7 @@ export class PonyfillTextEncoderStream
3534
private textEncoder: TextEncoder;
3635
constructor(encoding?: BufferEncoding) {
3736
super({
38-
transform: (chunk, controller) => {
39-
controller.enqueue(this.textEncoder.encode(chunk));
40-
},
37+
transform: (chunk, controller) => controller.enqueue(this.textEncoder.encode(chunk)),
4138
});
4239
this.textEncoder = new PonyfillTextEncoder(encoding);
4340
}

packages/node-fetch/src/WritableStream.ts

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { once } from 'node:events';
12
import { Writable } from 'node:stream';
23
import { fakeRejectPromise } from '@whatwg-node/promise-helpers';
34
import { endStream, fakePromise, safeWrite } from './utils.js';
@@ -62,19 +63,15 @@ export class PonyfillWritableStream<W = any> implements WritableStream<W> {
6263
getWriter(): WritableStreamDefaultWriter<W> {
6364
const writable = this.writable;
6465
return {
65-
closed: new Promise<undefined>(resolve => {
66-
writable.once('close', () => {
67-
resolve(undefined);
68-
});
69-
}),
66+
get closed() {
67+
return once(writable, 'close') as Promise<any>;
68+
},
7069
get desiredSize() {
7170
return writable.writableLength;
7271
},
73-
ready: new Promise<undefined>(resolve => {
74-
writable.once('drain', () => {
75-
resolve(undefined);
76-
});
77-
}),
72+
get ready() {
73+
return once(writable, 'drain') as Promise<any>;
74+
},
7875
releaseLock() {
7976
// no-op
8077
},
@@ -95,10 +92,8 @@ export class PonyfillWritableStream<W = any> implements WritableStream<W> {
9592
return fakePromise().then(() => endStream(writable));
9693
},
9794
abort(reason) {
98-
return new Promise<void>(resolve => {
99-
writable.destroy(reason);
100-
writable.once('close', resolve);
101-
});
95+
writable.destroy(reason);
96+
return once(writable, 'close') as Promise<any>;
10297
},
10398
};
10499
}
@@ -114,10 +109,8 @@ export class PonyfillWritableStream<W = any> implements WritableStream<W> {
114109
}
115110

116111
abort(reason: any): Promise<void> {
117-
return new Promise<void>(resolve => {
118-
this.writable.destroy(reason);
119-
this.writable.once('close', resolve);
120-
});
112+
this.writable.destroy(reason);
113+
return once(this.writable, 'close') as Promise<any>;
121114
}
122115

123116
locked = false;

0 commit comments

Comments
 (0)