fix reporter (#3699)

This commit is contained in:
V 2025-10-01 23:12:33 +02:00 committed by GitHub
parent fd461045b9
commit 7aa1d47193
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -11,6 +11,24 @@ import * as Webpack from "@webpack";
import { wreq } from "@webpack";
import { AnyModuleFactory } from "webpack";
function getWebpackChunkMap() {
const sym = Symbol();
let v: Record<PropertyKey, string> | null = null;
Object.defineProperty(Object.prototype, sym, {
get() {
v = this;
return "";
},
configurable: true
});
wreq.u(sym);
delete Object.prototype[sym];
return v;
}
export async function loadLazyChunks() {
const LazyChunkLoaderLogger = new Logger("LazyChunkLoader");
@ -153,17 +171,10 @@ export async function loadLazyChunks() {
}
// All chunks Discord has mapped to asset files, even if they are not used anymore
const allChunks = [] as PropertyKey[];
// Matches "id" or id:
for (const currentMatch of String(wreq.u).matchAll(/(?:"([\deE]+?)"(?![,}]))|(?:([\deE]+?):)/g)) {
const id = currentMatch[1] ?? currentMatch[2];
if (id == null) continue;
const numId = Number(id);
allChunks.push(Number.isNaN(numId) ? id : numId);
}
const chunkMap = getWebpackChunkMap();
if (!chunkMap) throw new Error("Failed to get chunk map");
const allChunks = Object.keys(chunkMap).map(id => Number.isNaN(Number(id)) ? id : Number(id));
if (allChunks.length === 0) throw new Error("Failed to get all chunks");
// Chunks which our regex could not catch to load