From 771cbd54f5e266c49deb70f3a03f0143eb7f10c0 Mon Sep 17 00:00:00 2001 From: Tharki-God Date: Thu, 18 Jul 2024 00:31:49 +0530 Subject: [PATCH] patchedBy --- src/renderer/managers/coremods.ts | 22 +++++++++---------- src/renderer/managers/plugins.ts | 1 + .../modules/webpack/plaintext-patch.ts | 9 +++++--- src/types/webpack.ts | 1 + 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/renderer/managers/coremods.ts b/src/renderer/managers/coremods.ts index e975c24ab..8463ecb8e 100644 --- a/src/renderer/managers/coremods.ts +++ b/src/renderer/managers/coremods.ts @@ -79,15 +79,15 @@ export async function stopAll(): Promise { export function runPlaintextPatches(): void { [ - experimentsPlaintext, - notrackPlaintext, - noDevtoolsWarningPlaintext, - messagePopover, - notices, - contextMenu, - languagePlaintext, - commandsPlaintext, - settingsPlaintext, - badgesPlaintext, - ].forEach(patchPlaintext); + { patch: experimentsPlaintext, name: "replugged.coremod.experiments" }, + { patch: notrackPlaintext, name: "replugged.coremod.noTrack" }, + { patch: noDevtoolsWarningPlaintext, name: "replugged.coremod.noDevtoolsWarning" }, + { patch: messagePopover, name: "replugged.coremod.messagePopover" }, + { patch: notices, name: "replugged.coremod.notices" }, + { patch: contextMenu, name: "replugged.coremod.contextMenu" }, + { patch: languagePlaintext, name: "replugged.coremod.language" }, + { patch: commandsPlaintext, name: "replugged.coremod.commands" }, + { patch: settingsPlaintext, name: "replugged.coremod.settings" }, + { patch: badgesPlaintext, name: "replugged.coremod.badges" }, + ].forEach(({ patch, name }) => patchPlaintext(patch, name)); } diff --git a/src/renderer/managers/plugins.ts b/src/renderer/managers/plugins.ts index 0797d7cb1..4a7ac6b5f 100644 --- a/src/renderer/managers/plugins.ts +++ b/src/renderer/managers/plugins.ts @@ -176,6 +176,7 @@ export async function runPlaintextPatches(): Promise { }?t=${Date.now()}` ) ).default, + plugin.manifest.id, ); } }), diff --git a/src/renderer/modules/webpack/plaintext-patch.ts b/src/renderer/modules/webpack/plaintext-patch.ts index e5bdb361f..6d241c554 100644 --- a/src/renderer/modules/webpack/plaintext-patch.ts +++ b/src/renderer/modules/webpack/plaintext-patch.ts @@ -15,6 +15,8 @@ export const plaintextPatches: RawPlaintextPatch[] = []; export function patchModuleSource(mod: WebpackModule, id: string): WebpackModule { const originalSource = mod.toString(); + const patchedBy: string[] = []; + const patchedSource = plaintextPatches.reduce((source, patch) => { if ( patch.find && @@ -32,7 +34,7 @@ export function patchModuleSource(mod: WebpackModule, id: string): WebpackModule if (result === source) { return source; } - + patchedBy.push(patch.id); return result; }, originalSource); @@ -44,7 +46,7 @@ export function patchModuleSource(mod: WebpackModule, id: string): WebpackModule return (0, eval)( `${ patchedSource.startsWith("function(") ? `0,${patchedSource}` : patchedSource - }\n//# sourceURL=PatchedWebpack-${id}`, + }\n//Patched by: ${patchedBy.filter(Boolean).join(", ")}\n//# sourceURL=PatchedWebpack-${id}`, ); } catch (err) { logger.error(`PatchedWebpack-${id}`, err); @@ -59,10 +61,11 @@ export function patchModuleSource(mod: WebpackModule, id: string): WebpackModule * @internal * @hidden */ -export function patchPlaintext(patches: PlaintextPatch[]): void { +export function patchPlaintext(patches: PlaintextPatch[], id: string): void { plaintextPatches.push( ...patches.map((patch) => ({ ...patch, + id, replacements: patch.replacements.map((replacement) => typeof replacement === "function" ? replacement diff --git a/src/types/webpack.ts b/src/types/webpack.ts index ee50e8d0e..5e069f0c1 100644 --- a/src/types/webpack.ts +++ b/src/types/webpack.ts @@ -61,6 +61,7 @@ export interface PlaintextPatch { export interface RawPlaintextPatch { find?: string | RegExp; + id: string; check?: (source: string) => boolean; replacements: PlaintextReplacer[]; }