From 54f51ebc73505c4d2f2c0330edf9b015c75bd822 Mon Sep 17 00:00:00 2001 From: CosminPerRam Date: Thu, 12 Sep 2024 19:45:33 +0300 Subject: [PATCH] feat: remove punycode package (#630) * feat: remove punycode package * fix(deno): specify node scope in import --- lib/DnsResolver.js | 8 ++++++-- package-lock.json | 5 +++-- package.json | 1 - 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/DnsResolver.js b/lib/DnsResolver.js index 8cadd8f..e7238d2 100644 --- a/lib/DnsResolver.js +++ b/lib/DnsResolver.js @@ -1,6 +1,6 @@ import dns from 'node:dns' import { isIP } from 'node:net' -import punycode from 'punycode/punycode.js' +import { domainToASCII } from 'node:url' export default class DnsResolver { /** @@ -30,7 +30,11 @@ export default class DnsResolver { return { address: host } } - const asciiForm = punycode.toASCII(host) + const asciiForm = domainToASCII(host) + if (!asciiForm) { + throw new Error('Invalid domain') + } + if (asciiForm !== host) { this.logger.debug('Encoded punycode: ' + host + ' -> ' + asciiForm) host = asciiForm diff --git a/package-lock.json b/package-lock.json index e5a0bfd..5945826 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,7 +15,6 @@ "iconv-lite": "0.6.3", "long": "5.2.3", "minimist": "1.2.8", - "punycode": "2.3.1", "seek-bzip": "2.0.0", "varint": "6.0.0" }, @@ -2839,6 +2838,7 @@ "version": "2.3.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", "integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==", + "dev": true, "engines": { "node": ">=6" } @@ -5440,7 +5440,8 @@ "punycode": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", - "integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==" + "integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==", + "dev": true }, "queue-microtask": { "version": "1.2.3", diff --git a/package.json b/package.json index 5755101..9a88fa0 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,6 @@ "iconv-lite": "0.6.3", "long": "5.2.3", "minimist": "1.2.8", - "punycode": "2.3.1", "seek-bzip": "2.0.0", "varint": "6.0.0" },