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
4 changes: 4 additions & 0 deletions cli/src/ios/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ async function generateCordovaPackageFile(p: Plugin, config: Config) {
);
await writeFile(packageSwiftPath, content);
} else {
const sourceFiles = getPlatformElement(p, platform, 'source-file');
if (sourceFiles.length === 0 && headerFiles.length === 0) {
return;
}
const content = `// swift-tools-version: 5.9

import PackageDescription
Expand Down
2 changes: 1 addition & 1 deletion cli/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export function getPluginPlatform(p: Plugin, platform: string): any {
});
return platforms[0];
}
return [];
return undefined;
}

export function getPlatformElement(p: Plugin, platform: string, elementName: string): any {
Expand Down
20 changes: 16 additions & 4 deletions cli/src/util/spm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { fatal } from '../errors';
import { getMajoriOSVersion } from '../ios/common';
import { logger } from '../log';
import type { Plugin } from '../plugin';
import { getPluginPlatform, getPluginType, PluginType } from '../plugin';
import { getPlatformElement, getPluginPlatform, getPluginType, PluginType } from '../plugin';
import { runCommand } from '../util/subprocess';

export interface SwiftPlugin {
Expand Down Expand Up @@ -124,6 +124,11 @@ let package = Package(
const relPath = relative(config.ios.nativeXcodeProjDirAbs, plugin.rootPath);
packageSwiftText += `,\n .package(name: "${plugin.id}", path: "${relPath}")`;
} else {
const sourceFiles = getPlatformElement(plugin, config.ios.name, 'source-file');
const headerFiles = getPlatformElement(plugin, config.ios.name, 'header-file');
if (sourceFiles.length === 0 && headerFiles.length === 0) {
continue;
}
packageSwiftText += `,\n .package(name: "${plugin.name}", path: "../../capacitor-cordova-ios-plugins/sources/${plugin.name}")`;
}
} else {
Expand Down Expand Up @@ -151,14 +156,21 @@ let package = Package(
.product(name: "Cordova", package: "capacitor-swift-pm")`;

for (const plugin of plugins) {
let pluginText = `,\n .product(name: "${plugin.ios?.name}", package: "${plugin.ios?.name}")`;
if (getPluginType(plugin, config.ios.name) === PluginType.Cordova) {
const platformTag = getPluginPlatform(plugin, config.ios.name);
if (platformTag.$?.package) {
pluginText = `,\n .product(name: "${plugin.id}", package: "${plugin.id}")`;
packageSwiftText += `,\n .product(name: "${plugin.id}", package: "${plugin.id}")`;
} else {
const sourceFiles = getPlatformElement(plugin, config.ios.name, 'source-file');
const headerFiles = getPlatformElement(plugin, config.ios.name, 'header-file');
if (sourceFiles.length === 0 && headerFiles.length === 0) {
continue;
}
packageSwiftText += `,\n .product(name: "${plugin.ios?.name}", package: "${plugin.ios?.name}")`;
}
} else {
packageSwiftText += `,\n .product(name: "${plugin.ios?.name}", package: "${plugin.ios?.name}")`;
}
packageSwiftText += pluginText;
}

packageSwiftText += `
Expand Down
Loading