From 6276fcc77d7e438a063def8034166806215bf69c Mon Sep 17 00:00:00 2001 From: Jens Meindertsma Date: Wed, 9 Mar 2022 12:10:41 +0100 Subject: [PATCH] Replace `got` w/ `node-fetch` Closes GH-109. Closes GH-110. Reviewed-by: Christian Murphy Reviewed-by: Titus Wormer --- lib/integration/esbuild.js | 14 ++++++++++++-- package.json | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/integration/esbuild.js b/lib/integration/esbuild.js index 3f7ed9f..2eabd6a 100644 --- a/lib/integration/esbuild.js +++ b/lib/integration/esbuild.js @@ -17,7 +17,7 @@ import assert from 'node:assert' import {promises as fs} from 'node:fs' import path from 'node:path' import process from 'node:process' -import got from 'got' +import fetch from 'node-fetch' import {VFile} from 'vfile' import {createFormatAwareProcessors} from '../util/create-format-aware-processors.js' import {extnamesToRegex} from '../util/extnames-to-regex.js' @@ -97,7 +97,17 @@ export function esbuild(options = {}) { async function onloadremote(data) { const href = data.path console.log('%s: downloading `%s`', remoteNamespace, href) - const contents = (await got(href, {cache})).body + + /** @type {string} */ + let contents + + const cachedContents = cache.get(href) + if (cachedContents) { + contents = cachedContents + } else { + contents = await (await fetch(href)).text() + cache.set(href, contents) + } return filter.test(href) ? onload({ diff --git a/package.json b/package.json index 695c219..6446bb9 100644 --- a/package.json +++ b/package.json @@ -51,11 +51,11 @@ "estree-util-build-jsx": "^2.0.0", "estree-util-is-identifier-name": "^2.0.0", "estree-walker": "^3.0.0", - "got": "^11.0.0", "hast-util-to-estree": "^2.0.0", "markdown-extensions": "^1.0.0", "mdast-util-mdx": "^2.0.0", "micromark-extension-mdxjs": "^1.0.0", + "node-fetch": "^3.2.0", "periscopic": "^3.0.0", "remark-parse": "^10.0.0", "remark-rehype": "^10.0.0",