webpack: make window exports non enumerable

main
Vendicated 5 months ago
parent da01237c05
commit 9b9a5322c9
No known key found for this signature in database
GPG Key ID: D66986BAF75ECF18

@ -209,7 +209,7 @@ function patchFactories(factories: Record<string, (module: any, exports: any, re
// There are (at the time of writing) 11 modules exporting the window // There are (at the time of writing) 11 modules exporting the window
// Make these non enumerable to improve webpack search performance // Make these non enumerable to improve webpack search performance
if (exports === window && require.c) { if (require.c && (exports === window || exports?.default === window)) {
Object.defineProperty(require.c, id, { Object.defineProperty(require.c, id, {
value: require.c[id], value: require.c[id],
enumerable: false, enumerable: false,
@ -229,7 +229,7 @@ function patchFactories(factories: Record<string, (module: any, exports: any, re
for (const [filter, callback] of subscriptions) { for (const [filter, callback] of subscriptions) {
try { try {
if (filter(exports)) { if (exports && filter(exports)) {
subscriptions.delete(filter); subscriptions.delete(filter);
callback(exports, id); callback(exports, id);
} else if (exports.default && filter(exports.default)) { } else if (exports.default && filter(exports.default)) {

@ -106,13 +106,13 @@ export const find = traceFunction("find", function find(filter: FilterFn, { isIn
for (const key in cache) { for (const key in cache) {
const mod = cache[key]; const mod = cache[key];
if (!mod?.exports || mod.exports === window) continue; if (!mod?.exports) continue;
if (filter(mod.exports)) { if (filter(mod.exports)) {
return isWaitFor ? [mod.exports, key] : mod.exports; return isWaitFor ? [mod.exports, key] : mod.exports;
} }
if (mod.exports.default && mod.exports.default !== window && filter(mod.exports.default)) { if (mod.exports.default && filter(mod.exports.default)) {
const found = mod.exports.default; const found = mod.exports.default;
return isWaitFor ? [found, key] : found; return isWaitFor ? [found, key] : found;
} }

Loading…
Cancel
Save