@@ -726,7 +726,7 @@ async function toolInstalled(
726
726
*
727
727
* consult [ghcup metadata repo](https://github.com/haskell/ghcup-metadata/) for details.
728
728
*/
729
- export type ReleaseMetadata = Map < string , Map < string , Map < string , string [ ] > > > ;
729
+ export type ReleaseMetadata = Map < string , Map < string , Map < string , string [ ] > > > ;
730
730
731
731
/**
732
732
* Compute Map of supported HLS versions for this platform.
@@ -829,13 +829,29 @@ async function getReleaseMetadata(
829
829
830
830
const offlineCache = path . join ( storagePath , 'ghcupReleases.cache.json' ) ;
831
831
832
+ /**
833
+ * Convert a json value to ReleaseMetadata.
834
+ * Assumes the json is well-formed and a valid Release-Metadata.
835
+ * @param obj Release Metadata without any typing information but well-formed.
836
+ * @returns Typed ReleaseMetadata.
837
+ */
838
+ const objectToMetadata = ( obj : any ) : ReleaseMetadata => {
839
+ const hlsMetaEntries = Object . entries ( obj ) . map ( ( [ hlsVersion , archMap ] ) => {
840
+ const archMetaEntries = Object . entries ( archMap as any ) . map ( ( [ arch , supportedGhcVersionsPerOs ] ) => {
841
+ return [ arch , new Map ( Object . entries ( supportedGhcVersionsPerOs as any ) ) ] as [ string , Map < string , string [ ] > ] ;
842
+ } ) ;
843
+ return [ hlsVersion , new Map ( archMetaEntries ) ] as [ string , Map < string , Map < string , string [ ] > > ] ;
844
+ } ) ;
845
+ return new Map ( hlsMetaEntries ) ;
846
+ } ;
847
+
832
848
async function readCachedReleaseData ( ) : Promise < ReleaseMetadata | null > {
833
849
try {
834
850
logger . info ( `Reading cached release data at ${ offlineCache } ` ) ;
835
851
const cachedInfo = await promisify ( fs . readFile ) ( offlineCache , { encoding : 'utf-8' } ) ;
836
852
// export type ReleaseMetadata = Map<string, Map<string, Map<string, string[]>>>;
837
- const value : ReleaseMetadata = JSON . parse ( cachedInfo ) ;
838
- return value ;
853
+ const value : any = JSON . parse ( cachedInfo ) ;
854
+ return objectToMetadata ( value ) ;
839
855
} catch ( err : any ) {
840
856
// If file doesn't exist, return null, otherwise consider it a failure
841
857
if ( err . code === 'ENOENT' ) {
@@ -852,7 +868,7 @@ async function getReleaseMetadata(
852
868
853
869
// Cache the latest successfully fetched release information
854
870
await promisify ( fs . writeFile ) ( offlineCache , JSON . stringify ( releaseInfoParsed ) , { encoding : 'utf-8' } ) ;
855
- return releaseInfoParsed ;
871
+ return objectToMetadata ( releaseInfoParsed ) ;
856
872
} catch ( githubError : any ) {
857
873
// Attempt to read from the latest cached file
858
874
try {
0 commit comments