Add back running modules without patches

This commit is contained in:
Nuckyz 2024-05-26 05:28:34 -03:00
parent 067a16c9dc
commit b2036762b5
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) { function patchFactory(id: PropertyKey, factory: ModuleFactory) {
const originalFactory = factory; const originalFactory = factory;
@ -299,16 +301,25 @@ function patchFactory(id: PropertyKey, factory: ModuleFactory) {
// eslint-disable-next-line prefer-const // eslint-disable-next-line prefer-const
let [module, exports, require] = args; let [module, exports, require] = args;
// Make sure the require argument is actually the WebpackRequire function if (wreq == null) {
if (wreq == null && typeof require === "function" && require.m != null) { // Make sure the require argument is actually the WebpackRequire function
const { stack } = new Error(); if (typeof require === "function" && require.m != null) {
const webpackInstanceFileName = stack?.match(/\/assets\/(.+?\.js)/)?.[1]; const { stack } = new Error();
logger.warn( const webpackInstanceFileName = stack?.match(/\/assets\/(.+?\.js)/)?.[1];
"WebpackRequire was not initialized, falling back to WebpackRequire passed to the first called patched module factory (" + logger.warn(
`id: ${String(id)}` + interpolateIfDefined`, WebpackInstance origin: ${webpackInstanceFileName}` + "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); );
_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; let factoryReturn: unknown;