Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade Undici to v6.7.0 #85

Merged
merged 2 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@
},
"homepage": "https://github.com/elastic/elastic-transport-js#readme",
"engines": {
"node": ">=16"
"node": ">=18"
},
"devDependencies": {
"@sinonjs/fake-timers": "github:sinonjs/fake-timers#0bfffc1",
"@types/debug": "^4.1.7",
"@types/ms": "^0.7.31",
"@types/node": "^17.0.31",
"@types/node": "^18.19.21",
"@types/sinonjs__fake-timers": "^8.1.2",
"@types/stoppable": "^1.1.1",
"@types/tap": "^15.0.7",
Expand All @@ -64,7 +64,7 @@
"ms": "^2.1.3",
"secure-json-parse": "^2.4.0",
"tslib": "^2.4.0",
"undici": "^5.22.1"
"undici": "^6.7.0"
},
"tap": {
"ts": true,
Expand Down
2 changes: 1 addition & 1 deletion src/connection/UndiciConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ export default class Connection extends BaseConnection {
timeoutId = setTimeout(() => {
timedout = true
if (options.signal != null) {
// @ts-expect-error Event is a Node.js global
options.signal.dispatchEvent(new Event('abort'))
} else {
this[kEmitter].emit('abort')
Expand All @@ -165,6 +164,7 @@ export default class Connection extends BaseConnection {
if (timeoutId != null) clearTimeout(timeoutId)
switch (err.code) {
case 'UND_ERR_ABORTED':
case DOMException.ABORT_ERR:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain why you added DOM support? This library is not intended to be run in a browser.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because Undici's request seems to possibly throw a DOMException also in the node environment, which causes the unit test to fail if the DOMException is not caught here.

I see in Undici's own test that they test it against DOMException as well: https://github.com/nodejs/undici/blob/main/test/node-test/abort-controller.js (Line 126).

Node.js supports DOMException in the globals since v17. That's why I added it here.

throw (timedout ? new TimeoutError('Request timed out') : new RequestAbortedError('Request aborted'))
case 'UND_ERR_HEADERS_TIMEOUT':
throw new TimeoutError('Request timed out')
Expand Down
2 changes: 1 addition & 1 deletion test/unit/http-connection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1266,7 +1266,7 @@ test('Cleanup abort listener', async t => {
method: 'GET',
}, {
...options,
signal: controller.signal
signal: controller.signal as AbortSignal
})
// @ts-expect-error
t.equal(controller.signal.eventEmitter.listeners('abort').length, 0)
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"importHelpers": true,
"outDir": "lib",
"lib": [
"esnext"
"esnext",
"dom"
]
},
"formatCodeOptions": {
Expand Down
Loading