Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patched By List #639

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/renderer/managers/coremods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ export async function stopAll(): Promise<void> {

export function runPlaintextPatches(): void {
[
experimentsPlaintext,
notrackPlaintext,
noDevtoolsWarningPlaintext,
messagePopover,
notices,
contextMenu,
languagePlaintext,
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: settingsPlaintext, name: "replugged.coremod.settings" },
{ patch: badgesPlaintext, name: "replugged.coremod.badges" },
].forEach(({ patch, name }) => patchPlaintext(patch, name));
}
1 change: 1 addition & 0 deletions src/renderer/managers/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ export async function runPlaintextPatches(): Promise<void> {
}?t=${Date.now()}`
)
).default,
plugin.manifest.id,
);
}
}),
Expand Down
9 changes: 6 additions & 3 deletions src/renderer/modules/webpack/plaintext-patch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand All @@ -32,7 +34,7 @@ export function patchModuleSource(mod: WebpackModule, id: string): WebpackModule
if (result === source) {
return source;
}

patchedBy.push(patch.id);
return result;
}, originalSource);

Expand All @@ -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);
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/types/webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export interface PlaintextPatch {

export interface RawPlaintextPatch {
find?: string | RegExp;
id: string;
check?: (source: string) => boolean;
replacements: PlaintextReplacer[];
}
Expand Down