Skip to content

Commit

Permalink
Replace got w/ node-fetch
Browse files Browse the repository at this point in the history
Closes GH-109.
Closes GH-110.

Reviewed-by: Christian Murphy <christian.murphy.42@gmail.com>
Reviewed-by: Titus Wormer <tituswormer@gmail.com>
  • Loading branch information
jensmeindertsma committed Mar 9, 2022
1 parent 9bd282c commit 6276fcc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 12 additions & 2 deletions lib/integration/esbuild.js
Expand Up @@ -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'
Expand Down Expand Up @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -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",
Expand Down

0 comments on commit 6276fcc

Please sign in to comment.