From feb4446d50a7b6a61e44a92b78e1e1af2d89a725 Mon Sep 17 00:00:00 2001 From: nlf Date: Thu, 24 Mar 2022 13:24:36 -0700 Subject: [PATCH] deps: make-fetch-happen@10.1.0 --- node_modules/make-fetch-happen/lib/agent.js | 5 ++ .../make-fetch-happen/lib/cache/index.js | 4 +- node_modules/make-fetch-happen/lib/dns.js | 49 +++++++++++++++++++ node_modules/make-fetch-happen/lib/options.js | 4 ++ node_modules/make-fetch-happen/package.json | 32 ++++++------ package-lock.json | 24 ++++----- package.json | 2 +- 7 files changed, 91 insertions(+), 29 deletions(-) create mode 100644 node_modules/make-fetch-happen/lib/dns.js diff --git a/node_modules/make-fetch-happen/lib/agent.js b/node_modules/make-fetch-happen/lib/agent.js index d28a31bfbda0c..f64644ff611a5 100644 --- a/node_modules/make-fetch-happen/lib/agent.js +++ b/node_modules/make-fetch-happen/lib/agent.js @@ -2,6 +2,7 @@ const LRU = require('lru-cache') const url = require('url') const isLambda = require('is-lambda') +const dns = require('./dns.js') const AGENT_CACHE = new LRU({ max: 50 }) const HttpAgent = require('agentkeepalive') @@ -77,11 +78,13 @@ function getAgent (uri, opts) { rejectUnauthorized: opts.rejectUnauthorized, timeout: agentTimeout, freeSocketTimeout: 15000, + lookup: dns.getLookup(opts.dns), }) : new HttpAgent({ maxSockets: agentMaxSockets, localAddress: opts.localAddress, timeout: agentTimeout, freeSocketTimeout: 15000, + lookup: dns.getLookup(opts.dns), }) AGENT_CACHE.set(key, agent) return agent @@ -171,6 +174,8 @@ const HttpsProxyAgent = require('https-proxy-agent') const SocksProxyAgent = require('socks-proxy-agent') module.exports.getProxy = getProxy function getProxy (proxyUrl, opts, isHttps) { + // our current proxy agents do not support an overridden dns lookup method, so will not + // benefit from the dns cache const popts = { host: proxyUrl.hostname, port: proxyUrl.port, diff --git a/node_modules/make-fetch-happen/lib/cache/index.js b/node_modules/make-fetch-happen/lib/cache/index.js index 17a6425592bcf..0de49d23fb933 100644 --- a/node_modules/make-fetch-happen/lib/cache/index.js +++ b/node_modules/make-fetch-happen/lib/cache/index.js @@ -14,8 +14,8 @@ const cacheFetch = async (request, options) => { // otherwise, we make a request, store it and return it const response = await remote(request, options) - const entry = new CacheEntry({ request, response, options }) - return entry.store('miss') + const newEntry = new CacheEntry({ request, response, options }) + return newEntry.store('miss') } // we have a cached response that satisfies this request, however if the cache diff --git a/node_modules/make-fetch-happen/lib/dns.js b/node_modules/make-fetch-happen/lib/dns.js new file mode 100644 index 0000000000000..f817c59f7329c --- /dev/null +++ b/node_modules/make-fetch-happen/lib/dns.js @@ -0,0 +1,49 @@ +const LRUCache = require('lru-cache') +const dns = require('dns') + +const defaultOptions = exports.defaultOptions = { + family: undefined, + hints: dns.ADDRCONFIG, + all: false, + verbatim: true, +} + +const lookupCache = exports.lookupCache = new LRUCache({ max: 50 }) + +// this is a factory so that each request can have its own opts (i.e. ttl) +// while still sharing the cache across all requests +exports.getLookup = (dnsOptions) => { + return (hostname, options, callback) => { + if (typeof options === 'function') { + callback = options + options = null + } else if (typeof options === 'number') { + options = { family: options } + } + + options = { ...defaultOptions, ...options } + + const key = JSON.stringify({ + hostname, + family: options.family, + hints: options.hints, + all: options.all, + verbatim: options.verbatim, + }) + + if (lookupCache.has(key)) { + const [address, family] = lookupCache.get(key) + process.nextTick(callback, null, address, family) + return + } + + dnsOptions.lookup(hostname, options, (err, address, family) => { + if (err) { + return callback(err) + } + + lookupCache.set(key, [address, family], { ttl: dnsOptions.ttl }) + return callback(null, address, family) + }) + } +} diff --git a/node_modules/make-fetch-happen/lib/options.js b/node_modules/make-fetch-happen/lib/options.js index a0c8664adf02a..daa9ecd9d5d5f 100644 --- a/node_modules/make-fetch-happen/lib/options.js +++ b/node_modules/make-fetch-happen/lib/options.js @@ -1,3 +1,5 @@ +const dns = require('dns') + const conditionalHeaders = [ 'if-modified-since', 'if-none-match', @@ -26,6 +28,8 @@ const configureOptions = (opts) => { options.retry = { retries: 0, ...options.retry } } + options.dns = { ttl: 5 * 60 * 1000, lookup: dns.lookup, ...options.dns } + options.cache = options.cache || 'default' if (options.cache === 'default') { const hasConditionalHeader = Object.keys(options.headers || {}).some((name) => { diff --git a/node_modules/make-fetch-happen/package.json b/node_modules/make-fetch-happen/package.json index e52131b8a8e01..e4afddba54090 100644 --- a/node_modules/make-fetch-happen/package.json +++ b/node_modules/make-fetch-happen/package.json @@ -1,11 +1,11 @@ { "name": "make-fetch-happen", - "version": "10.0.6", + "version": "10.1.0", "description": "Opinionated, caching, retrying fetch client", "main": "lib/index.js", "files": [ - "bin", - "lib" + "bin/", + "lib/" ], "scripts": { "preversion": "npm test", @@ -14,13 +14,16 @@ "test": "tap", "posttest": "npm run lint", "eslint": "eslint", - "lint": "eslint '**/*.js'", + "lint": "eslint \"**/*.js\"", "lintfix": "npm run lint -- --fix", - "postlint": "npm-template-check", + "postlint": "template-oss-check", "snap": "tap", - "template-copy": "npm-template-copy --force" + "template-oss-apply": "template-oss-apply --force" + }, + "repository": { + "type": "git", + "url": "https://github.com/npm/make-fetch-happen.git" }, - "repository": "https://github.com/npm/make-fetch-happen", "keywords": [ "http", "request", @@ -34,12 +37,12 @@ "license": "ISC", "dependencies": { "agentkeepalive": "^4.2.1", - "cacache": "^16.0.0", + "cacache": "^16.0.2", "http-cache-semantics": "^4.1.0", "http-proxy-agent": "^5.0.0", "https-proxy-agent": "^5.0.0", "is-lambda": "^1.0.1", - "lru-cache": "^7.5.1", + "lru-cache": "^7.7.1", "minipass": "^3.1.6", "minipass-collect": "^1.0.2", "minipass-fetch": "^2.0.3", @@ -51,17 +54,17 @@ "ssri": "^8.0.1" }, "devDependencies": { - "@npmcli/template-oss": "^2.9.2", - "eslint": "^8.11.0", + "@npmcli/eslint-config": "^3.0.1", + "@npmcli/template-oss": "3.1.2", "mkdirp": "^1.0.4", "nock": "^13.2.4", "rimraf": "^3.0.2", "safe-buffer": "^5.2.1", "standard-version": "^9.3.2", - "tap": "^15.1.6" + "tap": "^16.0.0" }, "engines": { - "node": "^12.13.0 || ^14.15.0 || >=16" + "node": "^12.13.0 || ^14.15.0 || >=16.0.0" }, "tap": { "color": 1, @@ -69,6 +72,7 @@ "check-coverage": true }, "templateOSS": { - "version": "2.9.2" + "//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.", + "version": "3.1.2" } } diff --git a/package-lock.json b/package-lock.json index a9c1156753b9a..e6674fdc51942 100644 --- a/package-lock.json +++ b/package-lock.json @@ -124,7 +124,7 @@ "libnpmsearch": "^5.0.2", "libnpmteam": "^4.0.2", "libnpmversion": "^3.0.1", - "make-fetch-happen": "^10.0.6", + "make-fetch-happen": "^10.1.0", "minipass": "^3.1.6", "minipass-pipeline": "^1.2.4", "mkdirp": "^1.0.4", @@ -4858,18 +4858,18 @@ "peer": true }, "node_modules/make-fetch-happen": { - "version": "10.0.6", - "resolved": "https://registry.npmjs.org/make-fetch-happen/-/make-fetch-happen-10.0.6.tgz", - "integrity": "sha512-4Gfh6lV3TLXmj7qz79hBFuvVqjYSMW6v2+sxtdX4LFQU0rK3V/txRjE0DoZb7X0IF3t9f8NO3CxPSWlvdckhVA==", + "version": "10.1.0", + "resolved": "https://registry.npmjs.org/make-fetch-happen/-/make-fetch-happen-10.1.0.tgz", + "integrity": "sha512-HeP4QlkadP/Op+hE+Une1070kcyN85FshQObku3/rmzRh4zDcKXA19d2L3AQR6UoaX3uZmhSOpTLH15b1vOFvQ==", "inBundle": true, "dependencies": { "agentkeepalive": "^4.2.1", - "cacache": "^16.0.0", + "cacache": "^16.0.2", "http-cache-semantics": "^4.1.0", "http-proxy-agent": "^5.0.0", "https-proxy-agent": "^5.0.0", "is-lambda": "^1.0.1", - "lru-cache": "^7.5.1", + "lru-cache": "^7.7.1", "minipass": "^3.1.6", "minipass-collect": "^1.0.2", "minipass-fetch": "^2.0.3", @@ -4881,7 +4881,7 @@ "ssri": "^8.0.1" }, "engines": { - "node": "^12.13.0 || ^14.15.0 || >=16" + "node": "^12.13.0 || ^14.15.0 || >=16.0.0" } }, "node_modules/markdown-escapes": { @@ -14471,17 +14471,17 @@ "peer": true }, "make-fetch-happen": { - "version": "10.0.6", - "resolved": "https://registry.npmjs.org/make-fetch-happen/-/make-fetch-happen-10.0.6.tgz", - "integrity": "sha512-4Gfh6lV3TLXmj7qz79hBFuvVqjYSMW6v2+sxtdX4LFQU0rK3V/txRjE0DoZb7X0IF3t9f8NO3CxPSWlvdckhVA==", + "version": "10.1.0", + "resolved": "https://registry.npmjs.org/make-fetch-happen/-/make-fetch-happen-10.1.0.tgz", + "integrity": "sha512-HeP4QlkadP/Op+hE+Une1070kcyN85FshQObku3/rmzRh4zDcKXA19d2L3AQR6UoaX3uZmhSOpTLH15b1vOFvQ==", "requires": { "agentkeepalive": "^4.2.1", - "cacache": "^16.0.0", + "cacache": "^16.0.2", "http-cache-semantics": "^4.1.0", "http-proxy-agent": "^5.0.0", "https-proxy-agent": "^5.0.0", "is-lambda": "^1.0.1", - "lru-cache": "^7.5.1", + "lru-cache": "^7.7.1", "minipass": "^3.1.6", "minipass-collect": "^1.0.2", "minipass-fetch": "^2.0.3", diff --git a/package.json b/package.json index 05cf493d78786..1f22bc7ca8daf 100644 --- a/package.json +++ b/package.json @@ -91,7 +91,7 @@ "libnpmsearch": "^5.0.2", "libnpmteam": "^4.0.2", "libnpmversion": "^3.0.1", - "make-fetch-happen": "^10.0.6", + "make-fetch-happen": "^10.1.0", "minipass": "^3.1.6", "minipass-pipeline": "^1.2.4", "mkdirp": "^1.0.4",