metro
namespace metroNamespaces
Functions
bulk(...items: MetroBulkItem[]): any[]
Runs several filters in a single registry pass, returning one result per item.
Returns
An array of matches positionally aligned with items.
filter<A extends FilterArgument[]>(predicate: FilterPredicate<A>): (...args: A) => MetroFilter
Defines a reusable filter that takes arguments. Its cache key is the build's hash of predicate's source plus the arguments' JSON, so every plugin defining the same filter shares one cache entry.
Returns
A function building the MetroFilter for a set of arguments.
find(filter: MetroFilter, options?: MetroSearchOptions): any
Finds a module matching a filter. Lazy unless { lazy: false } is passed, or all is set: the search runs on first access.
Returns
The matched module, an array of matches when all is set, undefined when the cache knows it is missing, or null.
findByFilePath<K extends MetroLookupFirst<MetroModulePath>, T extends MetroLookupArgs<string>>(first: K, ...rest: T): MetroModuleOrArray<[K, ...T[]], string><T extends MetroLookupArgs<string>>(...args: T): MetroModuleOrArray<T, string>
Finds a module by a segment of its file path. Lazy unless { lazy: false } is passed: the search runs on first access.
Returns
The matched module, typed from Discord's modules when the path is known.
findByName<K extends MetroLookupFirst<MetroModuleName>, T extends MetroLookupArgs<string>>(first: K, ...rest: T): MetroFunctionSignatureOrArray<[K, ...T[]], string><T extends MetroLookupArgs<string>>(...args: T): MetroFunctionSignatureOrArray<T, string>
Finds a module by the name of its default export. Lazy unless { lazy: false } is passed: the search runs on first access.
Returns
The matched function (or matches, for a bulk/all search), typed from Discord's modules when the name is known.
findByProps<K extends MetroLookupFirst<MetroPropName>, T extends MetroLookupArgs<string>>(first: K, ...rest: T): MetroPropertyRecordOrArray<[K, ...T[]], string><T extends MetroLookupArgs<string>>(...args: T): MetroPropertyRecordOrArray<T, string>
Finds a module exposing all of the given property names. Lazy unless { lazy: false } is passed: the search runs on first access.
Returns
The matched module (or matches, for a bulk/all search), typed from Discord's modules when the props are known.
findByPrototypes<U extends string, T extends U[] | MetroStringFindWithOptions<U, MetroSearchOptions> | MetroBulkFind<U>>(...args: T): AnyProps
Finds a module whose prototype exposes all of the given method names. Lazy unless { lazy: false } is passed: the search runs on first access.
Returns
The matched module.
findLazy(filter: MetroFilter, options?: MetroLazySearchOptions): any
Resolves a module matching filter once it loads, without ever loading it.
Returns
The loaded module, or a promise of the module once Discord loads it, or of undefined if signal aborts first
or a full search of this Discord build found the module missing.
getLoadedModule<T>(handle: T): T | undefined
Gives the module a lazy handle stands for once it has loaded, so a caller can keep the real object instead of reading through the proxy. It never loads a module.
Returns
The loaded module, undefined while the handle's module has not loaded, or handle itself when it is not a lazy handle.
getModulePresence(handle: MetroExport): MetroModulePresence | undefined
Reports what is known of a lazy handle's module, without loading it or resolving the handle.
A plugin should treat unknown as present: a patch on the handle waits for the module, so it never applies to nothing.
Returns
The module's MetroModulePresence, or undefined when handle is not a handle a patch waits on.
initializeModule(id: number): boolean
Forces a module to initialise via metro's __r, blacklisting it if it throws.
Returns
true if the module is initialised, false if it was blacklisted.
onModuleLoad(listener: MetroModuleLoadListener): () => void
Registers a listener invoked with every module as it loads.
Returns
A function that removes the listener.
onModuleLoaded(filter: MetroFilter, onLoad: (mdl: MetroExport) => void, waitOptions?: MetroWaitOptions): () => void
Calls onLoad with the module matching filter once it initializes, without ever initializing it.
A loaded module is passed at once; otherwise onLoad runs inside the module's factory, before its importer reads it.
A module a full search of this Discord build found missing never loads, so onLoad never runs for it; onMissing runs instead.
Returns
A function that stops waiting; it does nothing once onLoad has run.
Types
An object of shape T widened with an arbitrary property index.
The 21822 export names suggested for a lookup: those of modules with 2 or more distinctive ones.
The source paths of those modules, suggested for findByFilePath.
For each of 242 export names of DiscordModules, the keys exposing it, or string for a name more than
3 modules expose. A name another module shares is missing, so its lookups stay loose.
The 35 modules of Discord discord-350 with a typed export, keyed by source path, or by ~ and a
hash of the export names for a module without one. Their other exports are any.
Default-exported design-barrel components by their runtime name, the key findByName matches.
A value a filter argument may hold: its JSON is part of the filter's cache key.
A predicate taking a module and a filter's arguments; the build gives it a cache key from its source.
Props of FormArrow (function). Exports: default.
Props of FormIcon (function). Exports: default.
Props for HelpMessage; the defaults named here are those of Unbound's fallback.
A HelpMessage style: one of the HelpMessageTypes values.
React Native's ImageSourceUtils, which every Image render resolves its source through.
The keys exposing one prop: a short union, string for a prop too common to narrow, never for an unknown one.
The keys exposing every prop of K: the intersection of each prop's keys.
Widens a single result to an array when the search was made with all: true; a single one is undefined when the cache knows it is missing.
Tuple of param bags followed by a { bulk: true } marker, describing a bulk find.
A single entry in a bulk search: a filter plus its per-item options.
The marker object distinguishing a bulk find from a single one.
Result shape of a bulk by-name search, one function per requested item.
Result shape of a bulk by-property search, one record per requested item.
A module predicate, carrying its cache key and a raw flag, produced by every by* helper.
A function or class exported by a Discord module, whose signature Discord does not document.
Dispatches to the bulk or single by-name result shape.
Options that control internal search behaviour shared across every findBy* helper.
Options for findLazy, adding a signal that abandons the wait when aborted.
The arguments a findBy* lookup takes: search terms, optionally ending in options, or bulk param bags.
The first argument of a findBy* lookup: a search term, or a bulk find's first param bag. It is its own
parameter because only a non-rest parameter offers its string literals as completions.
Convenience alias for a by-property result derived from a union of prop names.
The exports of the module at path P, typed from Discord's module index, else AnyProps.
The default export findByName returns for N, or never when no Discord module's is named N.
The exports findByFilePath returns for P, or never when no Discord module has that path.
The module findByProps returns for the props K: the one Discord module exposing them all, or the union of
several. never when none does, or when every prop is too common to narrow the match.
A key of DiscordModules: a typed module's source path, or ~ and a hash of its export names.
Options for onModuleLoaded: whether to also match a module's default export, and to return it on such a match.
Called with each module's exports and id as the module loads.
A name findByName takes: a default export's runtime name, or any other string.
Dispatches to the bulk or single by-path result shape.
A source path findByFilePath takes: a Discord module's path, or any other string.
What is known of a module without loading it: loaded once loaded, present when an earlier search
found it in this build, missing when a full search of this build found nothing, and unknown otherwise.
The module exposing the props K, typed from Discord's module index, else a record of the props.
Either stays AnyProps: the index misses exports made at runtime, such as export * copies.
The default export named N, typed from Discord's module index, else an untyped MetroFunction.
A bag carrying a params array of prop names.
Dispatches to the bulk or single by-property result shape.
A prop name findByProps takes: an export name of a Discord module, or any other string.
A record keyed by the requested prop names.
Public options accepted by find and the findBy* family.
Result shape of a by-name search: the matched function (or its default export).
Result shape of a by-path search: the module's exports.
Result shape of a by-property search: a record keyed by the requested props.
Search options for flux.getStore, adding the short name-matching toggle.
Tuple of search terms followed by a trailing options object.
Options for onModuleLoaded's wait, adding onMissing, run at once instead of waiting when the cache knows the module is missing.
T, or Fallback when T is never.
Props of RowCheckmark (function). Exports: default.
The props of Discord's FormSwitch, which the switch fallback accepts.
Props of FormCheckbox (function). Exports: default.
Props of FormRadio (function). Exports: default.
A function exported by a Discord module, whose signature Discord does not document.
Variables
blacklist: Set<number>
Ids of metro modules that threw while initialising; searches skip them.
data: { cache: Map<any, any>; filePaths: Map<string, number>; importingModuleId: number; importTrackerId: number; initialized: number[]; listeners: Set<MetroModuleLoadListener>; origToString: any; patchedImportTracker: boolean; patchedNativeRequire: boolean; patchedRTNProfiler: boolean }
Metro search's mutable internal state: the module cache, load listeners and which require hooks are installed.