From 1f9e806bea4afb0dfc4a18d96e8a7fa7d823781a Mon Sep 17 00:00:00 2001 From: Michal Piechowiak Date: Thu, 24 Aug 2023 13:22:02 +0200 Subject: [PATCH] fix: fix fetching adapters manifest from latest gatsby version --- .../src/utils/get-latest-gatsby-files.ts | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/packages/gatsby/src/utils/get-latest-gatsby-files.ts b/packages/gatsby/src/utils/get-latest-gatsby-files.ts index 13d4b006b1765..d93eda130635c 100644 --- a/packages/gatsby/src/utils/get-latest-gatsby-files.ts +++ b/packages/gatsby/src/utils/get-latest-gatsby-files.ts @@ -32,30 +32,29 @@ const _getFile = async ({ outputFileName: string defaultReturn: T }): Promise => { + 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 } } }