fix(Webpack): Not canonicalizing regex in some places

This commit is contained in:
Nuckyz 2024-08-18 00:47:16 -03:00
parent 051bce89f8
commit 9cada9ad13
No known key found for this signature in database
GPG key ID: 440BF8296E1C4AD9

View file

@ -38,15 +38,15 @@ export let cache: WebpackInstance["c"];
export type FilterFn = (mod: any) => boolean; export type FilterFn = (mod: any) => boolean;
type PropsFilter = Array<string>; export type PropsFilter = Array<string>;
type CodeFilter = Array<string | RegExp>; export type CodeFilter = Array<string | RegExp>;
type StoreNameFilter = string; export type StoreNameFilter = string;
const stringMatches = (s: string, filter: CodeFilter) => export const stringMatches = (s: string, filter: CodeFilter) =>
filter.every(f => filter.every(f =>
typeof f === "string" typeof f === "string"
? s.includes(f) ? s.includes(f)
: f.test(s) : (f.global && (f.lastIndex = 0), f.test(s))
); );
export const filters = { export const filters = {
@ -258,6 +258,8 @@ export const findBulk = traceFunction("findBulk", function findBulk(...filterFns
* @returns string or null * @returns string or null
*/ */
export const findModuleId = traceFunction("findModuleId", function findModuleId(...code: CodeFilter) { export const findModuleId = traceFunction("findModuleId", function findModuleId(...code: CodeFilter) {
code = code.map(canonicalizeMatch);
for (const id in wreq.m) { for (const id in wreq.m) {
if (stringMatches(wreq.m[id].toString(), code)) return id; if (stringMatches(wreq.m[id].toString(), code)) return id;
} }
@ -452,12 +454,9 @@ export function findExportedComponentLazy<T extends object = any>(...props: Prop
* }) * })
*/ */
export const mapMangledModule = traceFunction("mapMangledModule", function mapMangledModule<S extends string>(code: string | RegExp | CodeFilter, mappers: Record<S, FilterFn>): Record<S, any> { export const mapMangledModule = traceFunction("mapMangledModule", function mapMangledModule<S extends string>(code: string | RegExp | CodeFilter, mappers: Record<S, FilterFn>): Record<S, any> {
if (!Array.isArray(code)) code = [code];
code = code.map(canonicalizeMatch);
const exports = {} as Record<S, any>; const exports = {} as Record<S, any>;
const id = findModuleId(...code); const id = findModuleId(...Array.isArray(code) ? code : [code]);
if (id === null) if (id === null)
return exports; return exports;
@ -606,6 +605,8 @@ export function waitFor(filter: string | PropsFilter | FilterFn, callback: Callb
* @returns Mapping of found modules * @returns Mapping of found modules
*/ */
export function search(...code: CodeFilter) { export function search(...code: CodeFilter) {
code = code.map(canonicalizeMatch);
const results = {} as Record<number, Function>; const results = {} as Record<number, Function>;
const factories = wreq.m; const factories = wreq.m;