Skip to content

Commit e6cc533

Browse files
authored
fix(capacitor): detect iOS platform with Swift Package Manager (#1787)
1 parent e3d93b9 commit e6cc533

5 files changed

Lines changed: 64 additions & 1 deletion

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type { CapacitorConfig } from '@capacitor/cli';
2+
3+
const config: CapacitorConfig = {
4+
appId: 'com.company.name',
5+
appName: 'name',
6+
plugins: {},
7+
};
8+
9+
export default config;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// swift-tools-version: 5.9
2+
import PackageDescription
3+
4+
// DO NOT MODIFY THIS FILE - managed by Capacitor CLI commands
5+
let package = Package(
6+
name: "CapApp-SPM",
7+
platforms: [.iOS(.v14)],
8+
products: [
9+
.library(
10+
name: "CapApp-SPM",
11+
targets: ["CapApp-SPM"])
12+
],
13+
dependencies: [
14+
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", exact: "6.0.0")
15+
],
16+
targets: [
17+
.target(
18+
name: "CapApp-SPM",
19+
dependencies: [
20+
.product(name: "Capacitor", package: "capacitor-swift-pm"),
21+
.product(name: "Cordova", package: "capacitor-swift-pm")
22+
]
23+
)
24+
]
25+
)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "@plugins/capacitor-spm",
3+
"devDependencies": {
4+
"@capacitor/cli": "*"
5+
}
6+
}

packages/knip/src/plugins/capacitor/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ const config = ['capacitor.config.{json,ts}'];
1717
const resolveConfig: ResolveConfig<CapacitorConfig> = async (config, { configFileDir }) => {
1818
const plugins = config.includePlugins ?? [];
1919
const android = isFile(configFileDir, 'android/capacitor.settings.gradle') ? ['@capacitor/android'] : [];
20-
const ios = isFile(configFileDir, 'ios/App/Podfile') ? ['@capacitor/ios'] : [];
20+
const hasIOS = isFile(configFileDir, 'ios/App/Podfile') || isFile(configFileDir, 'ios/App/CapApp-SPM/Package.swift');
21+
const ios = hasIOS ? ['@capacitor/ios'] : [];
2122

2223
return [...plugins, ...android, ...ios].map(id => toDependency(id));
2324
};
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import assert from 'node:assert/strict';
2+
import test from 'node:test';
3+
import { main } from '../../src/index.ts';
4+
import baseCounters from '../helpers/baseCounters.ts';
5+
import { createOptions } from '../helpers/create-options.ts';
6+
import { resolve } from '../helpers/resolve.ts';
7+
8+
const cwd = resolve('fixtures/plugins/capacitor-spm');
9+
10+
test('Find dependencies with the Capacitor plugin (Swift Package Manager)', async () => {
11+
const options = await createOptions({ cwd });
12+
const { issues, counters } = await main(options);
13+
14+
assert(issues.unlisted['capacitor.config.ts']['@capacitor/ios']);
15+
16+
assert.deepEqual(counters, {
17+
...baseCounters,
18+
unlisted: 1,
19+
processed: 1,
20+
total: 1,
21+
});
22+
});

0 commit comments

Comments
 (0)