Skip to content

Commit 58dc15e

Browse files
authored
fix(gatsby-recipes): Cache readme and always return string (#26833)
1 parent 9db8b00 commit 58dc15e

File tree

1 file changed

+16
-5
lines changed
  • packages/gatsby-recipes/src/providers/gatsby

1 file changed

+16
-5
lines changed

packages/gatsby-recipes/src/providers/gatsby/plugin.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,27 @@ const getNameForPlugin = node => {
102102
const getDescriptionForPlugin = async name => {
103103
const pkg = await readPackageJSON({}, name)
104104

105-
return pkg ? pkg.description : null
105+
return pkg?.description || ``
106106
}
107107

108+
const readmeCache = new Map()
109+
108110
const getReadmeForPlugin = async name => {
111+
if (readmeCache.has(name)) {
112+
return readmeCache.get(name)
113+
}
114+
109115
try {
110-
return fetch(`https://unpkg.com/${name}/README.md`)
116+
const readme = await fetch(`https://unpkg.com/${name}/README.md`)
111117
.then(res => res.text())
112118
.catch(() => null)
119+
120+
if (readme) {
121+
readmeCache.set(name, readme)
122+
}
123+
return readme || ``
113124
} catch (err) {
114-
return null
125+
return ``
115126
}
116127
}
117128

@@ -244,8 +255,8 @@ const read = async ({ root }, id) => {
244255

245256
return {
246257
id,
247-
description: description || null,
248-
readme: readme,
258+
description,
259+
readme,
249260
...plugin,
250261
shadowedFiles,
251262
shadowableFiles,

0 commit comments

Comments
 (0)