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() { get() {
if (promises === null) { if (promises === null) {
promises = require('internal/dns/promises'); promises = require('internal/dns/promises');
promises.setServers = defaultResolverSetServers;
promises.setDefaultResultOrder = setDefaultResultOrder;
} }
return promises; return promises;
} }

View File

@ -1,5 +1,3 @@
'use strict'; 'use strict';
const dnsPromises = require('internal/dns/promises'); module.exports = require('internal/dns/promises');
dnsPromises.setServers = require('dns').setServers;
module.exports = dnsPromises;

View File

@ -17,6 +17,8 @@ const {
emitInvalidHostnameWarning, emitInvalidHostnameWarning,
getDefaultVerbatim, getDefaultVerbatim,
errorCodes: dnsErrorCodes, errorCodes: dnsErrorCodes,
setDefaultResultOrder,
setDefaultResolver,
} = require('internal/dns/utils'); } = require('internal/dns/utils');
const { const {
NODATA, NODATA,
@ -349,11 +351,20 @@ Resolver.prototype.resolve = function resolve(hostname, rrtype) {
return ReflectApply(resolver, this, [hostname]); return ReflectApply(resolver, this, [hostname]);
}; };
function defaultResolverSetServers(servers) {
const resolver = new Resolver();
resolver.setServers(servers);
setDefaultResolver(resolver);
bindDefaultResolver(module.exports, Resolver.prototype);
}
module.exports = { module.exports = {
lookup, lookup,
lookupService, lookupService,
Resolver, Resolver,
setDefaultResultOrder,
setServers: defaultResolverSetServers,
// ERROR CODES // ERROR CODES
NODATA, NODATA,