From 9048432755095ce3dcca9d3bab39894f2b6c3967 Mon Sep 17 00:00:00 2001 From: jcesarmobile Date: Tue, 12 Sep 2023 10:34:08 +0200 Subject: [PATCH] fix(cli): use helper in Podfile with correct path (#6888) Co-authored-by: Mike Summerfeldt <20338451+IT-MikeS@users.noreply.github.com> --- cli/src/ios/update.ts | 30 +++++++++++++++++++++--------- ios-template/App/Podfile | 13 +------------ 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/cli/src/ios/update.ts b/cli/src/ios/update.ts index d2c0d2b7c..a41c5a661 100644 --- a/cli/src/ios/update.ts +++ b/cli/src/ios/update.ts @@ -95,6 +95,7 @@ async function updatePodfile( deployment: boolean, ): Promise { const dependenciesContent = await generatePodFile(config, plugins); + const relativeCapacitoriOSPath = await getRelativeCapacitoriOSPath(config); const podfilePath = join(config.ios.nativeProjectDirAbs, 'Podfile'); let podfileContent = await readFile(podfilePath, { encoding: 'utf-8' }); podfileContent = podfileContent.replace( @@ -102,7 +103,10 @@ async function updatePodfile( `$1${dependenciesContent}$2`, ); podfileContent = podfileContent.replace( - `require_relative '../../node_modules/@capacitor/ios/scripts/pods_helpers'`, + /(require_relative)[\s\S]+?(@capacitor\/ios\/scripts\/pods_helpers')/, + `require_relative '${relativeCapacitoriOSPath}/scripts/pods_helpers'`, + ); + podfileContent = podfileContent.replace( `def assertDeploymentTarget(installer) installer.pods_project.targets.each do |target| target.build_configurations.each do |config| @@ -115,6 +119,7 @@ async function updatePodfile( end end end`, + `require_relative '${relativeCapacitoriOSPath}/scripts/pods_helpers'`, ); await writeFile(podfilePath, podfileContent, { encoding: 'utf-8' }); @@ -155,15 +160,13 @@ end`, } } -async function generatePodFile( - config: Config, - plugins: Plugin[], -): Promise { +async function getRelativeCapacitoriOSPath(config: Config) { const capacitoriOSPath = resolveNode( config.app.rootDir, '@capacitor/ios', 'package.json', ); + if (!capacitoriOSPath) { fatal( `Unable to find ${c.strong('node_modules/@capacitor/ios')}.\n` + @@ -171,10 +174,19 @@ async function generatePodFile( ); } - const podfilePath = config.ios.nativeProjectDirAbs; - const relativeCapacitoriOSPath = convertToUnixPath( - relative(podfilePath, await realpath(dirname(capacitoriOSPath))), + return convertToUnixPath( + relative( + config.ios.nativeProjectDirAbs, + await realpath(dirname(capacitoriOSPath)), + ), ); +} + +async function generatePodFile( + config: Config, + plugins: Plugin[], +): Promise { + const relativeCapacitoriOSPath = await getRelativeCapacitoriOSPath(config); const capacitorPlugins = plugins.filter( p => getPluginType(p, platform) === PluginType.Core, @@ -186,7 +198,7 @@ async function generatePodFile( } return ` pod '${p.ios.name}', :path => '${convertToUnixPath( - relative(podfilePath, await realpath(p.rootPath)), + relative(config.ios.nativeProjectDirAbs, await realpath(p.rootPath)), )}'\n`; }), ); diff --git a/ios-template/App/Podfile b/ios-template/App/Podfile index 73bd027ca..affb695cb 100644 --- a/ios-template/App/Podfile +++ b/ios-template/App/Podfile @@ -1,15 +1,4 @@ -def assertDeploymentTarget(installer) - installer.pods_project.targets.each do |target| - target.build_configurations.each do |config| - # ensure IPHONEOS_DEPLOYMENT_TARGET is at least 13.0 - deployment_target = config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'].to_f - should_upgrade = deployment_target < 13.0 && deployment_target != 0.0 - if should_upgrade - config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '13.0' - end - end - end -end +require_relative '../../node_modules/@capacitor/ios/scripts/pods_helpers' platform :ios, '13.0' use_frameworks!