Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions cli/src/ios/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,30 @@ export function getMajoriOSVersion(config: Config): string {
);
return iosVersion;
}

export function getMajorMinoriOSVersion(config: Config): string {
const pbx = readFileSync(join(config.ios.nativeXcodeProjDirAbs, 'project.pbxproj'), 'utf-8');
const searchString = 'IPHONEOS_DEPLOYMENT_TARGET = ';
const startIndex = pbx.indexOf(searchString);
if (startIndex === -1) {
return '';
}
const valueStart = startIndex + searchString.length;
// Extract until semicolon or newline (typical end of value in pbxproj)
const endIndex = pbx.indexOf(';', valueStart);
const newlineIndex = pbx.indexOf('\n', valueStart);
const actualEnd =
endIndex !== -1 && newlineIndex !== -1
? Math.min(endIndex, newlineIndex)
: endIndex !== -1
? endIndex
: newlineIndex !== -1
? newlineIndex
: pbx.length;
let iosVersion = pbx.substring(valueStart, actualEnd).trim();
// Remove trailing .0 if present
if (iosVersion.endsWith('.0')) {
iosVersion = iosVersion.slice(0, -2);
}
return iosVersion;
}
6 changes: 3 additions & 3 deletions cli/src/util/spm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { extract } from 'tar';
import { getCapacitorPackageVersion } from '../common';
import type { Config } from '../definitions';
import { fatal } from '../errors';
import { getMajoriOSVersion } from '../ios/common';
import { getMajorMinoriOSVersion } from '../ios/common';
import { logger } from '../log';
import type { Plugin } from '../plugin';
import { getPluginType, PluginType } from '../plugin';
Expand Down Expand Up @@ -92,15 +92,15 @@ export async function removeCocoapodsFiles(config: Config): Promise<void> {

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

let packageSwiftText = `// swift-tools-version: 5.9
import PackageDescription

// DO NOT MODIFY THIS FILE - managed by Capacitor CLI commands
let package = Package(
name: "CapApp-SPM",
platforms: [.iOS(.v${iosVersion})],
platforms: [.iOS(${iosVersion.includes('.') ? `"${iosVersion}"` : `.v${iosVersion}`})],
products: [
.library(
name: "CapApp-SPM",
Expand Down