From 14fc807adb3a42672a4b8c95343c60c22f3dd70b Mon Sep 17 00:00:00 2001 From: Aaron Powell Date: Mon, 17 Aug 2026 15:23:18 +1000 Subject: [PATCH] fix(website): fail the build when the contributor manifest is unreadable Silently falling back to 0 is how the contributor badge regressed before, so a missing or malformed .all-contributorsrc now throws in production builds and warns in dev instead of shipping a wrong count. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 80686fef-efe3-4cdd-8cd6-bfa61a5d0af6 --- website/astro.config.mjs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/website/astro.config.mjs b/website/astro.config.mjs index 41a7b457..6638f923 100644 --- a/website/astro.config.mjs +++ b/website/astro.config.mjs @@ -15,13 +15,22 @@ import pagefindResources from "./src/integrations/pagefind-resources"; // browser, so the read would fail there and the badge would reset to 0 on // hydration even though the server-rendered HTML had the right number. function readContributorsTotal() { + const here = path.dirname(fileURLToPath(import.meta.url)); + const manifest = path.resolve(here, "..", ".all-contributorsrc"); try { - const here = path.dirname(fileURLToPath(import.meta.url)); - const rc = JSON.parse( - fs.readFileSync(path.resolve(here, "..", ".all-contributorsrc"), "utf8"), - ); - return Array.isArray(rc.contributors) ? rc.contributors.length : 0; - } catch { + const rc = JSON.parse(fs.readFileSync(manifest, "utf8")); + if (!Array.isArray(rc.contributors)) { + throw new Error("`contributors` is missing or is not an array"); + } + return rc.contributors.length; + } catch (error) { + const message = `Could not read the contributor count from ${manifest}: ${error.message}`; + // Falling back to 0 silently is how this badge regressed before, so make a + // broken manifest fail the production build rather than ship a wrong count. + if (process.env.NODE_ENV === "production") { + throw new Error(message); + } + console.warn(`[contributors] ${message}`); return 0; } }