import { ExpoConfig } from '@expo/config-types' ; import { XcodeProject } from 'xcode' ; import { ConfigPlugin } from '../Plugin.types' ; import { withXcodeProject } from '../plugins/ios-plugins' ; import { addWarningIOS } from '../utils/warnings' ; import { isNotComment } from './utils/Xcodeproj' ; type Bitcode = NonNullable < ExpoConfig [ 'ios' ] > [ 'bitcode' ] ; /**
 * Plugin to set a bitcode preference for the Xcode project
 * based on the project's Expo config `ios.bitcode` value.
 */ export const withBitcode = config => { return withXcodeProject ( config , async ( config ) => { config . modResults = await setBitcodeWithConfig ( config , { project : config . modResults } ) ; return config ; } ) ; } ; param bitcode export const withCustomBitcode = ( config , bitcode ) => { return withXcodeProject ( config , async ( config ) => { config . modResults = await setBitcode ( bitcode , { project : config . modResults } ) ; return config ; } ) ; } ; /**
 * Get the bitcode preference from the Expo config.
 */ export function getBitcode ( config ) { return config . ios ?. bitcode ; } /**
 * Enable or disable the `ENABLE_BITCODE` property of the project configurations.
 */ export function setBitcodeWithConfig ( config , { project } ) { const bitcode = getBitcode ( config ) ; return setBitcode ( bitcode , { project } ) ; } /**
 * Enable or disable the `ENABLE_BITCODE` property.
 */ export function setBitcode ( bitcode , { project } ) { const isDefaultBehavior = bitcode == null ; if ( isDefaultBehavior ) { return project ; } const targetName = typeof bitcode === 'string' ? bitcode : undefined ; const isBitcodeEnabled = ! ! bitcode ; if ( targetName ) { const configs = Object . entries ( project . pbxXCBuildConfigurationSection ( ) ) . filter ( isNotComment ) ; const hasConfiguration = configs . find ( ( [ , configuration ] ) => configuration . name === targetName ) ; if ( hasConfiguration ) { project . addBuildProperty ( 'ENABLE_BITCODE' , 'NO' ) ; } else { const names = [ ... new Set ( configs . map ( ( [ , configuration ] ) => `"${ configuration . name }"` ) ) , ] . sort ( ) ; addWarningIOS ( 'ios.bitcode' , `No configuration named "${ targetName }". Expected one of: ${ names . join ( ', ' ) }.` ) ; } } project . addBuildProperty ( 'ENABLE_BITCODE' , isBitcodeEnabled ? 'YES' : 'NO' , targetName ) ; return project ; }