From ee6f1a8e5ad22f568b1c4082dc9a70118698cd3b Mon Sep 17 00:00:00 2001 From: Cobblestone Date: Fri, 19 Jan 2024 16:12:27 -0500 Subject: [PATCH] fix top level await errors --- src/lib/globals/versions.ts | 65 ++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 30 deletions(-) diff --git a/src/lib/globals/versions.ts b/src/lib/globals/versions.ts index 46b199b4..6a037c0c 100644 --- a/src/lib/globals/versions.ts +++ b/src/lib/globals/versions.ts @@ -13,44 +13,49 @@ type MinecraftVersion = { sha1: string; }; -const response = await fetch( - "https://raw.githubusercontent.com/misode/mcmeta/summary/versions/data.min.json" -); -const minecraftVersionData: MinecraftVersion[] = await response.json(); - const dpvDict: { [dataPackVersion: string]: string } = {}; const dpvDictAll: { [dataPackVersion: string]: string } = {}; let lastStable: string = "newest"; -for ( - let index = minecraftVersionData[0].data_pack_version; - index > 0; - index-- -) { - const mcVs: MinecraftVersion[] = minecraftVersionData.filter( - (version: MinecraftVersion) => version.data_pack_version === index - ); - if (mcVs.length === 0) { - continue; - } - const stableMcVs: MinecraftVersion[] = mcVs.filter( - (version: MinecraftVersion) => version.stable + +// this only exists because top level await support is weird +async function genStuff() { + const response = await fetch( + "https://raw.githubusercontent.com/misode/mcmeta/summary/versions/data.min.json" ); - if (stableMcVs.length === 1) { - dpvDict[index] = stableMcVs[0].id; - dpvDictAll[index] = stableMcVs[0].id; - lastStable = stableMcVs[0].id; - } else if (stableMcVs.length > 1) { - dpvDict[index] = `${stableMcVs.at(-1)?.id} - ${stableMcVs[0].id}`; - dpvDictAll[index] = `${stableMcVs.at(-1)?.id} - ${stableMcVs[0].id}`; - lastStable = stableMcVs[0].id; - } else if (mcVs.length === 1) { - dpvDictAll[index] = mcVs[0].id + " (" + lastStable + ")"; - } else if (mcVs.length > 1) { - dpvDictAll[index] = `${mcVs.at(-1)?.id} - ${mcVs[0].id} (${lastStable})`; + const minecraftVersionData: MinecraftVersion[] = await response.json(); + for ( + let index = minecraftVersionData[0].data_pack_version; + index > 0; + index-- + ) { + const mcVs: MinecraftVersion[] = minecraftVersionData.filter( + (version: MinecraftVersion) => version.data_pack_version === index + ); + if (mcVs.length === 0) { + continue; + } + const stableMcVs: MinecraftVersion[] = mcVs.filter( + (version: MinecraftVersion) => version.stable + ); + if (stableMcVs.length === 1) { + dpvDict[index] = stableMcVs[0].id; + dpvDictAll[index] = stableMcVs[0].id; + lastStable = stableMcVs[0].id; + } else if (stableMcVs.length > 1) { + dpvDict[index] = `${stableMcVs.at(-1)?.id} - ${stableMcVs[0].id}`; + dpvDictAll[index] = `${stableMcVs.at(-1)?.id} - ${stableMcVs[0].id}`; + lastStable = stableMcVs[0].id; + } else if (mcVs.length === 1) { + dpvDictAll[index] = mcVs[0].id + " (" + lastStable + ")"; + } else if (mcVs.length > 1) { + dpvDictAll[index] = `${mcVs.at(-1)?.id} - ${mcVs[0].id} (${lastStable})`; + } } } +genStuff() + export const getDataPackVersion = (version: string): string => { for (const dpv in dpvDictAll) { if (dpvDict[dpv] === version || dpvDictAll[dpv] === version) {