Skip to content

Commit

Permalink
fix: use Capacitor 7 for SPM dependency (#7835)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile authored Jan 21, 2025
1 parent 5dc309e commit 640c3cb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions cli/src/util/spm.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { existsSync, readFileSync, writeFileSync } from 'fs-extra';
import { join, relative, resolve } from 'path';

import { getCapacitorPackageVersion } from '../common';
import type { Config } from '../definitions';
import { logger } from '../log';
import type { Plugin } from '../plugin';
Expand Down Expand Up @@ -28,14 +29,16 @@ export async function generatePackageFile(config: Config, plugins: Plugin[]): Pr
const packageSwiftFile = await findPackageSwiftFile(config);
try {
logger.warn('SPM Support is still experimental');
const textToWrite = generatePackageText(config, plugins);
const textToWrite = await generatePackageText(config, plugins);
writeFileSync(packageSwiftFile, textToWrite);
} catch (err) {
logger.error(`Unable to write to ${packageSwiftFile}. Verify it is not already open. \n Error: ${err}`);
}
}

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

const pbx = readFileSync(join(config.ios.nativeXcodeProjDirAbs, 'project.pbxproj'), 'utf-8');
const searchString = 'IPHONEOS_DEPLOYMENT_TARGET = ';
const iosVersion = pbx.substring(
Expand All @@ -56,7 +59,7 @@ let package = Package(
targets: ["CapApp-SPM"])
],
dependencies: [
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", branch: "main")`;
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", exact: "${iosPlatformVersion}")`;

for (const plugin of plugins) {
const relPath = relative(config.ios.nativeXcodeProjDirAbs, plugin.rootPath);
Expand Down
2 changes: 1 addition & 1 deletion ios-spm-template/App/CapApp-SPM/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ let package = Package(
targets: ["CapApp-SPM"])
],
dependencies: [
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", branch: "main")
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "7.0.0")
],
targets: [
.target(
Expand Down

0 comments on commit 640c3cb

Please sign in to comment.