feat: support node 18 (#8447)

This commit is contained in:
jrandolf 2022-06-01 13:53:17 +02:00 committed by GitHub
parent 9dc9a9477c
commit f2d8276d6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 2 deletions

View File

@ -23,7 +23,7 @@ jobs:
matrix: matrix:
# Include all major maintenance + active LTS + current Node.js versions. # Include all major maintenance + active LTS + current Node.js versions.
# https://github.com/nodejs/Release#release-schedule # https://github.com/nodejs/Release#release-schedule
node: [14, 16] node: [14, 16, 18]
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v3 uses: actions/checkout@v3

View File

@ -16,9 +16,21 @@
import NodeWebSocket from 'ws'; import NodeWebSocket from 'ws';
import { ConnectionTransport } from '../common/ConnectionTransport.js'; import { ConnectionTransport } from '../common/ConnectionTransport.js';
import { packageVersion } from '../generated/version.js'; import { packageVersion } from '../generated/version.js';
import { promises as dns } from 'dns';
export class NodeWebSocketTransport implements ConnectionTransport { export class NodeWebSocketTransport implements ConnectionTransport {
static create(url: string): Promise<NodeWebSocketTransport> { static async create(urlString: string): Promise<NodeWebSocketTransport> {
// TODO(jrandolf): 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
// because of https://bugzilla.mozilla.org/show_bug.cgi?id=1769994.
const url = new URL(urlString);
const { address } = await dns.lookup(url.hostname, { verbatim: false });
url.hostname = address;
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const ws = new NodeWebSocket(url, [], { const ws = new NodeWebSocket(url, [], {
followRedirects: true, followRedirects: true,