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AC,WAAW,CAAC,CAAC;IAC7E,OAAO,iBAAiB,CAAC,WAAW,CAAC,QAAQ,CAAC,yBAAyB,CAAC,CAAC;AAC3E,CAAC;AAPD,8EAOC;AAED,SAAgB,uBAAuB,CAAC,SAAoB;IAC1D,OAAO,OAAO,CACZ,SAAS,CAAC,YAAY,IAAI,CAAC,SAAS,CAAC,mBAAmB,IAAI,SAAS,CAAC,uBAAuB,CAAC,CAC/F,CAAC;AACJ,CAAC;AAJD,0DAIC;AAED,SAAgB,0BAA0B,CACxC,MAAyB,EACzB,SAAoB,EACpB,QAAuB;IAEvB,OAAO,CACL,YAAY,CAAC,MAAM,EAAE,QAAQ,CAAC,KAAK,SAAS,CAAC,YAAY;QACzD,iBAAiB,CAAC,MAAM,CAAC,KAAK,SAAS,CAAC,gBAAgB;QACxD,iBAAiB,CAAC,MAAM,CAAC,KAAK,SAAS,CAAC,qBAAqB;QAC7D,uBAAuB,CAAC,MAAM,CAAC,KAAK,SAAS,CAAC,sBAAsB;QACpE,iCAAiC,CAAC,MAAM,EAAE,SAAS,CAAC,CACrD,CAAC;AACJ,CAAC;AAZD,gEAYC;AAED,SAAgB,iCAAiC,CAC/C,MAAgE,EAChE,SAAoB;;IAEpB,MAAM,sBAAsB,GAAG,iBAAiB,CAAC,MAAM,CAAC,CAAC;IACzD,MAAM,kBAAkB,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;IACjD,MAAM,qBAAqB,SAAG,SAAS,CAAC,uBAAuB,mCAAI,IAAI,CAAC;IACxE,MAAM,iBAAiB,SAAG,SAAS,CAAC,mBAAmB,mCAAI,IAAI,CAAC;IAEhE,OAAO,CACL,iBAAiB,KAAK,kBAAkB,IAAI,qBAAqB,KAAK,sBAAsB,CAC7F,CAAC;AACJ,CAAC;AAZD,8EAYC","sourcesContent":["import { ExpoConfig } from '@expo/config-types';\nimport * as path from 'path';\nimport resolveFrom from 'resolve-from';\nimport xcode from 'xcode';\n\nimport { ConfigPlugin } from '../Plugin.types';\nimport { withExpoPlist } from '../plugins/ios-plugins';\nimport { ExpoPlist } from './IosConfig.types';\n\nconst CREATE_MANIFEST_IOS_PATH = 'expo-updates/scripts/create-manifest-ios.sh';\n\ntype ExpoConfigUpdates = Pick<\n ExpoConfig,\n 'sdkVersion' | 'owner' | 'runtimeVersion' | 'updates' | 'slug'\n>;\n\nexport enum Config {\n ENABLED = 'EXUpdatesEnabled',\n CHECK_ON_LAUNCH = 'EXUpdatesCheckOnLaunch',\n LAUNCH_WAIT_MS = 'EXUpdatesLaunchWaitMs',\n RUNTIME_VERSION = 'EXUpdatesRuntimeVersion',\n SDK_VERSION = 'EXUpdatesSDKVersion',\n UPDATE_URL = 'EXUpdatesURL',\n RELEASE_CHANNEL = 'EXUpdatesReleaseChannel',\n}\n\nexport function getUpdateUrl(\n config: Pick<ExpoConfigUpdates, 'owner' | 'slug'>,\n username: string | null\n): string | null {\n const user = typeof config.owner === 'string' ? config.owner : username;\n if (!user) {\n return null;\n }\n return `https://exp.host/@${user}/${config.slug}`;\n}\n\nexport function getRuntimeVersion(\n config: Pick<ExpoConfigUpdates, 'runtimeVersion'>\n): string | null {\n return typeof config.runtimeVersion === 'string' ? config.runtimeVersion : null;\n}\n\nexport function getSDKVersion(config: Pick<ExpoConfigUpdates, 'sdkVersion'>): string | null {\n return typeof config.sdkVersion === 'string' ? config.sdkVersion : null;\n}\n\nexport function getUpdatesEnabled(config: Pick<ExpoConfigUpdates, 'updates'>): boolean {\n return config.updates?.enabled !== false;\n}\n\nexport function getUpdatesTimeout(config: Pick<ExpoConfigUpdates, 'updates'>) {\n return config.updates?.fallbackToCacheTimeout ?? 0;\n}\n\nexport function getUpdatesCheckOnLaunch(\n config: Pick<ExpoConfigUpdates, 'updates'>\n): 'NEVER' | 'ALWAYS' {\n if (config.updates?.checkAutomatically === 'ON_ERROR_RECOVERY') {\n return 'NEVER';\n } else if (config.updates?.checkAutomatically === 'ON_LOAD') {\n return 'ALWAYS';\n }\n return 'ALWAYS';\n}\n\nexport const withUpdates: ConfigPlugin<{ expoUsername: string | null }> = (\n config,\n { expoUsername }\n) => {\n return withExpoPlist(config, config => {\n config.modResults = setUpdatesConfig(config, config.modResults, expoUsername);\n return config;\n });\n};\n\nexport function setUpdatesConfig(\n config: ExpoConfigUpdates,\n expoPlist: ExpoPlist,\n username: string | null\n): ExpoPlist {\n const newExpoPlist = {\n ...expoPlist,\n [Config.ENABLED]: getUpdatesEnabled(config),\n [Config.CHECK_ON_LAUNCH]: getUpdatesCheckOnLaunch(config),\n [Config.LAUNCH_WAIT_MS]: getUpdatesTimeout(config),\n };\n\n const updateUrl = getUpdateUrl(config, username);\n if (updateUrl) {\n newExpoPlist[Config.UPDATE_URL] = updateUrl;\n } else {\n delete newExpoPlist[Config.UPDATE_URL];\n }\n\n return setVersionsConfig(config, newExpoPlist);\n}\n\nexport function setVersionsConfig(config: ExpoConfigUpdates, expoPlist: ExpoPlist): ExpoPlist {\n const newExpoPlist = { ...expoPlist };\n\n const runtimeVersion = getRuntimeVersion(config);\n const sdkVersion = getSDKVersion(config);\n if (runtimeVersion) {\n delete newExpoPlist[Config.SDK_VERSION];\n newExpoPlist[Config.RUNTIME_VERSION] = runtimeVersion;\n } else if (sdkVersion) {\n delete newExpoPlist[Config.RUNTIME_VERSION];\n newExpoPlist[Config.SDK_VERSION] = sdkVersion;\n } else {\n delete newExpoPlist[Config.SDK_VERSION];\n delete newExpoPlist[Config.RUNTIME_VERSION];\n }\n\n return newExpoPlist;\n}\n\nfunction formatConfigurationScriptPath(projectRoot: string): string {\n const buildScriptPath = resolveFrom.silent(projectRoot, CREATE_MANIFEST_IOS_PATH);\n\n if (!buildScriptPath) {\n throw new Error(\n \"Could not find the build script for iOS. This could happen in case of outdated 'node_modules'. Run 'npm install' to make sure that it's up-to-date.\"\n );\n }\n\n const relativePath = path.relative(path.join(projectRoot, 'ios'), buildScriptPath);\n return process.platform === 'win32' ? relativePath.replace(/\\\\/g, '/') : relativePath;\n}\n\ninterface ShellScriptBuildPhase {\n isa: 'PBXShellScriptBuildPhase';\n name: string;\n shellScript: string;\n [key: string]: any;\n}\n\nexport function getBundleReactNativePhase(project: xcode.XcodeProject): ShellScriptBuildPhase {\n const shellScriptBuildPhase = project.hash.project.objects.PBXShellScriptBuildPhase as Record<\n string,\n ShellScriptBuildPhase\n >;\n const bundleReactNative = Object.values(shellScriptBuildPhase).find(\n buildPhase => buildPhase.name === '\"Bundle React Native code and images\"'\n );\n\n if (!bundleReactNative) {\n throw new Error(`Couldn't find a build phase \"Bundle React Native code and images\"`);\n }\n\n return bundleReactNative;\n}\n\nexport function ensureBundleReactNativePhaseContainsConfigurationScript(\n projectRoot: string,\n project: xcode.XcodeProject\n): xcode.XcodeProject {\n const bundleReactNative = getBundleReactNativePhase(project);\n const buildPhaseShellScriptPath = formatConfigurationScriptPath(projectRoot);\n\n if (!isShellScriptBuildPhaseConfigured(projectRoot, project)) {\n // check if there's already another path to create-manifest-ios.sh\n // this might be the case for monorepos\n if (bundleReactNative.shellScript.includes(CREATE_MANIFEST_IOS_PATH)) {\n bundleReactNative.shellScript = bundleReactNative.shellScript.replace(\n new RegExp(`(\\\\\\\\n)(\\\\.\\\\.)+/node_modules/${CREATE_MANIFEST_IOS_PATH}`),\n ''\n );\n }\n bundleReactNative.shellScript = `${bundleReactNative.shellScript.replace(\n /\"$/,\n ''\n )}${buildPhaseShellScriptPath}\\\\n\"`;\n }\n return project;\n}\n\nexport function isShellScriptBuildPhaseConfigured(\n projectRoot: string,\n project: xcode.XcodeProject\n): boolean {\n const bundleReactNative = getBundleReactNativePhase(project);\n const buildPhaseShellScriptPath = formatConfigurationScriptPath(projectRoot);\n return bundleReactNative.shellScript.includes(buildPhaseShellScriptPath);\n}\n\nexport function isPlistConfigurationSet(expoPlist: ExpoPlist): boolean {\n return Boolean(\n expoPlist.EXUpdatesURL && (expoPlist.EXUpdatesSDKVersion || expoPlist.EXUpdatesRuntimeVersion)\n );\n}\n\nexport function isPlistConfigurationSynced(\n config: ExpoConfigUpdates,\n expoPlist: ExpoPlist,\n username: string | null\n): boolean {\n return (\n getUpdateUrl(config, username) === expoPlist.EXUpdatesURL &&\n getUpdatesEnabled(config) === expoPlist.EXUpdatesEnabled &&\n getUpdatesTimeout(config) === expoPlist.EXUpdatesLaunchWaitMs &&\n getUpdatesCheckOnLaunch(config) === expoPlist.EXUpdatesCheckOnLaunch &&\n isPlistVersionConfigurationSynced(config, expoPlist)\n );\n}\n\nexport function isPlistVersionConfigurationSynced(\n config: Pick<ExpoConfigUpdates, 'sdkVersion' | 'runtimeVersion'>,\n expoPlist: ExpoPlist\n): boolean {\n const expectedRuntimeVersion = getRuntimeVersion(config);\n const expectedSdkVersion = getSDKVersion(config);\n const currentRuntimeVersion = expoPlist.EXUpdatesRuntimeVersion ?? null;\n const currentSdkVersion = expoPlist.EXUpdatesSDKVersion ?? null;\n\n return (\n currentSdkVersion === expectedSdkVersion && currentRuntimeVersion === expectedRuntimeVersion\n );\n}\n"]} |