From 5dee2e8549de195f7bdb213ce7bb7f6dde840811 Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Thu, 21 Dec 2023 21:46:34 -0300 Subject: [PATCH] Future proof reporter to work in latest canary --- scripts/generateReport.ts | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/scripts/generateReport.ts b/scripts/generateReport.ts index b4033ecb3..0a17e8d7e 100644 --- a/scripts/generateReport.ts +++ b/scripts/generateReport.ts @@ -350,7 +350,7 @@ function runTime(token: string) { let invalidEntryPoint = false; for (const id of chunkIds) { - if (!wreq.u(id)) continue; + if (wreq.u(id) == null || wreq.u(id) === "undefined.js") continue; const isWasm = await fetch(wreq.p + wreq.u(id)) .then(r => r.text()) @@ -376,9 +376,22 @@ function runTime(token: string) { } catch (err) { } } - const allChunks = Function("return " + (wreq.u.toString().match(/(?<=\()\{.+?\}/s)?.[0] ?? "null"))() as Record | null; - if (!allChunks) throw new Error("Failed to get all chunks"); - const chunksLeft = Object.keys(allChunks).filter(id => { + // Matches "id" or id: + const chunkIdRegex = /(?:"(\d+?)")|(?:(\d+?):)/g; + const wreqU = wreq.u.toString(); + + const allChunks = [] as string[]; + let currentMatch: RegExpExecArray | null; + + while ((currentMatch = chunkIdRegex.exec(wreqU)) != null) { + const id = currentMatch[1] ?? currentMatch[2]; + if (id == null) continue; + + allChunks.push(id); + } + + if (allChunks.length === 0) throw new Error("Failed to get all chunks"); + const chunksLeft = allChunks.filter(id => { return !(validChunks.has(id) || invalidChunks.has(id)); });