Skip to content
Draft
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
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ cli/assets
dist
types
android/capacitor/src/main/assets/native-bridge.js
ios/Capacitor/Capacitor/assets/native-bridge.js
ios/Sources/Capacitor/assets/native-bridge.js
ios/Frameworks/Capacitor.xcframework/ios-arm64_x86_64-simulator/Capacitor.framework/native-bridge.js
ios/Frameworks/Capacitor.xcframework/ios-arm64/Capacitor.framework/native-bridge.js
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ jobs:
- run: npm test
working-directory: ./core
test-ios:
runs-on: macos-15
runs-on: macos-26
timeout-minutes: 30
needs:
- setup
- lint
strategy:
matrix:
xcode:
- /Applications/Xcode_26.0.app
- /Applications/Xcode_26.6.app
steps:
- run: sudo xcode-select --switch ${{ matrix.xcode }}
- run: xcrun simctl list > /dev/null
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Pods/
Podfile.lock
Build/*
build/
.build/
Index/
.*.sw*
android-template.iml
Expand Down
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ core/types
cli/assets
dist
android/capacitor/src/main/assets/native-bridge.js
ios/Capacitor/Capacitor/assets/native-bridge.js
ios/Sources/Capacitor/assets/native-bridge.js
ios/Frameworks/Capacitor.xcframework/ios-arm64_x86_64-simulator/Capacitor.framework/native-bridge.js
ios/Frameworks/Capacitor.xcframework/ios-arm64/Capacitor.framework/native-bridge.js
89 changes: 89 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// swift-tools-version: 6.0
import PackageDescription

let package = Package(
name: "Capacitor",
platforms: [.iOS(.v16)],
products: [
.library(
name: "Capacitor",
targets: ["Capacitor", "CapacitorObjC", "CapacitorObjCShims"]
),
.library(
name: "Cordova",
targets: ["Cordova"]
),
.library(
name: "CapacitorCordova",
targets: ["Cordova", "CapacitorCordova"]
)
],
targets: [
.target(
name: "CapacitorObjC",
path: "ios/Sources/CapacitorObjC",
publicHeadersPath: "include",
cSettings: [
.headerSearchPath("include"),
.headerSearchPath("include/Capacitor")
]
),
.target(
name: "Capacitor",
dependencies: ["CapacitorObjC"],
path: "ios/Sources/Capacitor",
resources: [
.copy("assets"),
.copy("PrivacyInfo.xcprivacy")
],
swiftSettings: [.swiftLanguageMode(.v5)]
),
.target(
name: "CapacitorObjCShims",
dependencies: ["Capacitor"],
path: "ios/Sources/CapacitorObjCShims",
exclude: ["Capacitor.modulemap"],
publicHeadersPath: "include",
cSettings: [
.headerSearchPath("include"),
.headerSearchPath("include/Capacitor")
]
),
.target(
name: "Cordova",
path: "ios/Sources/Cordova",
exclude: ["CapacitorCordova.modulemap"],
resources: [.copy("PrivacyInfo.xcprivacy")],
publicHeadersPath: "include",
cSettings: [
.headerSearchPath("include"),
.headerSearchPath("include/Cordova")
],
linkerSettings: [
.linkedFramework("UIKit"),
.linkedFramework("WebKit"),
.linkedFramework("MobileCoreServices"),
.linkedFramework("CFNetwork")
]
),
.target(
name: "CapacitorCordova",
dependencies: ["Capacitor", "Cordova"],
path: "ios/Sources/CapacitorCordova",
swiftSettings: [.swiftLanguageMode(.v5)]
),
.testTarget(
name: "CapacitorTests",
dependencies: ["Capacitor"],
path: "ios/Tests/CapacitorTests",
resources: [.copy("Resources/configurations")],
swiftSettings: [.swiftLanguageMode(.v5)]
),
.testTarget(
name: "CapacitorObjCTests",
dependencies: ["CapacitorObjCShims"],
path: "ios/Tests/CapacitorObjCTests"
)
],
swiftLanguageModes: [.v5]
)
46 changes: 46 additions & 0 deletions cli/src/declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,52 @@ export interface CapacitorConfig {
* @since 8.4.0
*/
packageOptions?: { [pluginId: string]: PackageOptions };

/**
* Override which Capacitor Swift package the generated `Package.swift` depends on.
*
* By default the generated package pins the git tag matching the installed
* `@capacitor/ios` version, which is correct for both stable and pre-release versions
* and matches what CocoaPods resolves.
*
* Set this only when developing against an unreleased Capacitor, such as a local
* checkout or a feature branch. Exactly one of `path`, `branch`, `revision`, `exact`,
* or `from` must be set. `path` points at the repository root (the directory containing
* `Package.swift`) and may be relative to the app.
*
* The `CAPACITOR_IOS_PACKAGE` environment variable takes precedence over this setting,
* so a checkout can be redirected without editing committed configuration.
*
* Note that `branch` and `revision` builds are not reproducible and decouple the native
* code from the `@capacitor/core` JavaScript bridge it is versioned against.
*
* @since 9.0.0
* @example { "path": "../capacitor" }
* @example { "branch": "next" }
*/
capacitorPackage?: {
/**
* Repository to fetch from. Ignored when `path` is set.
*
* @default 'https://github.com/ionic-team/capacitor'
*/
url?: string;

/** Path to a local Capacitor repository root. */
path?: string;

/** Branch to track. */
branch?: string;

/** Exact commit to pin. */
revision?: string;

/** Exact version tag to pin. */
exact?: string;

/** Minimum version tag, allowing compatible upgrades. */
from?: string;
};
};
};
};
Expand Down
31 changes: 24 additions & 7 deletions cli/src/ios/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ import type { Plugin } from '../plugin';
import { PluginType, getPluginType, getPlugins, printPlugins } from '../plugin';
import { copy as copyTask } from '../tasks/copy';
import { setAllStringIn } from '../tasks/migrate';
import {
findCapacitorDependencyVersion,
resolveCapacitorPackage,
rewriteCapacitorDependency,
} from '../util/capacitor-package';
import {
generateCordovaPodspecs,
generateCordovaPackageFiles,
Expand Down Expand Up @@ -65,16 +70,29 @@ async function updatePluginFiles(config: Config, plugins: Plugin[], deployment:
}

const validSPMPackages = await checkPluginsForPackageSwift(config, plugins);
const iosPlatformVersion = await getCapacitorPackageVersion(config, config.ios.name);
const majorCapVersion = major(iosPlatformVersion);
const capacitorPackage = await resolveCapacitorPackage(config, 'from');
await Promise.all(
validSPMPackages.map(async (plugin) => {
const iosPlatformVersion = await getCapacitorPackageVersion(config, config.ios.name);
const packageSwiftPath = join(plugin.rootPath, 'Package.swift');
let content = await readFile(packageSwiftPath, { encoding: 'utf-8' });
const regex = new RegExp(
'url:\\s*"https://github.com/ionic-team/capacitor-swift-pm\\.git",\\s*from:\\s*"([^"]+)"',
);
const version = content.match(regex)?.[1];
const majorCapVersion = major(iosPlatformVersion);
const version = findCapacitorDependencyVersion(content);

if (version && major(version) != majorCapVersion) {
logger.warn(`${plugin.id} is built for Capacitor ${major(version)}, it might cause issues`);
}

if (capacitorPackage.sourceBased) {
// The plugin has to resolve to the same package identity as the app, or SPM ends up with
// two packages that both vend a Capacitor product.
const rewritten = rewriteCapacitorDependency(content, capacitorPackage, plugin.rootPath);
if (rewritten !== content) {
await writeFile(packageSwiftPath, rewritten);
}
return;
}

if (version && major(version) != majorCapVersion) {
const preCapVersion = prerelease(iosPlatformVersion);
const forceVersion = preCapVersion ? iosPlatformVersion : `${majorCapVersion}.0.0`;
Expand All @@ -85,7 +103,6 @@ async function updatePluginFiles(config: Config, plugins: Plugin[], deployment:
` from: "${forceVersion}"`,
);
await writeFile(packageSwiftPath, content);
logger.warn(`${plugin.id} is built for Capacitor ${major(version)}, it might cause issues`);
}
}),
);
Expand Down
Loading
Loading