From ffdde860c9172c34445655e67b947e71516b9e5b Mon Sep 17 00:00:00 2001 From: Louis Delassus Date: Sat, 12 Oct 2024 00:49:11 +0200 Subject: [PATCH] Fix unity versions scrapping not getting all the versions --- .../logic/ingestUnityVersions/scrapeVersions.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/functions/src/logic/ingestUnityVersions/scrapeVersions.ts b/functions/src/logic/ingestUnityVersions/scrapeVersions.ts index 390cb1a..75247f0 100644 --- a/functions/src/logic/ingestUnityVersions/scrapeVersions.ts +++ b/functions/src/logic/ingestUnityVersions/scrapeVersions.ts @@ -9,12 +9,13 @@ export const scrapeVersions = async (): Promise => { const scripts = document.querySelectorAll('script'); + const allVersions = new Map(); + for (const script of scripts) { if (script.textContent) { const matches = [...script.textContent.matchAll(unity_version_regex)]; if (matches.length > 0) { - const uniqueVersions = new Set(); - return matches + const versions = matches .filter((match) => { // Filter out prerelease and unsupported versions const [_, major, minor, patch, changeSet] = match; @@ -23,8 +24,7 @@ export const scrapeVersions = async (): Promise => { .map((match) => { const [_, major, minor, patch, changeSet] = match; const version = `${major}.${minor}.${patch}`; - if (!uniqueVersions.has(version)) { - uniqueVersions.add(version); + if (!allVersions.has(version)) { return { version, changeSet, @@ -38,9 +38,17 @@ export const scrapeVersions = async (): Promise => { return null; }) .filter((version) => version !== null) as EditorVersionInfo[]; + + versions.forEach((it) => { + allVersions.set(it.version, it); + }); } } } + if (allVersions.size > 0) { + return Array.from(allVersions.values()); + } + throw new Error('No Unity versions found!'); };