11import { existsSync , readFileSync , writeFileSync } from 'fs-extra' ;
22import { join , relative , resolve } from 'path' ;
33
4+ import { getCapacitorPackageVersion } from '../common' ;
45import type { Config } from '../definitions' ;
56import { logger } from '../log' ;
67import type { Plugin } from '../plugin' ;
@@ -28,14 +29,16 @@ export async function generatePackageFile(config: Config, plugins: Plugin[]): Pr
2829 const packageSwiftFile = await findPackageSwiftFile ( config ) ;
2930 try {
3031 logger . warn ( 'SPM Support is still experimental' ) ;
31- const textToWrite = generatePackageText ( config , plugins ) ;
32+ const textToWrite = await generatePackageText ( config , plugins ) ;
3233 writeFileSync ( packageSwiftFile , textToWrite ) ;
3334 } catch ( err ) {
3435 logger . error ( `Unable to write to ${ packageSwiftFile } . Verify it is not already open. \n Error: ${ err } ` ) ;
3536 }
3637}
3738
38- function generatePackageText ( config : Config , plugins : Plugin [ ] ) : string {
39+ async function generatePackageText ( config : Config , plugins : Plugin [ ] ) : Promise < string > {
40+ const iosPlatformVersion = await getCapacitorPackageVersion ( config , config . ios . name ) ;
41+
3942 const pbx = readFileSync ( join ( config . ios . nativeXcodeProjDirAbs , 'project.pbxproj' ) , 'utf-8' ) ;
4043 const searchString = 'IPHONEOS_DEPLOYMENT_TARGET = ' ;
4144 const iosVersion = pbx . substring (
@@ -56,7 +59,7 @@ let package = Package(
5659 targets: ["CapApp-SPM"])
5760 ],
5861 dependencies: [
59- .package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", branch : "main ")` ;
62+ .package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", exact : "${ iosPlatformVersion } ")` ;
6063
6164 for ( const plugin of plugins ) {
6265 const relPath = relative ( config . ios . nativeXcodeProjDirAbs , plugin . rootPath ) ;
0 commit comments