From 1ed956114f82721e905a33ee3c39ca417ecc0a24 Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Sun, 26 May 2024 05:46:53 -0300 Subject: [PATCH] fix logic --- src/webpack/patchWebpack.ts | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/webpack/patchWebpack.ts b/src/webpack/patchWebpack.ts index 480234dbd..efebaf6bb 100644 --- a/src/webpack/patchWebpack.ts +++ b/src/webpack/patchWebpack.ts @@ -161,7 +161,7 @@ Reflect.defineProperty(Function.prototype, "m", { } }); -let wreqNotInitializedLogged = false; +let wreqFallbackApplied = false; function patchFactory(id: PropertyKey, factory: ModuleFactory) { const originalFactory = factory; @@ -302,22 +302,25 @@ function patchFactory(id: PropertyKey, factory: ModuleFactory) { let [module, exports, require] = args; 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; + if (!wreqFallbackApplied) { + wreqFallbackApplied = true; + + // 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) { logger.error("WebpackRequire was not initialized, running modules without patches instead."); } + } + if (IS_DEV) { return originalFactory.apply(this, args); } }