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.`, + ) +}