import { normalizePath } from "@rnx-kit/tools-node" ; import { getMetroResolver , remapReactNativeModule , resolveModulePath , } from "./resolver" ; import type { MetroResolver , Options } from "./types" ; import { remapImportPath } from "./utils/remapImportPath" ; function makeResolver ( { remapModule = ( _ , moduleName , __ ) => moduleName , } = { } ) { const resolve = getMetroResolver ( ) ; const resolvers = [ remapModule , remapReactNativeModule , resolveModulePath ] ; return ( context , moduleName , platform ) => { if ( ! platform ) { throw new Error ( "No platform was specified" ) ; } const backupResolveRequest = context . resolveRequest ; delete context . resolveRequest ; const modifiedModuleName = resolvers . reduce ( ( modifiedName , remap ) => remap ( context , modifiedName , platform ) , moduleName ) ; const resolution = resolve ( context , normalizePath ( modifiedModuleName ) , platform ) ; context . resolveRequest = backupResolveRequest ; return resolution ; } ; } makeResolver . remapImportPath = remapImportPath ; export = makeResolver ;