Test mapMangledModule with new api

This commit is contained in:
Nuckyz 2024-06-21 03:53:39 -03:00
parent f6dbcb7709
commit e93562b95b
No known key found for this signature in database
GPG key ID: 440BF8296E1C4AD9
9 changed files with 49 additions and 23 deletions

View file

@ -65,7 +65,7 @@ export function getUserSettingDefinition<T = any>(group: string, name: string):
}
/**
* {@link getUserSettingDefinition}, lazy.
* Lazy version of {@link getUserSettingDefinition}
*
* Get the definition for a setting.
*

View file

@ -56,7 +56,7 @@ function ReplacementComponent({ module, match, replacement, setReplacementError
const [compileResult, setCompileResult] = React.useState<[boolean, string]>();
const [patchedCode, matchResult, diff] = React.useMemo(() => {
const src: string = fact.toString().replaceAll("\n", "");
const src = String(fact).replaceAll("\n", "");
try {
new RegExp(match);

View file

@ -111,14 +111,14 @@ export async function loadLazyChunks() {
Webpack.factoryListeners.add(factory => {
let isResolved = false;
searchAndLoadLazyChunks(factory.toString()).then(() => isResolved = true);
searchAndLoadLazyChunks(String(factory)).then(() => isResolved = true);
chunksSearchPromises.push(() => isResolved);
});
for (const factoryId in wreq.m) {
let isResolved = false;
searchAndLoadLazyChunks(wreq.m[factoryId].toString()).then(() => isResolved = true);
searchAndLoadLazyChunks(String(wreq.m[factoryId])).then(() => isResolved = true);
chunksSearchPromises.push(() => isResolved);
}

View file

@ -33,10 +33,8 @@ async function runReporter() {
await Promise.all(Webpack.webpackSearchHistory.map(async ([searchType, args]) => {
args = [...args];
let result: any;
try {
let result = null as any;
try {
switch (searchType) {
case "webpackDependantLazy":
case "webpackDependantLazyComponent": {
@ -45,13 +43,12 @@ async function runReporter() {
break;
}
case "extractAndLoadChunks": {
const [code, matcher] = args;
result = true;
const extractAndLoadChunks = args.shift();
/* result = await Webpack.extractAndLoadChunks(code, matcher);
result = await extractAndLoadChunks();
if (result === false) {
result = null;
} */
}
break;
}
@ -65,6 +62,14 @@ async function runReporter() {
if (findResult[SYM_PROXY_INNER_GET] != null) {
result = findResult[SYM_PROXY_INNER_VALUE];
if (result != null && searchType === "mapMangledModule") {
for (const innerMap in result) {
if (result[innerMap][SYM_PROXY_INNER_GET] != null) {
throw new Error("Webpack Find Fail");
}
}
}
}
if (findResult[SYM_LAZY_COMPONENT_INNER] != null) {
@ -77,7 +82,7 @@ async function runReporter() {
}
if (result == null) {
throw "a rock at ben shapiro";
throw new Error("Webpack Find Fail");
}
} catch (e) {
let logMessage = searchType;
@ -99,23 +104,44 @@ async function runReporter() {
parsedArgs === args &&
["waitFor", "find", "findComponent", "webpackDependantLazy", "webpackDependantLazyComponent"].includes(searchType)
) {
let filter = parsedArgs[0].toString();
let filter = String(parsedArgs[0]);
if (filter.length > 150) {
filter = filter.slice(0, 147) + "...";
}
logMessage += `(${filter})`;
} else if (searchType === "extractAndLoadChunks") {
const [code, matcher] = parsedArgs;
let regexStr: string;
if (parsedArgs[1] === Webpack.DefaultExtractAndLoadChunksRegex) {
if (matcher === Webpack.DefaultExtractAndLoadChunksRegex) {
regexStr = "DefaultExtractAndLoadChunksRegex";
} else {
regexStr = parsedArgs[1].toString();
regexStr = String(matcher);
}
logMessage += `([${parsedArgs[0].map((arg: any) => `"${arg}"`).join(", ")}], ${regexStr})`;
logMessage += `(${JSON.stringify(code)}, ${regexStr})`;
} else if (searchType === "mapMangledModule") {
const [code, mappers] = parsedArgs;
const parsedFailedMappers = Object.entries<any>(mappers)
.filter(([key]) => result == null || result[key][SYM_PROXY_INNER_GET] != null)
.map(([key, filter]) => {
let parsedFilter: string;
if (filter.$$vencordProps != null) {
const filterName = filter.$$vencordProps[0];
parsedFilter = `${filterName}(${filter.$$vencordProps.slice(1).map((arg: any) => JSON.stringify(arg)).join(", ")})`;
} else {
logMessage += `(${filterName.length ? `${filterName}(` : ""}${parsedArgs.map(arg => `"${arg}"`).join(", ")})${filterName.length ? ")" : ""}`;
parsedFilter = String(filter).slice(0, 147) + "...";
}
return [key, parsedFilter];
});
logMessage += `(${JSON.stringify(code)}, {\n${parsedFailedMappers.map(([key, parsedFilter]) => `\t${key}: ${parsedFilter}`).join(",\n")}\n})`;
} else {
logMessage += `(${filterName.length ? `${filterName}(` : ""}${parsedArgs.map(arg => JSON.stringify(arg)).join(", ")})${filterName.length ? ")" : ""}`;
}
ReporterLogger.log("Webpack Find Fail:", logMessage);

View file

@ -10,5 +10,5 @@ import { extractAndLoadChunksLazy, findByProps } from "@webpack";
export const cl = classNameFactory("vc-decor-");
export const DecorationModalStyles = findByProps("modalFooterShopButton");
export const requireAvatarDecorationModal = extractAndLoadChunksLazy([".COLLECTIBLES_SHOP_FULLSCREEN&&"]);
export const requireCreateStickerModal = extractAndLoadChunksLazy(["stickerInspected]:"]);
export const requireAvatarDecorationModal = extractAndLoadChunksLazy(".COLLECTIBLES_SHOP_FULLSCREEN&&");
export const requireCreateStickerModal = extractAndLoadChunksLazy("stickerInspected]:");

View file

@ -160,7 +160,7 @@ function initWs(isManual = false) {
return reply("Expected exactly one 'find' matches, found " + keys.length);
const mod = candidates[keys[0]];
let src = String(mod.original ?? mod).replaceAll("\n", "");
let src = String(mod).replaceAll("\n", "");
if (src.startsWith("function(")) {
src = "0," + src;

View file

@ -111,7 +111,7 @@ interface ProfileModalProps {
const ColorPicker = findComponentByCode<ColorPickerProps>(".Messages.USER_SETTINGS_PROFILE_COLOR_SELECT_COLOR", ".BACKGROUND_PRIMARY)");
const ProfileModal = findComponentByCode<ProfileModalProps>('"ProfileCustomizationPreview"');
const requireColorPicker = extractAndLoadChunksLazy(["USER_SETTINGS_PROFILE_COLOR_DEFAULT_BUTTON.format"], /createPromise:\(\)=>\i\.\i\("?(.+?)"?\).then\(\i\.bind\(\i,"?(.+?)"?\)\)/);
const requireColorPicker = extractAndLoadChunksLazy("USER_SETTINGS_PROFILE_COLOR_DEFAULT_BUTTON.format", /createPromise:\(\)=>\i\.\i\("?(.+?)"?\).then\(\i\.bind\(\i,"?(.+?)"?\)\)/);
export default definePlugin({
name: "FakeProfileThemes",

View file

@ -33,7 +33,7 @@ interface ColorPickerWithSwatchesProps {
const ColorPicker = findComponentByCode<ColorPickerProps>(".Messages.USER_SETTINGS_PROFILE_COLOR_SELECT_COLOR", ".BACKGROUND_PRIMARY)");
const ColorPickerWithSwatches = findExportedComponent<ColorPickerWithSwatchesProps>("ColorPicker", "CustomColorPicker");
export const requireSettingsMenu = extractAndLoadChunksLazy(['name:"UserSettings"'], /createPromise:.{0,20}Promise\.all\((\[\i\.\i\("?.+?"?\).+?\])\).then\(\i\.bind\(\i,"?(.+?)"?\)\).{0,50}"UserSettings"/);
export const requireSettingsMenu = extractAndLoadChunksLazy('name:"UserSettings"', /createPromise:.{0,20}Promise\.all\((\[\i\.\i\("?.+?"?\).+?\])\).then\(\i\.bind\(\i,"?(.+?)"?\)\).{0,50}"UserSettings"/);
const cl = classNameFactory("vc-pindms-modal-");

View file

@ -782,7 +782,7 @@ export function extractAndLoadChunksLazy(code: string | string[], matcher: RegEx
});
if (IS_REPORTER) {
webpackSearchHistory.push(["extractAndLoadChunks", [extractAndLoadChunks]]);
webpackSearchHistory.push(["extractAndLoadChunks", [extractAndLoadChunks, code, matcher]]);
}
return extractAndLoadChunks;