From a7ec15f35de0f4eb4b873888a752faf2a11154e3 Mon Sep 17 00:00:00 2001 From: Feng Yu Date: Sat, 28 May 2022 13:26:56 +0800 Subject: [PATCH] dns: make promise API fully constructed from `lib/internal/dns/promises` --- lib/dns.js | 2 -- lib/dns/promises.js | 4 +--- lib/internal/dns/promises.js | 11 +++++++++++ 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/dns.js b/lib/dns.js index 351fa43f357f4d..97793eb12aaf3a 100644 --- a/lib/dns.js +++ b/lib/dns.js @@ -439,8 +439,6 @@ ObjectDefineProperties(module.exports, { get() { if (promises === null) { promises = require('internal/dns/promises'); - promises.setServers = defaultResolverSetServers; - promises.setDefaultResultOrder = setDefaultResultOrder; } 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 395b059758f36f..334260923faa7b 100644 --- a/lib/internal/dns/promises.js +++ b/lib/internal/dns/promises.js @@ -17,6 +17,8 @@ const { emitInvalidHostnameWarning, getDefaultVerbatim, errorCodes: dnsErrorCodes, + setDefaultResultOrder, + setDefaultResolver, } = require('internal/dns/utils'); const { NODATA, @@ -349,11 +351,20 @@ Resolver.prototype.resolve = function resolve(hostname, rrtype) { return ReflectApply(resolver, this, [hostname]); }; +function defaultResolverSetServers(servers) { + const resolver = new Resolver(); + + resolver.setServers(servers); + setDefaultResolver(resolver); + bindDefaultResolver(module.exports, Resolver.prototype); +} module.exports = { lookup, lookupService, Resolver, + setDefaultResultOrder, + setServers: defaultResolverSetServers, // ERROR CODES NODATA,