diff --git a/src/renderer/modules/webpack/patch-load.ts b/src/renderer/modules/webpack/patch-load.ts index 0d261fea4..6f01da9a6 100644 --- a/src/renderer/modules/webpack/patch-load.ts +++ b/src/renderer/modules/webpack/patch-load.ts @@ -50,7 +50,7 @@ function patchChunk(chunk: WebpackChunk): void { for (const id in modules) { const originalMod = modules[id]; sourceStrings[id] = originalMod.toString(); - const mod = patchModuleSource(originalMod); + const mod = patchModuleSource(originalMod, id); modules[id] = function (module, exports, require) { mod(module, exports, require); diff --git a/src/renderer/modules/webpack/plaintext-patch.ts b/src/renderer/modules/webpack/plaintext-patch.ts index c4040019b..ca216ee98 100644 --- a/src/renderer/modules/webpack/plaintext-patch.ts +++ b/src/renderer/modules/webpack/plaintext-patch.ts @@ -1,5 +1,7 @@ import type { PlaintextPatch, RawPlaintextPatch, WebpackModule } from "../../../types"; +import { Logger } from "../logger"; +const logger = Logger.api("plaintext-patch"); /** * All plaintext patches */ @@ -10,7 +12,7 @@ export const plaintextPatches: RawPlaintextPatch[] = []; * @param mod Module * @returns Patched module */ -export function patchModuleSource(mod: WebpackModule): WebpackModule { +export function patchModuleSource(mod: WebpackModule, id: string): WebpackModule { const originalSource = mod.toString(); const patchedSource = plaintextPatches.reduce((source, patch) => { @@ -39,8 +41,13 @@ export function patchModuleSource(mod: WebpackModule): WebpackModule { } try { // eslint-disable-next-line no-eval - return (0, eval)(patchedSource); - } catch { + return (0, eval)( + `${ + patchedSource.startsWith("function") ? `0,${patchedSource}` : patchedSource + }\n//# sourceURL=PatchedWebpack-${id}`, + ); + } catch (err) { + logger.error(err); // Syntax error in patched module--fail return mod; }