import { loadValidatedConfig } from '@app-config/config' ; import { currentEnvironment } from '@app-config/node' ; import { generateModuleText } from '@app-config/utils' ; import { relative } from 'path' ; import { Transformer , upstreamTransformer } from './upstream-transformer' ; /**
 * Transform is called by Metro for each package resolved in the React Native project
 */ export const transform = async ( { src , filename , options } ) => { const appConfigPath = relative ( options . projectRoot , require . resolve ( '@app-config/main' , { paths : [ options . projectRoot ] , } ) ) ; if ( filename !== appConfigPath ) { return upstreamTransformer . transform ( { src , filename , options } ) ; } const { fullConfig } = await loadValidatedConfig ( ) ; const modifiedSrc = generateModuleText ( fullConfig , { environment : currentEnvironment ( ) , useGlobalNamespace : false , validationFunctionCode : undefined , esmValidationCode : false , } ) ; return upstreamTransformer . transform ( { src : modifiedSrc , filename , options } ) ; } ;