1{"version":3,"file":"BuildProperties.js","names":["createBuildGradlePropsConfigPlugin","configToPropertyRules","name","withUnknown","config","sourceConfig","withGradleProperties","modResults","updateAndroidBuildPropertiesFromConfig","Object","defineProperty","value","withJsEngineGradleProps","propName","propValueGetter","android","jsEngine","gradleProperties","configToProperty","updateAndroidBuildProperty","options","oldPropIndex","findIndex","prop","type","key","newProp","push","removePropWhenValueIsNull","splice"],"sources":["../../src/android/BuildProperties.ts"],"sourcesContent":["import type { ExpoConfig } from '@expo/config-types';\n\nimport type { ConfigPlugin } from '../Plugin.types';\nimport { withGradleProperties } from '../plugins/android-plugins';\nimport { BuildPropertiesConfig, ConfigToPropertyRuleType } from '../utils/BuildProperties.types';\nimport type { PropertiesItem } from './Properties';\n\n/**\n * Creates a `withGradleProperties` config-plugin based on given config to property mapping rules.\n *\n * The factory supports two modes from generic type inference\n * ```ts\n * // config-plugin without `props`, it will implicitly use the expo config as source config.\n * createBuildGradlePropsConfigPlugin<ExpoConfig>(): ConfigPlugin<void>;\n *\n * // config-plugin with a parameter `props: CustomType`, it will use the `props` as source config.\n * createBuildGradlePropsConfigPlugin<CustomType>(): ConfigPlugin<CustomType>;\n * ```\n *\n * @param configToPropertyRules config to property mapping rules\n * @param name the config plugin name\n */\nexport function createBuildGradlePropsConfigPlugin<SourceConfigType extends BuildPropertiesConfig>(\n configToPropertyRules: ConfigToPropertyRuleType<SourceConfigType>[],\n name?: string\n) {\n const withUnknown: ConfigPlugin<SourceConfigType extends ExpoConfig ? void : SourceConfigType> = (\n config,\n sourceConfig\n ) =>\n withGradleProperties(config, (config) => {\n config.modResults = updateAndroidBuildPropertiesFromConfig(\n (sourceConfig ?? config) as SourceConfigType,\n config.modResults,\n configToPropertyRules\n );\n return config;\n });\n if (name) {\n Object.defineProperty(withUnknown, 'name', {\n value: name,\n });\n }\n return withUnknown;\n}\n\n/**\n * A config-plugin to update `android/gradle.properties` from the `jsEngine` in expo config\n */\nexport const withJsEngineGradleProps = createBuildGradlePropsConfigPlugin<ExpoConfig>(\n [\n {\n propName: 'expo.jsEngine',\n propValueGetter: (config) => config.android?.jsEngine ?? config.jsEngine ?? 'hermes',\n },\n ],\n 'withJsEngineGradleProps'\n);\n\nexport function updateAndroidBuildPropertiesFromConfig<\n SourceConfigType extends BuildPropertiesConfig\n>(\n config: SourceConfigType,\n gradleProperties: PropertiesItem[],\n configToPropertyRules: ConfigToPropertyRuleType<SourceConfigType>[]\n) {\n for (const configToProperty of configToPropertyRules) {\n const value = configToProperty.propValueGetter(config);\n updateAndroidBuildProperty(gradleProperties, configToProperty.propName, value);\n }\n\n return gradleProperties;\n}\n\nexport function updateAndroidBuildProperty(\n gradleProperties: PropertiesItem[],\n name: string,\n value: string | null | undefined,\n options?: { removePropWhenValueIsNull?: boolean }\n) {\n const oldPropIndex = gradleProperties.findIndex(\n (prop) => prop.type === 'property' && prop.key === name\n );\n\n if (value) {\n // found the matched value, add or merge new property\n const newProp: PropertiesItem = {\n type: 'property',\n key: name,\n value,\n };\n\n if (oldPropIndex >= 0) {\n gradleProperties[oldPropIndex] = newProp;\n } else {\n gradleProperties.push(newProp);\n }\n } else if (options?.removePropWhenValueIsNull && oldPropIndex >= 0) {\n gradleProperties.splice(oldPropIndex, 1);\n }\n\n return gradleProperties;\n}\n"],"mappings":";;;;;;;;;AAGA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,kCAAkC,CAChDC,qBAAmE,EACnEC,IAAa,EACb;EACA,MAAMC,WAAwF,GAAG,CAC/FC,MAAM,EACNC,YAAY,KAEZ,IAAAC,sCAAoB,EAACF,MAAM,EAAGA,MAAM,IAAK;IACvCA,MAAM,CAACG,UAAU,GAAGC,sCAAsC,CACvDH,YAAY,aAAZA,YAAY,cAAZA,YAAY,GAAID,MAAM,EACvBA,MAAM,CAACG,UAAU,EACjBN,qBAAqB,CACtB;IACD,OAAOG,M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