Skip to content

Commit

Permalink
fix: fix fetching adapters manifest from latest gatsby version
Browse files Browse the repository at this point in the history
  • Loading branch information
pieh committed Aug 24, 2023
1 parent a1c87bc commit 1f9e806
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions packages/gatsby/src/utils/get-latest-gatsby-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,29 @@ const _getFile = async <T>({
outputFileName: string
defaultReturn: T
}): Promise<T> => {
let fileToUse = path.join(ROOT, fileName)
try {
const { data } = await axios.get(`${UNPKG_ROOT}${fileName}`, {
timeout: 5000,
})

await fs.writeFile(outputFileName, JSON.stringify(data, null, 2), `utf8`)
await fs.writeFile(outputFileName, data, `utf8`)

return data
fileToUse = outputFileName
} catch (e) {
if (await fs.pathExists(outputFileName)) {
return fs.readJSON(outputFileName)
}
// no-op
}

if (fileName.endsWith(`.json`)) {
return fs.readJSON(path.join(ROOT, fileName)).catch(() => defaultReturn)
} else {
try {
const importedFile = await import(path.join(ROOT, fileName))
const adapters = preferDefault(importedFile)
return adapters
} catch (e) {
// no-op
return defaultReturn
}
if (fileToUse.endsWith(`.json`)) {
return fs.readJSON(fileToUse).catch(() => defaultReturn)
} else {
try {
const importedFile = await import(fileToUse)
const adapters = preferDefault(importedFile)
return adapters
} catch (e) {
// no-op
return defaultReturn
}
}
}
Expand Down

0 comments on commit 1f9e806

Please sign in to comment.