From a8fa685cfac63ceff4d3905d47d4d6683f9dbac6 Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Sun, 26 May 2024 05:28:34 -0300 Subject: [PATCH] Add back running modules without patches --- src/webpack/patchWebpack.ts | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/webpack/patchWebpack.ts b/src/webpack/patchWebpack.ts index e756d3d0b..480234dbd 100644 --- a/src/webpack/patchWebpack.ts +++ b/src/webpack/patchWebpack.ts @@ -161,6 +161,8 @@ Reflect.defineProperty(Function.prototype, "m", { } }); +let wreqNotInitializedLogged = false; + function patchFactory(id: PropertyKey, factory: ModuleFactory) { const originalFactory = factory; @@ -299,16 +301,25 @@ function patchFactory(id: PropertyKey, factory: ModuleFactory) { // eslint-disable-next-line prefer-const let [module, exports, require] = args; - // Make sure the require argument is actually the WebpackRequire function - if (wreq == null && typeof require === "function" && require.m != null) { - const { stack } = new Error(); - const webpackInstanceFileName = stack?.match(/\/assets\/(.+?\.js)/)?.[1]; - logger.warn( - "WebpackRequire was not initialized, falling back to WebpackRequire passed to the first called patched module factory (" + - `id: ${String(id)}` + interpolateIfDefined`, WebpackInstance origin: ${webpackInstanceFileName}` + - ")" - ); - _initWebpack(require); + if (wreq == null) { + // Make sure the require argument is actually the WebpackRequire function + if (typeof require === "function" && require.m != null) { + const { stack } = new Error(); + const webpackInstanceFileName = stack?.match(/\/assets\/(.+?\.js)/)?.[1]; + logger.warn( + "WebpackRequire was not initialized, falling back to WebpackRequire passed to the first called patched module factory (" + + `id: ${String(id)}` + interpolateIfDefined`, WebpackInstance origin: ${webpackInstanceFileName}` + + ")" + ); + _initWebpack(require); + } else if (IS_DEV) { + if (!wreqNotInitializedLogged) { + wreqNotInitializedLogged = true; + logger.error("WebpackRequire was not initialized, running modules without patches instead."); + } + + return originalFactory.apply(this, args); + } } let factoryReturn: unknown;