11---
2- import fs from " node:fs/promises" ;
32import { Badge } from " @astrojs/starlight/components" ;
43
54type Props = {
@@ -22,24 +21,34 @@ const {
2221 prefix = " v" ,
2322} = Astro .props as Props ;
2423
25- async function readVersion(relPath : string ): Promise <string > {
24+ const scripts = import .meta .glob (" ../../../*.bash" , {
25+ query: " ?raw" ,
26+ import: " default" ,
27+ eager: true ,
28+ }) as Record <string , string >;
29+
30+ function readVersion(filename : string ): string {
2631 try {
27- // Build a file URL relative to this component's location
28- const url = new URL (relPath , import .meta .url );
29- const content = await fs .readFile (url , " utf8" );
32+ const importPath = ` ../../../${filename } ` ;
33+ const content = scripts [importPath ];
34+ if (! content ) {
35+ console .error (` Script file ${filename } not found at ${importPath } ` );
36+ return " unknown" ;
37+ }
3038 // More robust match: allow spaces and single/double quotes
3139 const match = content .match (
3240 / (?:^ | \n )\s * script_version\s * =\s * (["'] )([^ "'] + )\1 / ,
3341 );
3442 return match ?.[2 ] ?? " unknown" ;
35- } catch {
43+ } catch (e ) {
44+ console .error (` Error parsing script file ${filename }: ` , e );
3645 return " unknown" ;
3746 }
3847}
3948
4049// Scripts live at the repository root; this component is at docs/src/components/
4150// So we traverse up three directories to reach the repo root.
42- const version = await readVersion (` ../../../${ file } ` );
51+ const version = readVersion (file );
4352const isKnown = version !== " unknown" ;
4453const normalizedVersion = typeof version === " string" ? version .trim () : " " ;
4554const displayVersion = isKnown
0 commit comments