From 5ee5c29b69d382b4d601d58b227c476e8129b458 Mon Sep 17 00:00:00 2001 From: Randolf Jung Date: Wed, 1 Jun 2022 13:23:37 +0200 Subject: [PATCH] feat: support node 18 --- .github/workflows/ci.yml | 2 +- src/node/NodeWebSocketTransport.ts | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3c845a8d801fc..00531cba7ffcd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,7 +23,7 @@ jobs: matrix: # Include all major maintenance + active LTS + current Node.js versions. # https://github.com/nodejs/Release#release-schedule - node: [14, 16] + node: [14, 16, 18] steps: - name: Checkout uses: actions/checkout@v3 diff --git a/src/node/NodeWebSocketTransport.ts b/src/node/NodeWebSocketTransport.ts index 78a60781e6a8b..b178e0e180a18 100644 --- a/src/node/NodeWebSocketTransport.ts +++ b/src/node/NodeWebSocketTransport.ts @@ -16,9 +16,20 @@ import NodeWebSocket from 'ws'; import { ConnectionTransport } from '../common/ConnectionTransport.js'; import { packageVersion } from '../generated/version.js'; +import { promises as dns } from 'dns'; export class NodeWebSocketTransport implements ConnectionTransport { - static create(url: string): Promise { + static async create(urlString: string): Promise { + // Starting in Node 17, IPv6 is favoured over IPv4 due to a change in a default + // option: + // - https://github.com/nodejs/node/issues/40537, + // Due to this, we parse and resolve the hostname manually with the previous + // behavior according to: + // - https://nodejs.org/api/dns.html#dnslookuphostname-options-callback + const url = new URL(urlString); + const { address } = await dns.lookup(url.hostname, { verbatim: false }); + url.hostname = address; + return new Promise((resolve, reject) => { const ws = new NodeWebSocket(url, [], { followRedirects: true,