Add back running modules without patches

This commit is contained in:
Nuckyz 2024-05-26 05:28:34 -03:00
parent 265cf12d39
commit a8fa685cfa
No known key found for this signature in database
GPG key ID: 440BF8296E1C4AD9

View file

@ -161,6 +161,8 @@ Reflect.defineProperty(Function.prototype, "m", {
}
});
let wreqNotInitializedLogged = false;
function patchFactory(id: PropertyKey, factory: ModuleFactory) {
const originalFactory = factory;
@ -299,8 +301,9 @@ function patchFactory(id: PropertyKey, factory: ModuleFactory) {
// eslint-disable-next-line prefer-const
let [module, exports, require] = args;
if (wreq == null) {
// Make sure the require argument is actually the WebpackRequire function
if (wreq == null && typeof require === "function" && require.m != null) {
if (typeof require === "function" && require.m != null) {
const { stack } = new Error();
const webpackInstanceFileName = stack?.match(/\/assets\/(.+?\.js)/)?.[1];
logger.warn(
@ -309,6 +312,14 @@ function patchFactory(id: PropertyKey, factory: ModuleFactory) {
")"
);
_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;