From 280b9d562f680b5cfba659a0a6d454b2ca3688e0 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 | 17 ++++++++++++++++- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/lib/dns.js b/lib/dns.js index 284032202a24d4..064615014425b2 100644 --- a/lib/dns.js +++ b/lib/dns.js @@ -412,8 +412,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 58493134221913..21c423fe71eb8a 100644 --- a/lib/internal/dns/promises.js +++ b/lib/internal/dns/promises.js @@ -16,6 +16,8 @@ const { validateTries, emitInvalidHostnameWarning, getDefaultVerbatim, + setDefaultResultOrder, + setDefaultResolver, } = require('internal/dns/utils'); const { codes, dnsException } = require('internal/errors'); const { toASCII } = require('internal/idna'); @@ -322,6 +324,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 }; + resolver.setServers(servers); + setDefaultResolver(resolver); + bindDefaultResolver(module.exports, Resolver.prototype); +} + +module.exports = { + lookup, + lookupService, + Resolver, + setDefaultResultOrder, + setServers: defaultResolverSetServers, +}; bindDefaultResolver(module.exports, Resolver.prototype);