From f141253cfef4ba4ff0697716b5211f1fc292c0e7 Mon Sep 17 00:00:00 2001 From: SukkaW Date: Sun, 9 Aug 2026 18:32:00 +0800 Subject: [PATCH] Wire up Dead Domain CI Check for Node.js 26 [skip ci] --- Build/lib/fetch-retry.ts | 2 ++ Build/lib/is-domain-alive.test.ts | 20 ++++++++++++++++++++ Build/lib/is-domain-alive.ts | 18 ++++++++++++------ package.json | 4 ++-- pnpm-lock.yaml | 10 +++++----- 5 files changed, 41 insertions(+), 13 deletions(-) create mode 100644 Build/lib/is-domain-alive.test.ts diff --git a/Build/lib/fetch-retry.ts b/Build/lib/fetch-retry.ts index c3d6b9e2..2552c50c 100644 --- a/Build/lib/fetch-retry.ts +++ b/Build/lib/fetch-retry.ts @@ -174,6 +174,8 @@ const agent = new Agent({ }) ); +export { agent as fetchAgent }; + export interface FetchResponseProgress { onResponseStart?: (contentEncoding: string | null) => void, onEncodedBodyChunk?: (bytes: number) => void, diff --git a/Build/lib/is-domain-alive.test.ts b/Build/lib/is-domain-alive.test.ts new file mode 100644 index 00000000..53fd8a27 --- /dev/null +++ b/Build/lib/is-domain-alive.test.ts @@ -0,0 +1,20 @@ +import { describe, it } from 'mocha'; +import { expect } from 'earl'; +import { DOMAIN_ALIVE_REASON_MESSAGES, DOMAIN_ALIVE_REASONS } from 'domain-alive'; +import { createDomainAliveMethods } from './is-domain-alive'; + +describe('domain-alive integration', () => { + it('constructs the checkers with the custom DoH agent', async () => { + const { isDomainAlive, isRegisterableDomainAlive } = createDomainAliveMethods({}); + const [domainResult, registerableDomainResult] = await Promise.all([ + isDomainAlive(''), + isRegisterableDomainAlive('') + ]); + + expect(domainResult.reason).toEqual(DOMAIN_ALIVE_REASONS.INVALID_DOMAIN); + expect(registerableDomainResult.reason).toEqual(DOMAIN_ALIVE_REASONS.INVALID_DOMAIN); + expect(DOMAIN_ALIVE_REASON_MESSAGES[domainResult.reason]).toEqual( + 'No registerable domain could be extracted.' + ); + }); +}); diff --git a/Build/lib/is-domain-alive.ts b/Build/lib/is-domain-alive.ts index 3636274e..446c60bf 100644 --- a/Build/lib/is-domain-alive.ts +++ b/Build/lib/is-domain-alive.ts @@ -1,5 +1,5 @@ import { createDomainAliveChecker, createRegisterableDomainAliveChecker } from 'domain-alive'; -import { $$fetch, fetchForDoH } from './fetch-retry'; +import { $$fetch, fetchAgent, fetchForDoH } from './fetch-retry'; const dnsServers = [ 'https://8.8.8.8/dns-query', 'https://8.8.4.4/dns-query', @@ -55,14 +55,13 @@ const dnsServers = [ const resultCache = new Map(); const registerableDomainResultCache = new Map(); -export async function getMethods() { - const customWhoisServersMapping = await (await ($$fetch('https://cdn.jsdelivr.net/npm/whois-servers-list@latest/list.json'))).json() as any; - +export function createDomainAliveMethods(customWhoisServersMapping: Record) { const isRegisterableDomainAlive = createRegisterableDomainAliveChecker({ dns: { dnsServers, maxAttempts: 6, - customFetchForDoH: fetchForDoH as typeof fetch + customFetchForDoH: fetchForDoH as typeof fetch, + customAgentForDoH: fetchAgent }, registerableDomainResultCache, whois: { @@ -74,7 +73,8 @@ export async function getMethods() { dns: { dnsServers, maxAttempts: 6, - customFetchForDoH: fetchForDoH as typeof fetch + customFetchForDoH: fetchForDoH as typeof fetch, + customAgentForDoH: fetchAgent }, registerableDomainResultCache, resultCache, @@ -84,4 +84,10 @@ export async function getMethods() { }); return { isRegisterableDomainAlive, isDomainAlive }; +} + +export async function getMethods() { + const customWhoisServersMapping = await (await ($$fetch('https://cdn.jsdelivr.net/npm/whois-servers-list@latest/list.json'))).json() as Record; + + return createDomainAliveMethods(customWhoisServersMapping); }; diff --git a/package.json b/package.json index 3661aa11..416c21e6 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "build-profile": "pnpm run dexnode -r @swc-node/register ./Build/index.ts", "bench-download": "pnpm run node ./Build/benchmark-download-client.ts", "lint": "eslint --format=sukka .", - "test": "SWC_NODE_IGNORE_DYNAMIC=true SWC_NODE_PROJECT=tsconfig.test.json mocha --require @swc-node/register --watch-extensions ts,tsx" + "test": "SWC_NODE_IGNORE_DYNAMIC=true SWC_NODE_PROJECT=tsconfig.test.json mocha --require @swc-node/register --watch-extensions ts,tsx \"Build/**/*.test.ts\"" }, "author": "", "license": "ISC", @@ -26,7 +26,7 @@ "ci-info": "^4.4.0", "cli-progress": "^3.12.0", "csv-parse": "^7.0.2", - "domain-alive": "^0.1.24", + "domain-alive": "^0.1.25", "fast-cidr-tools": "^0.3.4", "fast-escape-regexp": "^1.0.1", "fast-uri": "^4.1.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9ceaaed5..95bf8448 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -33,8 +33,8 @@ importers: specifier: ^7.0.2 version: 7.0.2 domain-alive: - specifier: ^0.1.24 - version: 0.1.24(supports-color@8.1.1) + specifier: ^0.1.25 + version: 0.1.25(supports-color@8.1.1) fast-cidr-tools: specifier: ^0.3.4 version: 0.3.4 @@ -1161,8 +1161,8 @@ packages: dom-serializer@1.4.1: resolution: {integrity: sha512-VHwB3KfrcOOkelEG2ZOfxqLZdfkil8PtJi4P8N2MMXucZq2yLp75ClViUlOVwyoHEDjYU433Aq+5zWP61+RGag==} - domain-alive@0.1.24: - resolution: {integrity: sha512-/KogFcl5dnHaxKMQyWARruBtXthGaiKoIH8G61/0knCEMr59ymrYabsADbJDYjN7O0+K+0qBqdh9ewjOhLkeEw==} + domain-alive@0.1.25: + resolution: {integrity: sha512-S3NXngSmSg2DBQHdrfzSGWe96yqIm19LJORvYqoVDXkLyG0tDoQTwbGorgbCkFkCakBdoq9KTAsjTkFNi2fMbQ==} domelementtype@2.3.0: resolution: {integrity: sha512-OLETBj6w0OsagBwdXnPdN0cnMfF9opN69co+7ZrbfPGrdpPVNBUj02spi6B1N7wChLQiPn4CSH/zJvXw56gmHw==} @@ -2957,7 +2957,7 @@ snapshots: domhandler: 4.3.1 entities: 2.2.0 - domain-alive@0.1.24(supports-color@8.1.1): + domain-alive@0.1.25(supports-color@8.1.1): dependencies: debug: 4.4.3(supports-color@8.1.1) foxts: 5.9.1