mirror of
https://github.com/github/awesome-copilot.git
synced 2026-08-25 10:21:40 +00:00
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
This commit is contained in:
@@ -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
|
// 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.
|
// hydration even though the server-rendered HTML had the right number.
|
||||||
function readContributorsTotal() {
|
function readContributorsTotal() {
|
||||||
|
const here = path.dirname(fileURLToPath(import.meta.url));
|
||||||
|
const manifest = path.resolve(here, "..", ".all-contributorsrc");
|
||||||
try {
|
try {
|
||||||
const here = path.dirname(fileURLToPath(import.meta.url));
|
const rc = JSON.parse(fs.readFileSync(manifest, "utf8"));
|
||||||
const rc = JSON.parse(
|
if (!Array.isArray(rc.contributors)) {
|
||||||
fs.readFileSync(path.resolve(here, "..", ".all-contributorsrc"), "utf8"),
|
throw new Error("`contributors` is missing or is not an array");
|
||||||
);
|
}
|
||||||
return Array.isArray(rc.contributors) ? rc.contributors.length : 0;
|
return rc.contributors.length;
|
||||||
} catch {
|
} 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;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user