From 663d40062440e5b13c9a2926562883ebd55ec93c Mon Sep 17 00:00:00 2001 From: Feng Yu Date: Sat, 28 May 2022 14:04:37 +0800 Subject: [PATCH] dns: move setServers to internal/dns/promise.js --- lib/dns.js | 1 - lib/dns/promises.js | 4 +--- lib/internal/dns/promises.js | 16 +++++++++++++++- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/dns.js b/lib/dns.js index e969ad2b80658d..02e007b54ec26b 100644 --- a/lib/dns.js +++ b/lib/dns.js @@ -386,7 +386,6 @@ ObjectDefineProperties(module.exports, { get() { if (promises === null) { promises = require('internal/dns/promises'); - promises.setServers = defaultResolverSetServers; } return promises; } diff --git a/lib/dns/promises.js b/lib/dns/promises.js index ad8a2561ef51e4..35881e5bb47374 100644 --- a/lib/dns/promises.js +++ b/lib/dns/promises.js @@ -1,5 +1,3 @@ 'use strict'; -const dnsPromises = require('internal/dns/promises'); -dnsPromises.setServers = require('dns').setServers; -module.exports = dnsPromises; +module.exports = require('internal/dns/promises'); diff --git a/lib/internal/dns/promises.js b/lib/internal/dns/promises.js index a12e52c0012d0f..4e4e385f2eb758 100644 --- a/lib/internal/dns/promises.js +++ b/lib/internal/dns/promises.js @@ -17,6 +17,7 @@ const { emitInvalidHostnameWarning, getDefaultVerbatim, setDefaultResultOrder, + setDefaultResolver, } = require('internal/dns/utils'); const { codes, dnsException } = require('internal/errors'); const { toASCII } = require('internal/idna'); @@ -313,6 +314,19 @@ Resolver.prototype.resolve = function resolve(hostname, rrtype) { return ReflectApply(resolver, this, [hostname]); }; +function defaultResolverSetServers(servers) { + const resolver = new Resolver(); -module.exports = { lookup, lookupService, Resolver, setDefaultResultOrder }; + resolver.setServers(servers); + setDefaultResolver(resolver); + bindDefaultResolver(module.exports, Resolver.prototype); +} + +module.exports = { + lookup, + lookupService, + Resolver, + setDefaultResultOrder, + setServers: defaultResolverSetServers, +}; bindDefaultResolver(module.exports, Resolver.prototype);