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 ?? 'jsc',\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,kCAAT,CACLC,qBADK,EAELC,IAFK,EAGL;EACA,MAAMC,WAAwF,GAAG,CAC/FC,MAD+F,EAE/FC,YAF+F,KAI/F,IAAAC,sCAAA,EAAqBF,MAArB,EAA8BA,MAAD,IAAY;IACvCA,MAAM,CAACG,UAAP,GAAoBC,sCAAsC,CACvDH,YADuD,aACvDA,YADuD,cACvDA,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