From d341bd86ce05fabe44f3be5888ba2611b61914b4 Mon Sep 17 00:00:00 2001 From: Gar Date: Thu, 17 Jun 2021 07:06:05 -0700 Subject: [PATCH] make-fetch-happen@9.0.3 * fix: implement cache modes correctly --- .../make-fetch-happen/lib/cache/entry.js | 6 ++++++ .../make-fetch-happen/lib/cache/index.js | 17 ++++++++--------- node_modules/make-fetch-happen/package.json | 2 +- package-lock.json | 14 +++++++------- package.json | 2 +- 5 files changed, 23 insertions(+), 18 deletions(-) diff --git a/node_modules/make-fetch-happen/lib/cache/entry.js b/node_modules/make-fetch-happen/lib/cache/entry.js index 0df006fe34a3f..41f8a3d215ee1 100644 --- a/node_modules/make-fetch-happen/lib/cache/entry.js +++ b/node_modules/make-fetch-happen/lib/cache/entry.js @@ -145,6 +145,12 @@ class CacheEntry { return } + // a cache mode of 'reload' means to behave as though we have no cache + // on the way to the network. return undefined to allow cacheFetch to + // create a brand new request no matter what. + if (options.cache === 'reload') + return + // find the specific entry that satisfies the request let match for (const entry of matches) { diff --git a/node_modules/make-fetch-happen/lib/cache/index.js b/node_modules/make-fetch-happen/lib/cache/index.js index 00df31dd15023..cca93d9b4eb5d 100644 --- a/node_modules/make-fetch-happen/lib/cache/index.js +++ b/node_modules/make-fetch-happen/lib/cache/index.js @@ -7,7 +7,7 @@ const cacheFetch = async (request, options) => { // try to find a cached entry that satisfies this request const entry = await CacheEntry.find(request, options) if (!entry) { - // no cached result, if the cache mode is only-if-cached that's a failure + // no cached result, if the cache mode is 'only-if-cached' that's a failure if (options.cache === 'only-if-cached') throw new NotCachedError(request.url) @@ -17,22 +17,21 @@ const cacheFetch = async (request, options) => { return entry.store('miss') } - // we have a cached response that satisfies this request, however - // if the cache mode is reload the user explicitly wants us to revalidate - if (options.cache === 'reload') + // we have a cached response that satisfies this request, however if the cache + // mode is 'no-cache' then we send the revalidation request no matter what + if (options.cache === 'no-cache') return entry.revalidate(request, options) - // if the cache mode is either force-cache or only-if-cached we will only - // respond with a cached entry, even if it's stale. set the status to the - // appropriate value based on whether revalidation is needed and respond - // from the cache + // if the cached entry is not stale, or if the cache mode is 'force-cache' or + // 'only-if-cached' we can respond with the cached entry. set the status + // based on the result of needsRevalidation and respond const _needsRevalidation = entry.policy.needsRevalidation(request) if (options.cache === 'force-cache' || options.cache === 'only-if-cached' || !_needsRevalidation) return entry.respond(request.method, options, _needsRevalidation ? 'stale' : 'hit') - // cache entry might be stale, revalidate it and return a response + // if we got here, the cache entry is stale so revalidate it return entry.revalidate(request, options) } diff --git a/node_modules/make-fetch-happen/package.json b/node_modules/make-fetch-happen/package.json index af97a161c6088..44330998bb02f 100644 --- a/node_modules/make-fetch-happen/package.json +++ b/node_modules/make-fetch-happen/package.json @@ -1,6 +1,6 @@ { "name": "make-fetch-happen", - "version": "9.0.2", + "version": "9.0.3", "description": "Opinionated, caching, retrying fetch client", "main": "lib/index.js", "files": [ diff --git a/package-lock.json b/package-lock.json index e49153959c919..88b1797e90ab9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -116,7 +116,7 @@ "libnpmsearch": "^3.1.1", "libnpmteam": "^2.0.3", "libnpmversion": "^1.2.1", - "make-fetch-happen": "^9.0.1", + "make-fetch-happen": "^9.0.3", "minipass": "^3.1.3", "minipass-pipeline": "^1.2.4", "mkdirp": "^1.0.4", @@ -4953,9 +4953,9 @@ } }, "node_modules/make-fetch-happen": { - "version": "9.0.2", - "resolved": "https://registry.npmjs.org/make-fetch-happen/-/make-fetch-happen-9.0.2.tgz", - "integrity": "sha512-UkAWAuXPXSSlVviTjH2We20mtj1NnZW2Qq/oTY2dyMbRQ5CR3Xed3akCDMnM7j6axrMY80lhgM7loNE132PfAw==", + "version": "9.0.3", + "resolved": "https://registry.npmjs.org/make-fetch-happen/-/make-fetch-happen-9.0.3.tgz", + "integrity": "sha512-uZ/9Cf2vKqsSWZyXhZ9wHHyckBrkntgbnqV68Bfe8zZenlf7D6yuGMXvHZQ+jSnzPkjosuNP1HGasj1J4h8OlQ==", "inBundle": true, "dependencies": { "agentkeepalive": "^4.1.3", @@ -13989,9 +13989,9 @@ } }, "make-fetch-happen": { - "version": "9.0.2", - "resolved": "https://registry.npmjs.org/make-fetch-happen/-/make-fetch-happen-9.0.2.tgz", - "integrity": "sha512-UkAWAuXPXSSlVviTjH2We20mtj1NnZW2Qq/oTY2dyMbRQ5CR3Xed3akCDMnM7j6axrMY80lhgM7loNE132PfAw==", + "version": "9.0.3", + "resolved": "https://registry.npmjs.org/make-fetch-happen/-/make-fetch-happen-9.0.3.tgz", + "integrity": "sha512-uZ/9Cf2vKqsSWZyXhZ9wHHyckBrkntgbnqV68Bfe8zZenlf7D6yuGMXvHZQ+jSnzPkjosuNP1HGasj1J4h8OlQ==", "requires": { "agentkeepalive": "^4.1.3", "cacache": "^15.2.0", diff --git a/package.json b/package.json index 851c4a2c6924a..a8f7047924913 100644 --- a/package.json +++ b/package.json @@ -87,7 +87,7 @@ "libnpmsearch": "^3.1.1", "libnpmteam": "^2.0.3", "libnpmversion": "^1.2.1", - "make-fetch-happen": "^9.0.1", + "make-fetch-happen": "^9.0.3", "minipass": "^3.1.3", "minipass-pipeline": "^1.2.4", "mkdirp": "^1.0.4",