dns: make promise API fully constructed from lib/internal/dns/promises

PR-URL: https://github.com/nodejs/node/pull/43227
Refs: https://github.com/nodejs/node/discussions/43198
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
This commit is contained in:
Feng Yu 2022-06-21 02:58:45 +08:00 committed by GitHub
parent f9db8840ad
commit 3847617f55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 5 deletions

View File

@ -439,8 +439,6 @@ ObjectDefineProperties(module.exports, {
get() {
if (promises === null) {
promises = require('internal/dns/promises');
promises.setServers = defaultResolverSetServers;
promises.setDefaultResultOrder = setDefaultResultOrder;
}
return promises;
}

View File

@ -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');

View File

@ -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,