From eec5465bbb67685627617de4f273829c612770b9 Mon Sep 17 00:00:00 2001 From: Rosie Val Date: Thu, 6 Aug 2026 11:45:54 -0400 Subject: [PATCH] ServerDrawer: implement rawFindAll to support createElementIntercept scanning --- plugins/server-drawer/src/lib/rawFind.ts | 32 ++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/plugins/server-drawer/src/lib/rawFind.ts b/plugins/server-drawer/src/lib/rawFind.ts index 178a371..c8e3d2e 100644 --- a/plugins/server-drawer/src/lib/rawFind.ts +++ b/plugins/server-drawer/src/lib/rawFind.ts @@ -39,6 +39,38 @@ export function rawFind(predicate: (exports: any) => boolean): T | unde return undefined; } +export function rawFindAll(predicate: (exports: any) => boolean): T[] { + const modules = window?.modules; + if (!modules) return []; + + const results: T[] = []; + const seen = new Set(); + + for (const id in modules) { + const def = modules[id]; + if (!def?.isInitialized) continue; + + const exports = def.publicModule?.exports; + if (!exports) continue; + + try { + if (predicate(exports) && !seen.has(exports)) { + results.push(exports); + seen.add(exports); + } + const dflt = exports.default; + if (dflt != null && predicate(dflt) && !seen.has(dflt)) { + results.push(dflt); + seen.add(dflt); + } + } catch { + // Ignore predicate errors and continue scanning. + } + } + + return results; +} + export function rawFindByTypeName(name: string): T | undefined { return rawFind((m) => m?.name === name || m?.displayName === name || m?.type?.name === name || m?.type?.displayName === name); }