Skip to content

Commit cf46c63

Browse files
authored
Merge pull request #38 from Cap-go/spm_correct_platforms
fix: SPM correct platform for iOS
2 parents 516c30b + e78f602 commit cf46c63

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

cli/src/ios/common.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,29 @@ export function getMajoriOSVersion(config: Config): string {
113113
);
114114
return iosVersion;
115115
}
116+
117+
export function getMajorMinoriOSVersion(config: Config): string {
118+
const pbx = readFileSync(join(config.ios.nativeXcodeProjDirAbs, 'project.pbxproj'), 'utf-8');
119+
const searchString = 'IPHONEOS_DEPLOYMENT_TARGET = ';
120+
const startIndex = pbx.indexOf(searchString);
121+
if (startIndex === -1) {
122+
return '';
123+
}
124+
const valueStart = startIndex + searchString.length;
125+
// Extract until semicolon or newline (typical end of value in pbxproj)
126+
const endIndex = pbx.indexOf(';', valueStart);
127+
const newlineIndex = pbx.indexOf('\n', valueStart);
128+
const actualEnd = endIndex !== -1 && newlineIndex !== -1
129+
? Math.min(endIndex, newlineIndex)
130+
: endIndex !== -1
131+
? endIndex
132+
: newlineIndex !== -1
133+
? newlineIndex
134+
: pbx.length;
135+
let iosVersion = pbx.substring(valueStart, actualEnd).trim();
136+
// Remove trailing .0 if present
137+
if (iosVersion.endsWith('.0')) {
138+
iosVersion = iosVersion.slice(0, -2);
139+
}
140+
return iosVersion;
141+
}

cli/src/util/spm.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { extract } from 'tar';
88
import { getCapacitorPackageVersion } from '../common';
99
import type { Config } from '../definitions';
1010
import { fatal } from '../errors';
11-
import { getMajoriOSVersion } from '../ios/common';
11+
import { getMajorMinoriOSVersion } from '../ios/common';
1212
import { logger } from '../log';
1313
import type { Plugin } from '../plugin';
1414
import { getPluginType, PluginType } from '../plugin';
@@ -92,15 +92,15 @@ export async function removeCocoapodsFiles(config: Config): Promise<void> {
9292

9393
export async function generatePackageText(config: Config, plugins: Plugin[]): Promise<string> {
9494
const iosPlatformVersion = await getCapacitorPackageVersion(config, config.ios.name);
95-
const iosVersion = getMajoriOSVersion(config);
95+
const iosVersion = getMajorMinoriOSVersion(config);
9696

9797
let packageSwiftText = `// swift-tools-version: 5.9
9898
import PackageDescription
9999
100100
// DO NOT MODIFY THIS FILE - managed by Capacitor CLI commands
101101
let package = Package(
102102
name: "CapApp-SPM",
103-
platforms: [.iOS(.v${iosVersion})],
103+
platforms: [.iOS(${iosVersion.includes('.') ? `"${iosVersion}"` : `.v${iosVersion}`})],
104104
products: [
105105
.library(
106106
name: "CapApp-SPM",

0 commit comments

Comments
 (0)