From 113a2d334bca5bf6fa55aa47284e4dd6512785f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matou=C5=A1=20Ku=C4=8Dera?= Date: Fri, 3 May 2024 12:59:34 +0200 Subject: [PATCH 1/2] fix: ignore more untracked file errors --- docusaurus.config.ts | 17 +++++++++-------- src/util/authorUtils.ts | 26 ++++++++++++++------------ 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/docusaurus.config.ts b/docusaurus.config.ts index 4046259b8..ea589492c 100644 --- a/docusaurus.config.ts +++ b/docusaurus.config.ts @@ -6,8 +6,7 @@ import footer from "./config/footer.config"; import { env } from "process"; import { Config } from "@docusaurus/types"; import { Options } from "@docusaurus/plugin-content-docs"; -import { getFileCommitHash } from "@docusaurus/utils/src/gitUtils"; -import { AUTHOR_FALLBACK, AuthorData, commitCache, cacheAuthorData } from "./src/util/authorUtils"; +import { AUTHOR_FALLBACK, AuthorData, commitCache, cacheAuthorData, getFileCommitHashSafe } from "./src/util/authorUtils"; const preview = env.VERCEL_ENV === "preview"; cacheAuthorData(preview || process.env.NODE_ENV === "development"); @@ -89,12 +88,14 @@ const config: Config = { ...AUTHOR_FALLBACK, }; if (process.env.NODE_ENV !== "development") { - const { commit } = await getFileCommitHash(params.filePath); - const username = commitCache.get(commit); - author = { - commit, - username: username ?? AUTHOR_FALLBACK.username, - }; + const data = await getFileCommitHashSafe(params.filePath); + if (data) { + const username = commitCache.get(data.commit); + author = { + commit: data.commit, + username: username ?? AUTHOR_FALLBACK.username, + }; + } } return { diff --git a/src/util/authorUtils.ts b/src/util/authorUtils.ts index e2ccdefe3..3429e6322 100644 --- a/src/util/authorUtils.ts +++ b/src/util/authorUtils.ts @@ -47,6 +47,18 @@ async function cacheUsernameFromCommit(commit: string) { } } +export const getFileCommitHashSafe = async (file: string): Promise<{ commit: string } | null> => { + try { + return await getFileCommitHash(file); + } catch (e) { + if (e instanceof FileNotTrackedError) { + return null; + } + + throw e; // different error, rethrow + } +}; + export async function cacheAuthorData(isPreview: boolean) { // Only Render in Production and not cache in every invocation of importing docusaurus.config.ts if (isPreview || !new Error().stack.includes("async loadSite")) { @@ -59,18 +71,8 @@ export async function cacheAuthorData(isPreview: boolean) { } const pagesFiles = await Globby("docs/**/*.md*"); - const commits = await Promise.all( - pagesFiles.map((f) => { - return getFileCommitHash(f).catch((e) => { - if (e instanceof FileNotTrackedError) { - return null; - } - - throw e; // different error, rethrow - }); - }) - ); - + const commits = await Promise.all(pagesFiles.map(getFileCommitHashSafe)); const commitsSet = new Set(commits.filter(Boolean).map((value) => value.commit)); + await Promise.all(Array.from(commitsSet).map(cacheUsernameFromCommit)); } From 5bf0629217b59c1aca075c88ea91b7ba7c1e1330 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matou=C5=A1=20Ku=C4=8Dera?= Date: Fri, 3 May 2024 13:02:56 +0200 Subject: [PATCH 2/2] style: run Prettier --- docusaurus.config.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/docusaurus.config.ts b/docusaurus.config.ts index ea589492c..65acc3e19 100644 --- a/docusaurus.config.ts +++ b/docusaurus.config.ts @@ -6,7 +6,13 @@ import footer from "./config/footer.config"; import { env } from "process"; import { Config } from "@docusaurus/types"; import { Options } from "@docusaurus/plugin-content-docs"; -import { AUTHOR_FALLBACK, AuthorData, commitCache, cacheAuthorData, getFileCommitHashSafe } from "./src/util/authorUtils"; +import { + AUTHOR_FALLBACK, + AuthorData, + commitCache, + cacheAuthorData, + getFileCommitHashSafe, +} from "./src/util/authorUtils"; const preview = env.VERCEL_ENV === "preview"; cacheAuthorData(preview || process.env.NODE_ENV === "development");