diff --git a/lib/modules/src/finders/_internal.ts b/lib/modules/src/finders/_internal.ts index f5d54e1..fc3cf87 100644 --- a/lib/modules/src/finders/_internal.ts +++ b/lib/modules/src/finders/_internal.ts @@ -53,21 +53,21 @@ export type FilterResultFlag = (typeof FilterResultFlags)[keyof typeof FilterRes // Currently, we only have options that are relevant for checking exports // If we add more options later on, do NOT forget about // adding them here, and passing them in the lookup* functions -export function runFilter(filter: Filter, id: Metro.ModuleID): FilterResultFlag | false +export function runFilter(filter: Filter, id: Metro.ModuleID): FilterResultFlag | undefined export function runFilter( filter: Filter, id: Metro.ModuleID, exports: Metro.ModuleExports, options?: RunFilterOptions, -): FilterResultFlag | false +): FilterResultFlag | undefined export function runFilter( filter: Filter, id: Metro.ModuleID, exports?: Metro.ModuleExports, options?: RunFilterOptions, -): FilterResultFlag | false { +): FilterResultFlag | undefined { if (exports?.__esModule) { const { default: defaultExport } = exports @@ -86,7 +86,7 @@ export function runFilter( return FilterResultFlags.Found } - return false + return } export function exportsFromFilterResultFlag( diff --git a/lib/modules/src/metro/_internal.ts b/lib/modules/src/metro/_internal.ts index fd08cb8..c896315 100644 --- a/lib/modules/src/metro/_internal.ts +++ b/lib/modules/src/metro/_internal.ts @@ -38,7 +38,6 @@ export function patchMetroDefine(metroDefine: Metro.DefineFn) { // Add the module to the initialized set only if the factory doesn't error or the exports aren't bad _mInited.add(id) } catch { - _blacklist(id) } finally { _mInitingId = prevIId _mUninited.delete(id) @@ -51,38 +50,3 @@ export function patchMetroDefine(metroDefine: Metro.DefineFn) { ) }) satisfies Metro.DefineFn } - -/** - * Blacklists a module. A module can be blacklisted for several reasons: - * - * - If the module is already initialized, it either means: - * - The module factory threw an error during initialization - * - The module exports are bad after initialization - * - Otherwise, this module is known to be bad from previous caches - * - * @param id The module ID to blacklist. - * @internal - */ -export function _blacklist(id: Metro.ModuleID) { - // In case blacklisting happens before the module is initialized - _mUninited.delete(id) - - // Usually we'd also remove the module from _mInited too, - // but we already have an else block in the patchMetroDefine function that does that for us. - // _mInited.delete(id) - - // TODO(modules): caching -} - -/// BLACKLIST RESTORATION - -if (globalThis.__REVENGE_CACHE_MODULE_BLACKLIST__) - for (const id of globalThis.__REVENGE_CACHE_MODULE_BLACKLIST__) _blacklist(id) - -// @ts-expect-error -// biome-ignore lint/performance/noDelete: no -delete globalThis.__REVENGE_CACHE_MODULE_BLACKLIST__ - -declare namespace globalThis { - const __REVENGE_CACHE_MODULE_BLACKLIST__: Metro.ModuleID[] | undefined -} diff --git a/lib/modules/src/metro/utils.ts b/lib/modules/src/metro/utils.ts index c86142f..7a39314 100644 --- a/lib/modules/src/metro/utils.ts +++ b/lib/modules/src/metro/utils.ts @@ -58,10 +58,7 @@ export function isModuleExportBad(exp: Metro.ModuleExports[PropertyKey]): boolea // Nullish? exp == null || // Is it a proxy? (discord-intl has proxy exports) - isProxy(exp) || - // Can't run isProxy() on this because this isn't your typical proxy: - // https://github.com/discord/react-native/blob/master/packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/TurboModuleBinding.cpp - exp === nativeModuleProxy + isProxy(exp) ) } @@ -81,6 +78,9 @@ export function isModuleExportsBad(exports: Metro.ModuleExports): boolean { // - String, Boolean, Symbol, BigInt exports are not useful (who would do `module.exports = ...`?) !(typeof exports === 'object' || typeof exports === 'function') || // Checking if the object is empty - (exports.__proto__ === Object.prototype && !Reflect.ownKeys(exports).length) + (exports.__proto__ === Object.prototype && !Reflect.ownKeys(exports).length) || + // Can't run isProxy() on this because this isn't your typical proxy: + // https://github.com/discord/react-native/blob/master/packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/TurboModuleBinding.cpp + exports === nativeModuleProxy ) }