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

refactor(Webpack): Centralize and refactor Webpack patching #2485

Open
wants to merge 178 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
178 commits
Select commit Hold shift + click to select a range
2a77941
Proxy modules object for patching
Nuckyz May 20, 2024
ab24ce0
Merge branch 'dev' into modules-proxy-patches
Nuckyz May 20, 2024
b938bdf
Clarify about sentry webpack
Nuckyz May 20, 2024
2a2124c
Merge branch 'dev' into modules-proxy-patches
Nuckyz May 22, 2024
cf9bbfc
stop annoying me
Nuckyz May 22, 2024
c4645f7
Make patchedBy a string set
Nuckyz May 22, 2024
4b27346
Add WebpackRequire typings
Nuckyz May 22, 2024
d5bcbf5
fix
Nuckyz May 22, 2024
f6a7cdc
more fix
Nuckyz May 22, 2024
bc367b1
and also a fix
Nuckyz May 22, 2024
40a1f48
boops
Nuckyz May 23, 2024
deb0f7b
Merge remote-tracking branch 'upstream/dev' into modules-proxy-patches
Nuckyz May 23, 2024
5ca4e58
Clean up WebpackRequire typings
Nuckyz May 23, 2024
688449e
forgot this!
Nuckyz May 23, 2024
66e1db1
more
Nuckyz May 23, 2024
01a4ac9
sometimes I'm stupid
Nuckyz May 23, 2024
3ab68f9
Option for eager patching
Nuckyz May 23, 2024
bb3f629
Merge branch 'dev' into modules-proxy-patches
Nuckyz May 23, 2024
ac61a03
clean up
Nuckyz May 23, 2024
cfb493c
make reporter use eagerPatches
Nuckyz May 23, 2024
7371abb
lmao
Nuckyz May 23, 2024
1e96638
oops!
Nuckyz May 23, 2024
7b7b873
HORROR
Nuckyz May 23, 2024
bdd4b0f
Make eagerPatches an internal setting
Nuckyz May 23, 2024
bd95cc4
Exit script if a chunk failed to load
Nuckyz May 23, 2024
f5be78d
Patching toString -> String
Nuckyz May 23, 2024
8e9434c
Make reporter faster
Nuckyz May 24, 2024
9740d28
discord why tf would u roll back to 10 days old build???
Vendicated May 23, 2024
a120b35
Bump to v1.8.6
Vendicated May 23, 2024
c5541d2
Optimize slowest patches
Nuckyz May 24, 2024
16d05c8
Merge branch 'dev' into modules-proxy-patches
Nuckyz May 24, 2024
5e762dd
Add names to Modules objects
Nuckyz May 24, 2024
d8c6559
I forgot this
Nuckyz May 24, 2024
b38ab06
Preserve original modules prototype
Nuckyz May 24, 2024
9bbec66
Take a different approach which requires less cursed code
Nuckyz May 24, 2024
f727d10
I can never not forget something
Nuckyz May 24, 2024
f64b228
better log
Nuckyz May 24, 2024
488f133
Handle if for some reason modules are set again
Nuckyz May 24, 2024
86f69e8
I'm stupid
Nuckyz May 24, 2024
d6b5bc5
how many times
Nuckyz May 24, 2024
bacf021
aaaaa
Nuckyz May 24, 2024
3296ee1
Remove onChunksLoaded patch
Nuckyz May 24, 2024
3793acd
forgot the comment
Nuckyz May 24, 2024
5fbabb0
sob
Nuckyz May 24, 2024
8dde496
one more name cuz why not
Nuckyz May 24, 2024
2f16cdf
Make toStringTag non enumerable
Nuckyz May 24, 2024
daa1a35
Factories are called with a `this`
Nuckyz May 24, 2024
1e55ae5
this is more clean
Nuckyz May 24, 2024
9af63b3
more future proof
Nuckyz May 26, 2024
1a8a901
Merge branch 'dev' into modules-proxy-patches
Nuckyz May 26, 2024
affd527
Make factory wrapper a little more future proof
Nuckyz May 26, 2024
265cf12
I love
Nuckyz May 26, 2024
a8fa685
Add back running modules without patches
Nuckyz May 26, 2024
1ed9561
fix logic
Nuckyz May 26, 2024
3e3201a
improve wreq docs
Nuckyz May 26, 2024
440cb1f
Properly document wreq.a
Nuckyz May 26, 2024
18142ec
fix doc
Nuckyz May 26, 2024
c2047e5
fix typos
Nuckyz May 26, 2024
4d27643
type more
Nuckyz May 26, 2024
dae3841
ughh
Nuckyz May 26, 2024
32a2c90
fix typing of the global
Nuckyz May 26, 2024
c1e78b4
hasOwn != in
Nuckyz May 26, 2024
8fd22f6
e
Nuckyz May 26, 2024
9ada9bc
e part 2
Nuckyz May 26, 2024
8c5f2c8
Document patchWebpack better
Nuckyz May 26, 2024
1f99162
update patchWebpack license
Nuckyz May 26, 2024
f345484
Merge branch 'dev' into modules-proxy-patches
Nuckyz May 26, 2024
6d59a94
Merge branch 'dev' into modules-proxy-patches
Nuckyz May 27, 2024
513eea8
Prepare for in case modules object is accessed directly in the future
Nuckyz May 27, 2024
a1542bc
okay codium agent
Nuckyz May 28, 2024
e96458f
fixes for if we use prototype proxy in the future
Nuckyz May 28, 2024
539b70c
lmao oops
Nuckyz May 28, 2024
3e29528
Merge branch 'dev' into modules-proxy-patches
Nuckyz May 28, 2024
513d9f4
I knew I was forgetting something
Nuckyz May 28, 2024
c9c09b9
fix typo
Nuckyz May 28, 2024
acbc932
give name to PatchedFactory
Nuckyz May 28, 2024
9c2545a
undo explosion
Nuckyz May 28, 2024
1eeadbc
export all webpack instances
Nuckyz May 28, 2024
6b648f3
oops!
Nuckyz May 28, 2024
6426200
boop
Nuckyz May 28, 2024
d78f1c8
where did this come from?
Nuckyz May 28, 2024
84b9e3f
ConsoleShortcuts: Fix autocomplete on lazies, add more utils (#2519)
Vendicated May 28, 2024
a407370
explain UNCONFIGURABLE_PROPERTIES better
Nuckyz May 28, 2024
7350394
Add WebpackInstances shortcut
Nuckyz May 28, 2024
ea86df7
Merge branch 'dev' into modules-proxy-patches
Nuckyz May 28, 2024
4db6c4b
Merge branch 'dev' into modules-proxy-patches
Nuckyz May 29, 2024
4a87223
Fix reporter breaking because of ConsoleShortcuts
Nuckyz May 29, 2024
7509f20
Merge branch 'dev' into modules-proxy-patches
Nuckyz May 29, 2024
c8602ef
Fix reporter breaking because of ConsoleShortcuts
Nuckyz May 29, 2024
b745819
Merge branch 'dev' into modules-proxy-patches
Nuckyz May 29, 2024
892de53
Fix extractAndLoadChunks issue with 2 match groups; Improve testing o…
Nuckyz May 30, 2024
36f9eda
Merge branch 'dev' into modules-proxy-patches
Nuckyz May 30, 2024
9a9c1b0
Reporter: Properly implement reporter build of Vencord; Test more plu…
Nuckyz May 30, 2024
e225758
Merge branch 'dev' into modules-proxy-patches
Nuckyz May 30, 2024
3c62e39
edit another license header
Nuckyz May 30, 2024
3a25da5
Fix wrong external files and clean up build script; Remove non used s…
Nuckyz May 30, 2024
79849fd
Merge branch 'dev' into modules-proxy-patches
Nuckyz May 30, 2024
111a4f2
Merge branch 'dev' into modules-proxy-patches
Nuckyz May 30, 2024
022a049
Merge branch 'dev' into modules-proxy-patches
Nuckyz May 31, 2024
47eec04
Not needed anymore and breaks interpolated strings with newlines
Nuckyz May 31, 2024
545d69a
Use indexOf instead of includes; reset global find regex state
Nuckyz May 31, 2024
f4cc95d
Use indexOf in more places
Nuckyz May 31, 2024
db63fff
I should still be defining this
Nuckyz May 31, 2024
e21a6be
sfdsfdsfdsf
Nuckyz May 31, 2024
4187932
\n
Nuckyz May 31, 2024
fbb7ee5
Revert indexOf change
Nuckyz May 31, 2024
cbd9a93
don't depend in the value of bundlePath
Nuckyz May 31, 2024
2ab7d32
Merge branch 'dev' into modules-proxy-patches
Nuckyz Jun 1, 2024
01fdeb7
cya webpackChunkdiscord_app part 2
Nuckyz May 30, 2024
0aff3c2
Fix reporter
Nuckyz Jun 1, 2024
dd4d808
fix reporter part 2
Nuckyz Jun 1, 2024
db5397f
sdfdsf
Nuckyz Jun 1, 2024
50415a9
Merge branch 'dev' into modules-proxy-patches
Nuckyz Jun 1, 2024
4d8c566
Future proof against array modules
Nuckyz Jun 1, 2024
8580332
cleanup
Nuckyz Jun 1, 2024
33d5753
fix grammar issues
Nuckyz Jun 1, 2024
78fd37a
fix(css): brand-experiment is now brand-500
Vendicated Jun 1, 2024
c4c92ed
Add shortcut for lazy loading chunks
Nuckyz Jun 1, 2024
b79a0da
Merge branch 'dev' into modules-proxy-patches
Nuckyz Jun 1, 2024
c50208b
Add shortcut for lazy loading chunks
Nuckyz Jun 1, 2024
281ab91
Merge branch 'dev' into modules-proxy-patches
Nuckyz Jun 1, 2024
d8524b0
Add shortcut for lazy loading chunks
Nuckyz Jun 1, 2024
ac6a213
Merge branch 'dev' into modules-proxy-patches
Nuckyz Jun 1, 2024
61e1ead
Fix not restoring some original factories
Nuckyz Jun 1, 2024
4e14232
Fix patching pre-populated factories
Nuckyz Jun 1, 2024
6e6ee4d
NoPendingCount: Fix for message requests
Nuckyz Jun 2, 2024
066ce07
Merge branch 'dev' into modules-proxy-patches
Nuckyz Jun 2, 2024
53dd86f
Improve typings and other stuff
Nuckyz Jun 2, 2024
c8097f0
Merge branch 'dev' into modules-proxy-patches
Nuckyz Jun 6, 2024
625b248
Merge branch 'dev' into modules-proxy-patches
Nuckyz Jun 6, 2024
94ea4f8
Merge branch 'dev' into modules-proxy-patches
Nuckyz Jun 6, 2024
95c4cc0
Merge branch 'dev' into modules-proxy-patches
Nuckyz Jun 8, 2024
7f3cad2
Merge branch 'dev' into modules-proxy-patches
Nuckyz Jun 10, 2024
ed35c49
Merge branch 'dev' into modules-proxy-patches
Nuckyz Jun 12, 2024
c3bbc92
Decouple factoryListeners from patchFactory
Nuckyz Jun 12, 2024
6826fe0
guh
Nuckyz Jun 12, 2024
853585c
move down
Nuckyz Jun 12, 2024
6d587e6
More re-ordering
Nuckyz Jun 12, 2024
b2ae333
Merge branch 'dev' into modules-proxy-patches
Nuckyz Jun 12, 2024
92653ea
Merge branch 'dev' into modules-proxy-patches
Nuckyz Jun 12, 2024
8d31f3c
Use $$vencordOriginal as fallback
Nuckyz Jun 13, 2024
d473d52
update comment
Nuckyz Jun 13, 2024
a815122
Merge branch 'dev' into modules-proxy-patches
Nuckyz Jun 14, 2024
83b09a8
Merge branch 'dev' into modules-proxy-patches
Nuckyz Jun 14, 2024
afe6d9f
Separate wrapFactory and patchFactory
Nuckyz Jun 16, 2024
f208472
\n
Nuckyz Jun 16, 2024
9595f75
Merge branch 'dev' into modules-proxy-patches
Nuckyz Jun 18, 2024
24a0f62
Merge branch 'dev' into modules-proxy-patches
Nuckyz Jun 21, 2024
066001c
Add wreq.j
Nuckyz Jun 21, 2024
343e280
boop
Nuckyz Jun 21, 2024
3cf702a
fixes
Nuckyz Jun 21, 2024
a7b02f2
Merge branch 'dev' into modules-proxy-patches
Nuckyz Jun 21, 2024
2429231
Merge branch 'dev' into modules-proxy-patches
Nuckyz Jun 21, 2024
c400db4
Merge branch 'dev' into modules-proxy-patches
Nuckyz Jun 22, 2024
c4e7233
check for bundlePath value again
Nuckyz Jun 22, 2024
0e50994
Merge branch 'dev' into modules-proxy-patches
Nuckyz Jun 23, 2024
e592a50
Fix broken patches
Nuckyz Jun 27, 2024
edf4e75
Merge branch 'dev' into modules-proxy-patches
Nuckyz Jun 27, 2024
3b6bef1
Merge branch 'dev' into modules-proxy-patches
Nuckyz Jun 27, 2024
1e4ad4d
Fix for latest webpack change
Nuckyz Jun 28, 2024
d95367b
Merge branch 'dev' into modules-proxy-patches
Nuckyz Jun 28, 2024
c2d708a
Merge branch 'dev' into modules-proxy-patches
Nuckyz Jun 28, 2024
748a456
Delete patching properties after used
Nuckyz Jun 28, 2024
b833510
Merge branch 'dev' into modules-proxy-patches
Nuckyz Jun 28, 2024
9e998db
typings
Nuckyz Jun 28, 2024
5a85d6e
Harder conditions for Sentry patching
Nuckyz Jun 29, 2024
4caf86b
Merge branch 'dev' into modules-proxy-patches
Nuckyz Jun 29, 2024
28a7fbb
Merge branch 'dev' into modules-proxy-patches
Nuckyz Jun 29, 2024
332f3e5
Dont depend on modules being an object again
Nuckyz Jun 29, 2024
c1b4eb5
Merge branch 'dev' into modules-proxy-patches
Nuckyz Jun 29, 2024
1297408
Merge branch 'dev' into modules-proxy-patches
Nuckyz Jul 2, 2024
b333deb
improve settings ui (again)
Vendicated Jul 1, 2024
771d51b
Merge branch 'dev' into modules-proxy-patches
Nuckyz Jul 2, 2024
f6147c6
Merge branch 'dev' into modules-proxy-patches
Nuckyz Jul 3, 2024
208882e
Merge branch 'dev' into modules-proxy-patches
Nuckyz Jul 3, 2024
24795ba
Merge branch 'dev' into modules-proxy-patches
Nuckyz Jul 5, 2024
920fb20
Merge branch 'dev' into modules-proxy-patches
Nuckyz Jul 7, 2024
c835657
crazy
Nuckyz Jul 7, 2024
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
2 changes: 1 addition & 1 deletion src/Vencord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ export * as Util from "./utils";
export * as QuickCss from "./utils/quickCss";
export * as Updater from "./utils/updater";
export * as Webpack from "./webpack";
export * as WebpackPatcher from "./webpack/patchWebpack";
export { PlainSettings, Settings };

import "./utils/quickCss";
import "./webpack/patchWebpack";

import { openUpdaterModal } from "@components/VencordSettings/UpdaterTab";
import { StartAt } from "@utils/types";
Expand Down
4 changes: 3 additions & 1 deletion src/api/Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ export interface Settings {
autoUpdate: boolean;
autoUpdateNotification: boolean,
useQuickCss: boolean;
enableReactDevtools: boolean;
themeLinks: string[];
eagerPatches: boolean;
enabledThemes: string[];
enableReactDevtools: boolean;
frameless: boolean;
transparent: boolean;
winCtrlQ: boolean;
Expand Down Expand Up @@ -81,6 +82,7 @@ const DefaultSettings: Settings = {
autoUpdateNotification: true,
useQuickCss: true,
themeLinks: [],
eagerPatches: IS_REPORTER,
enabledThemes: [],
enableReactDevtools: false,
frameless: false,
Expand Down
2 changes: 1 addition & 1 deletion src/components/VencordSettings/PatchHelperTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = String(fact).replaceAll("\n", "");

try {
new RegExp(match);
Expand Down
28 changes: 15 additions & 13 deletions src/debug/loadLazyChunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Logger } from "@utils/Logger";
import { canonicalizeMatch } from "@utils/patches";
import * as Webpack from "@webpack";
import { wreq } from "@webpack";
import { AnyModuleFactory, ModuleFactory } from "webpack";

const LazyChunkLoaderLogger = new Logger("LazyChunkLoader");

Expand Down Expand Up @@ -69,7 +70,7 @@ export async function loadLazyChunks() {
await Promise.all(
Array.from(validChunkGroups)
.map(([chunkIds]) =>
Promise.all(chunkIds.map(id => wreq.e(id as any).catch(() => { })))
Promise.all(chunkIds.map(id => wreq.e(id)))
)
);

Expand All @@ -81,7 +82,7 @@ export async function loadLazyChunks() {
continue;
}

if (wreq.m[entryPoint]) wreq(entryPoint as any);
if (wreq.m[entryPoint]) wreq(entryPoint);
} catch (err) {
console.error(err);
}
Expand Down Expand Up @@ -109,32 +110,33 @@ export async function loadLazyChunks() {
}, 0);
}

Webpack.factoryListeners.add(factory => {
function factoryListener(factory: AnyModuleFactory | ModuleFactory) {
let isResolved = false;
searchAndLoadLazyChunks(factory.toString()).then(() => isResolved = true);
searchAndLoadLazyChunks(String(factory))
.then(() => isResolved = true)
.catch(() => isResolved = true);

chunksSearchPromises.push(() => isResolved);
});
}

Webpack.factoryListeners.add(factoryListener);
for (const factoryId in wreq.m) {
let isResolved = false;
searchAndLoadLazyChunks(wreq.m[factoryId].toString()).then(() => isResolved = true);

chunksSearchPromises.push(() => isResolved);
factoryListener(wreq.m[factoryId]);
}

await chunksSearchingDone;
Webpack.factoryListeners.delete(factoryListener);

// Require deferred entry points
for (const deferredRequire of deferredRequires) {
wreq!(deferredRequire as any);
wreq(deferredRequire);
}

// All chunks Discord has mapped to asset files, even if they are not used anymore
const allChunks = [] as string[];

// Matches "id" or id:
for (const currentMatch of wreq!.u.toString().matchAll(/(?:"(\d+?)")|(?:(\d+?):)/g)) {
for (const currentMatch of String(wreq.u).matchAll(/(?:"(\d+?)")|(?:(\d+?):)/g)) {
const id = currentMatch[1] ?? currentMatch[2];
if (id == null) continue;

Expand All @@ -155,10 +157,10 @@ export async function loadLazyChunks() {

// Loads and requires a chunk
if (!isWorkerAsset) {
await wreq.e(id as any);
await wreq.e(id);
// Technically, the id of the chunk does not match the entry point
// But, still try it because we have no way to get the actual entry point
if (wreq.m[id]) wreq(id as any);
if (wreq.m[id]) wreq(id);
}
}));

Expand Down
30 changes: 24 additions & 6 deletions src/debug/runReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { Logger } from "@utils/Logger";
import * as Webpack from "@webpack";
import { patches } from "plugins";
import { addPatch, patches } from "plugins";

import { loadLazyChunks } from "./loadLazyChunks";

Expand All @@ -19,7 +19,24 @@ async function runReporter() {
let loadLazyChunksResolve: (value: void | PromiseLike<void>) => void;
const loadLazyChunksDone = new Promise<void>(r => loadLazyChunksResolve = r);

Webpack.beforeInitListeners.add(() => loadLazyChunks().then((loadLazyChunksResolve)));
// The main patch for starting the reporter chunk loading
addPatch({
find: '"Could not find app-mount"',
replacement: {
match: /(?<="use strict";)/,
replace: "Vencord.Webpack._initReporter();"
}
}, "Vencord Reporter");

// @ts-ignore
Vencord.Webpack._initReporter = function () {
// initReporter is called in the patched entry point of Discord
// setImmediate to only start searching for lazy chunks after Discord initialized the app
setTimeout(async () => {
loadLazyChunks().then(loadLazyChunksResolve);
}, 0);
};

await loadLazyChunksDone;

for (const patch of patches) {
Expand Down Expand Up @@ -62,12 +79,12 @@ async function runReporter() {
if (result == null || (result.$$vencordInternal != null && result.$$vencordInternal() == null)) throw new Error("Webpack Find Fail");
} catch (e) {
let logMessage = searchType;
if (method === "find" || method === "proxyLazyWebpack" || method === "LazyComponentWebpack") logMessage += `(${args[0].toString().slice(0, 147)}...)`;
else if (method === "extractAndLoadChunks") logMessage += `([${args[0].map(arg => `"${arg}"`).join(", ")}], ${args[1].toString()})`;
if (method === "find" || method === "proxyLazyWebpack" || method === "LazyComponentWebpack") logMessage += `(${String(args[0]).slice(0, 147)}...)`;
else if (method === "extractAndLoadChunks") logMessage += `([${args[0].map(arg => `"${arg}"`).join(", ")}], ${String(args[1])})`;
else if (method === "mapMangledModule") {
const failedMappings = Object.keys(args[1]).filter(key => result?.[key] == null);

logMessage += `("${args[0]}", {\n${failedMappings.map(mapping => `\t${mapping}: ${args[1][mapping].toString().slice(0, 147)}...`).join(",\n")}\n})`;
logMessage += `("${args[0]}", {\n${failedMappings.map(mapping => `\t${mapping}: ${String(args[1][mapping]).slice(0, 147)}...`).join(",\n")}\n})`;
}
else logMessage += `(${args.map(arg => `"${arg}"`).join(", ")})`;

Expand All @@ -81,4 +98,5 @@ async function runReporter() {
}
}

runReporter();
// Run after the Vencord object has been created
setTimeout(runReporter, 0);
7 changes: 1 addition & 6 deletions src/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,8 @@ declare global {
export var Vesktop: any;
export var VesktopNative: any;

interface Window {
webpackChunkdiscord_app: {
push(chunk: any): any;
pop(): any;
};
interface Window extends Record<PropertyKey, any> {
_: LoDashStatic;
[k: string]: any;
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/plugins/_core/noTrack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { definePluginSettings } from "@api/Settings";
import { Devs } from "@utils/constants";
import { Logger } from "@utils/Logger";
import definePlugin, { OptionType, StartAt } from "@utils/types";
import { WebpackRequire } from "webpack";

const settings = definePluginSettings({
disableAnalytics: {
Expand Down Expand Up @@ -81,9 +82,9 @@ export default definePlugin({
Object.defineProperty(Function.prototype, "g", {
configurable: true,

set(v: any) {
set(this: WebpackRequire, globalObj: WebpackRequire["g"]) {
Object.defineProperty(this, "g", {
value: v,
value: globalObj,
configurable: true,
enumerable: true,
writable: true
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/consoleShortcuts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,12 @@ function makeShortcuts() {
wp: Webpack,
wpc: { getter: () => Webpack.cache },
wreq: { getter: () => Webpack.wreq },
WebpackInstances: { getter: () => Vencord.WebpackPatcher.allWebpackInstances },
wpsearch: search,
wpex: extract,
wpexs: (code: string) => extract(findModuleId(code)!),
loadLazyChunks: IS_DEV ? loadLazyChunks : () => { throw new Error("loadLazyChunks is dev only."); },
filters,
find,
findAll: findAll,
findByProps,
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/devCompanion.dev/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

export const WEBPACK_CHUNK = "webpackChunkdiscord_app";
export const REACT_GLOBAL = "Vencord.Webpack.Common.React";
export const SUPPORT_CHANNEL_ID = "1026515880080842772";

Expand Down
10 changes: 4 additions & 6 deletions src/utils/lazy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

import { UNCONFIGURABLE_PROPERTIES } from "./misc";

export function makeLazy<T>(factory: () => T, attempts = 5): () => T {
let tries = 0;
let cache: T;
Expand All @@ -29,10 +31,6 @@ export function makeLazy<T>(factory: () => T, attempts = 5): () => T {
};
}

// Proxies demand that these properties be unmodified, so proxyLazy
// will always return the function default for them.
const unconfigurable = ["arguments", "caller", "prototype"];

const handler: ProxyHandler<any> = {};

export const SYM_LAZY_GET = Symbol.for("vencord.lazy.get");
Expand All @@ -59,14 +57,14 @@ for (const method of [
handler.ownKeys = target => {
const v = target[SYM_LAZY_GET]();
const keys = Reflect.ownKeys(v);
for (const key of unconfigurable) {
for (const key of UNCONFIGURABLE_PROPERTIES) {
if (!keys.includes(key)) keys.push(key);
}
return keys;
};

handler.getOwnPropertyDescriptor = (target, p) => {
if (typeof p === "string" && unconfigurable.includes(p))
if (typeof p === "string" && UNCONFIGURABLE_PROPERTIES.includes(p))
return Reflect.getOwnPropertyDescriptor(target, p);

const descriptor = Reflect.getOwnPropertyDescriptor(target[SYM_LAZY_GET](), p);
Expand Down
8 changes: 8 additions & 0 deletions src/utils/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ export function pluralise(amount: number, singular: string, plural = singular +
return amount === 1 ? `${amount} ${singular}` : `${amount} ${plural}`;
}

/** Proxies which have an internal target but use a function as the main target require these properties to be unconfigurable */
export const UNCONFIGURABLE_PROPERTIES = ["arguments", "caller", "prototype"];

export function interpolateIfDefined(strings: TemplateStringsArray, ...args: any[]) {
if (args.some(arg => arg == null)) return "";
return strings.reduce((acc, str, i) => `${acc}${str}${args[i] ?? ""}`, "");
}

export function tryOrElse<T>(func: () => T, fallback: T): T {
try {
const res = func();
Expand Down
1 change: 1 addition & 0 deletions src/webpack/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@

export * as Common from "./common";
export * from "./webpack";
export * from "./wreq.d";
Loading