remove dns cache

This commit is contained in:
silverwind 2022-10-26 15:05:15 +02:00
parent f9e8ea3035
commit 6e805267f7
Signed by untrusted user: silverwind
GPG Key ID: 2E62B41C93869443

@ -1,6 +1,5 @@
#!/usr/bin/env node
import ansiRegex from "ansi-regex";
import dns from "dns";
import fetchEnhanced from "fetch-enhanced";
import minimist from "minimist";
import nodeFetch from "node-fetch";
@ -37,32 +36,6 @@ const patchSemvers = new Set(["patch"]);
const minorSemvers = new Set(["patch", "minor"]);
const majorSemvers = new Set(["patch", "minor", "major"]);
// dns cache
const cache = Object.create(null);
const waiting = Object.create(null);
const originalLookup = dns.lookup;
dns.lookup = (hostname, opts, callback) => {
if (!callback) {
callback = opts;
opts = undefined;
}
if (hostname in cache) {
callback(...cache[hostname]);
} else {
if (!(hostname in waiting)) {
waiting[hostname] = [callback];
originalLookup(hostname, opts, (...args) => {
if (!(hostname in cache)) cache[hostname] = args;
for (const callback of waiting[hostname]) {
callback(...args);
}
});
} else {
waiting[hostname].push(callback);
}
}
};
// workaround for https://github.com/nodejs/node/issues/6379
for (const stream of [process.stdout, process.stderr]) {
stream?._handle?.setBlocking?.(true);