feat(lib/modules/finders/lookup): warn about bad filters in development builds
This commit is contained in:
parent
273294df82
commit
331f509f8d
1 changed files with 13 additions and 0 deletions
|
|
@ -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<T = any>(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.`,
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue