From a370c1f7d3dca0db56a346c98c28ed9681a415e0 Mon Sep 17 00:00:00 2001 From: AAGaming Date: Wed, 24 Jul 2024 00:59:28 -0400 Subject: [PATCH] feat(classMapper): add classModuleMap, make findClass require ID --- src/class-mapper.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/class-mapper.ts b/src/class-mapper.ts index 86d8f627..079f6eac 100644 --- a/src/class-mapper.ts +++ b/src/class-mapper.ts @@ -1,10 +1,10 @@ -import { Module, findAllModules } from './webpack'; +import { Module, ModuleID, createModuleMapping } from './webpack'; export interface ClassModule { [name: string]: string; } -export const classMap: ClassModule[] = findAllModules((m: Module) => { +export const classModuleMap: Map = createModuleMapping((m: Module) => { if (typeof m == 'object' && !m.__esModule) { const keys = Object.keys(m); // special case some libraries @@ -17,16 +17,19 @@ export const classMap: ClassModule[] = findAllModules((m: Module) => { return false; }); -export function findClass(name: string): string | void { - return classMap.find((m) => m?.[name])?.[name]; +export const classMap = classModuleMap.values(); + +export function findClass(id: string, name: string): string | void { + return classModuleMap.get(id)?.[name]; } export function findClassModule(filter: (module: any) => boolean): ClassModule | void { - return classMap.find((m) => filter(m)); + // TODO optimize + return [...classModuleMap.values()].find((m) => filter(m)); } export function unminifyClass(minifiedClass: string): string | void { - for (let m of classMap) { + for (let m of classModuleMap.values()) { for (let className of Object.keys(m)) { if (m[className] == minifiedClass) return className; }