Merge branch 'modules-proxy-patches' into immediate-finds-modules-proxy

This commit is contained in:
Nuckyz 2024-05-24 08:24:56 -03:00
commit 5b96881177
No known key found for this signature in database
GPG key ID: 440BF8296E1C4AD9
2 changed files with 5 additions and 5 deletions

View file

@ -281,7 +281,7 @@ function patchFactory(id: PropertyKey, factory: ModuleFactory) {
if (!patch.all) patches.splice(i--, 1);
}
const patchedFactory: PatchedModuleFactory = (module, exports, require) => {
const patchedFactory: PatchedModuleFactory = function (module, exports, require) {
for (const moduleFactories of allModuleFactories) {
Object.defineProperty(moduleFactories, id, {
value: patchedFactory.$$vencordOriginal,
@ -297,17 +297,17 @@ function patchFactory(id: PropertyKey, factory: ModuleFactory) {
logger.error("WebpackRequire was not initialized, running modules without patches instead.");
}
return void originalFactory(module, exports, require);
return void originalFactory.call(this, module, exports, require);
}
try {
factory(module, exports, require);
factory.call(this, module, exports, require);
} catch (err) {
// Just rethrow Discord errors
if (factory === originalFactory) throw err;
logger.error("Error in patched module", err);
return void originalFactory(module, exports, require);
return void originalFactory.call(this, module, exports, require);
}
// Webpack sometimes sets the value of module.exports directly, so assign exports to it to make sure we properly handle it

View file

@ -13,7 +13,7 @@ export type Module = {
};
/** exports can be anything, however initially it is always an empty object */
export type ModuleFactory = (module: Module, exports: ModuleExports, require: WebpackRequire) => void;
export type ModuleFactory = (this: ModuleExports, module: Module, exports: ModuleExports, require: WebpackRequire) => void;
export type AsyncModuleBody = (
handleDependencies: (deps: Promise<any>[]) => Promise<any[]> & (() => void)