From 8d2a256bf4579f4c90ba2a6e9bdffba3da6f93c0 Mon Sep 17 00:00:00 2001 From: Feng Yu Date: Tue, 21 Jun 2022 02:58:45 +0800 Subject: [PATCH] dns: make promise API fully constructed from `lib/internal/dns/promises` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/43227 Refs: https://github.com/nodejs/node/discussions/43198 Reviewed-By: Matteo Collina Reviewed-By: Michaƫl Zasso Reviewed-By: Luigi Pinca Reviewed-By: Minwoo Jung --- 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 7d3b2d46b6e5db..233c551212c56d 100644 --- a/lib/dns.js +++ b/lib/dns.js @@ -415,8 +415,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 633ed44fed747e..062753c0430ff2 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, @@ -335,11 +337,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,