Capacitor Plugin Spm Support

Cap-go/capgo-skills/plugins/capacitor-plugin-dev/skills/capacitor-plugin-spm-support

作者 Cap-go2cfb277a148832bdb1a835b01e4de323687b498b無授權條款72 個星標收錄於 2026年10月9日更新於 2026年10月9日儲存庫昨天更新

Guides the agent through adding Swift Package Manager support to an existing Capacitor plugin. Covers Package.swift, CAPBridgedPlugin conversion, bridge cleanup, and package manifest updates. Do not use for app projects or non-Capacitor plugin frameworks.

AI 產生的概覽

指導為現有 Capacitor 外掛加入 Swift Package Manager 支援,包含 Package.swift 與橋接 Swift 註冊。

功能
此技能引導代理將現有的 Capacitor iOS 外掛從 CocoaPods 轉換為 Swift Package Manager。內容涵蓋蒐集外掛資訊、建立 Package.swift 清單、將外掛類別改為遵循 CAPBridgedPlugin、移除 Objective-C 橋接檔案,以及更新套件中繼資料。它也說明透過同步並建置範例應用程式來驗證的步驟。
適用情境
當希望 Capacitor 外掛透過 Xcode 的套件管理器而非 CocoaPods 被使用時適用。適合從 Objective-C 橋接檔案轉換為橋接 Swift 註冊的外掛,或需要為 SPM 更新套件清單與檔案匯出的外掛。不適用於應用程式專案或非 Capacitor 的外掛框架。
執行需求
僅為說明性內容,未附帶指令碼。假定已有 Capacitor 外掛儲存庫,包含 package.json、podspec、iOS Swift 原始碼,以及帶 capacitor.config 檔案的範例或測試應用程式,並需要 Node/npm 工具鏈與 Xcode 進行建置。

Add Swift Package Manager Support to a Capacitor Plugin

Add SPM support to an existing Capacitor plugin so it can be consumed without CocoaPods.

When to Use This Skill

  • User wants a plugin to work through Xcode's package manager
  • User is converting an existing iOS plugin from Obj-C bridge files to bridged Swift registration
  • User needs the plugin package manifest and file exports updated for SPM

Procedures

Step 1: Gather Plugin Information

Read these files in the plugin root:

  • package.json
  • the .podspec
  • the main Swift plugin class under ios/

Record:

  • the package name
  • the pod name
  • the iOS deployment target
  • the plugin class name
  • the JavaScript plugin name
  • all exposed plugin methods
  • any third-party CocoaPods dependencies that also need SPM equivalents

Step 2: Create Package.swift

Add a Package.swift manifest that:

  • declares the plugin package name
  • sets the iOS minimum version
  • points the target at the plugin's iOS source directory
  • depends on the Capacitor Swift package support package used by the project
  • adds any resolved third-party SPM packages

Keep the target structure aligned with the actual plugin source tree.

Step 3: Convert the Swift Plugin Class

Update the plugin class to conform to CAPBridgedPlugin.

Add the bridge properties at the top of the class:

  • identifier
  • jsName
  • pluginMethods

Preserve each method name and return type exactly as the plugin already exposes them.

Step 4: Remove Objective-C Bridge Files

Delete the old bridge header and implementation files once the Swift bridge is in place.

Then clean the Xcode project file so it no longer references them.

Step 5: Update Package Metadata

Update the plugin package manifest so it exports:

  • the iOS sources
  • the podspec
  • Package.swift

Add an iOS SPM install command if the project maintains script helpers.

Step 6: Verify

Install dependencies with the repository's existing package manager.

Then cd into the example or test app directory that contains capacitor.config.*, run npx cap sync (or the repository's equivalent runner) there, and build that same app.

Error Handling

  • Start with the Swift package resolver: check the target path and package dependency names first.
  • Verify bridge registration by matching the class name, identifier, and jsName against the exported API.
  • For unsupported CocoaPods dependencies, replace them with SPM-compatible packages or keep CocoaPods for that dependency.

來源與署名

來源:Cap-go/capgo-skills位於plugins/capacitor-plugin-dev/skills/capacitor-plugin-spm-support提交2cfb277

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架