From edcaa7a1fa6b8235f1c854bf75ddbdf3214bc54a Mon Sep 17 00:00:00 2001 From: Hirbod Mirjavadi Date: Sun, 2 Apr 2023 14:16:41 +0200 Subject: [PATCH] fix: XCode 14.3 temp issues with config plugin --- apps/expo/app.config.js | 1 + apps/expo/plugins/fix-deployment-target.js | 42 ++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 apps/expo/plugins/fix-deployment-target.js diff --git a/apps/expo/app.config.js b/apps/expo/app.config.js index e557dec971..c757f39309 100644 --- a/apps/expo/app.config.js +++ b/apps/expo/app.config.js @@ -160,6 +160,7 @@ export default { "./plugins/react-native-cronet.js", "./plugins/with-spotify-sdk.js", "./plugins/with-android-splash-screen.js", + "./plugins/fix-deployment-target.js", [ withInfoPlist, (config) => { diff --git a/apps/expo/plugins/fix-deployment-target.js b/apps/expo/plugins/fix-deployment-target.js new file mode 100644 index 0000000000..6300281346 --- /dev/null +++ b/apps/expo/plugins/fix-deployment-target.js @@ -0,0 +1,42 @@ +// Credit: https://github.com/facebook/react-native/issues/34106#issuecomment-1493040686 +// This plugin is used to fix the deployment target issue in iOS +const { withDangerousMod, withPlugins } = require("@expo/config-plugins"); +const { + mergeContents, +} = require("@expo/config-plugins/build/utils/generateCode"); +const { readFileSync, writeFileSync } = require("fs"); +const { resolve } = require("path"); + +const withFixedDeploymentTarget = (c) => { + return withDangerousMod(c, [ + "ios", + async (config) => { + const file = resolve(config.modRequest.platformProjectRoot, "Podfile"); + const contents = readFileSync(file, { encoding: "utf-8" }); + writeFileSync(file, fixDeploymentTarget(contents)); + return config; + }, + ]); +}; + +function fixDeploymentTarget(src) { + return mergeContents({ + tag: `rn-fix-deployment-target`, + src, + newSrc: ` + installer.pods_project.targets.each do |target| + if target.to_s === 'React-Codegen' + target.build_configurations.each do |config| + config.build_settings['SWIFT_VERSION'] = '5.0' + config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '13.0' + end + end + end +`, + anchor: /post_install/, + offset: 1, + comment: "#", + }).contents; +} + +module.exports = (config) => withPlugins(config, [withFixedDeploymentTarget]);