From 331f509f8d5bdb5e76f0f5c8ad3451b5e7a90c59 Mon Sep 17 00:00:00 2001 From: PalmDevs Date: Thu, 15 May 2025 15:12:29 +0700 Subject: [PATCH] feat(lib/modules/finders/lookup): warn about bad filters in development builds --- lib/modules/src/finders/lookup.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/modules/src/finders/lookup.ts b/lib/modules/src/finders/lookup.ts index 78bbe99..659b1f0 100644 --- a/lib/modules/src/finders/lookup.ts +++ b/lib/modules/src/finders/lookup.ts @@ -143,6 +143,7 @@ export function* lookupModules(filter: Filter, options?: LookupModulesOptions) { const exports = __r(id) const flag = runFilter(filter, id, exports, options) if (flag) yield exportsFromFilterResultFlag(flag, exports, options) + warnDeveloperAboutAPartialFilterMatch(id, filter.key) } } @@ -219,6 +220,7 @@ export function lookupModule(filter: Filter, options?: LookupModulesOptions) { // Run the filter again to ensure we have the correct exports const flag = runFilter(filter, id, exports, options) if (flag) return exportsFromFilterResultFlag(flag, exports, options) + warnDeveloperAboutAPartialFilterMatch(id, filter.key) } } @@ -254,3 +256,14 @@ export function lookupModuleByImportedPath(path: string): T | undefined // undefined will also return undefined either way, so we can just non-nullish assert it return getInitializedModuleExports(lookupModuleIdByImportedPath(path)!) } + +/** + * Warns the developer that the filter matched during exportsless comparison, but not during the full comparison. + * This will cause modules to be initialized unnecessarily, and may cause issues. + * @internal + */ +function warnDeveloperAboutAPartialFilterMatch(id: Metro.ModuleID, key: string) { + console.warn( + `[revenge.modules.finders.lookup] Module ${id} matched ${key} during uninitialized lookup, but did not match the full filter.`, + ) +}