From da22348b28f050541d56db221ef6bae481af820d Mon Sep 17 00:00:00 2001 From: d2du Date: Wed, 15 Jul 2026 00:30:33 +0530 Subject: [PATCH] fix website release history loading --- website/src/data/changes.ts | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/website/src/data/changes.ts b/website/src/data/changes.ts index 059ec90..b7528e1 100644 --- a/website/src/data/changes.ts +++ b/website/src/data/changes.ts @@ -1,9 +1,8 @@ import { execFileSync } from "node:child_process"; import { existsSync, readdirSync, readFileSync } from "node:fs"; -import { fileURLToPath } from "node:url"; import path from "node:path"; -const repositoryRoot = fileURLToPath(new URL("../../../", import.meta.url)); +const repositoryRoot = findRepositoryRoot(process.cwd()); const repositoryUrl = "https://github.com/Utility-Gods/gruntend"; export interface ChangeReference { @@ -35,6 +34,31 @@ export interface ReleasedChange { version: string; } +function findRepositoryRoot(startDirectory: string): string { + let directory = path.resolve(startDirectory); + + while (true) { + const changelogPath = path.join(directory, "CHANGELOG.md"); + const changesetConfigPath = path.join( + directory, + ".changeset", + "config.json", + ); + + if (existsSync(changelogPath) && existsSync(changesetConfigPath)) { + return directory; + } + + const parent = path.dirname(directory); + if (parent === directory) { + throw new Error( + `Unable to find the Gruntend repository root from ${startDirectory}.`, + ); + } + directory = parent; + } +} + function gitDate(args: string[]): string | undefined { try { const value = execFileSync("git", args, { @@ -151,12 +175,14 @@ function releaseDate( function readReleasedChanges(): ReleasedChange[] { const changelogPath = path.join(repositoryRoot, "CHANGELOG.md"); - if (!existsSync(changelogPath)) return []; - const source = readFileSync(changelogPath, "utf8"); const headingPattern = /^##\s+([^\s(]+)(?:\s+\(([^)]+)\))?\s*$/gm; const headings = [...source.matchAll(headingPattern)]; + if (headings.length === 0) { + throw new Error(`No releases found in ${changelogPath}.`); + } + return headings.map((heading, index) => { const version = heading[1]; const bodyStart = (heading.index ?? 0) + heading[0].length;