{"slug":"capacitor-plugin-spm-support","title":"capacitor-plugin-spm-support","summary":"Adds Swift Package Manager support to an existing Capacitor plugin repository so apps using CapApp-SPM can consume it after CocoaPods Trunk goes read-only (expected December 2, 2026). Covers root Package.swift naming rules the Capacitor CLI depends on, CAPBridgedPlugin conversion","platform":"Claude","tags":[],"authorName":"LLM Mart","authorSlug":"llm-mart","score":0,"source":"github","price":null,"verified":false,"createdAt":"2026-12-05T18:17:18.523986Z","repo":{"url":"https://github.com/Cap-go/capgo-skills","stars":79,"forks":4,"license":"MIT","updatedAt":"2026-12-05T16:44:30Z"},"bodyHtml":"<hr>\n<h2>name: capacitor-plugin-spm-support\ndescription: Adds Swift Package Manager support to an existing Capacitor plugin repository so apps using CapApp-SPM can consume it after CocoaPods Trunk goes read-only (expected December 2, 2026). Covers root Package.swift naming rules the Capacitor CLI depends on, CAPBridgedPlugin conversion (identifier, jsName, pluginMethods), removing the ObjC CAP_PLUGIN bridge (.m/.h), Sources/Tests layout, podspec and package.json files updates, third-party pod to SPM dependency mapping, resources/PrivacyInfo.xcprivacy, binary xcframeworks, and Capacitor 9 removal of the unconditional Cordova product. Use when app sync warns \"</h2>\n<h1>Add Swift Package Manager Support to a Capacitor Plugin</h1>\n<p>Make a plugin installable in SPM-based Capacitor apps while keeping its podspec for CocoaPods apps.</p>\n<h2>When to Use</h2>\n<p>TRIGGER when:</p>\n<ul>\n<li>A plugin repo has <code>ios/Plugin/*.swift</code> + <code>*.m</code>/<code>*.h</code> with <code>CAP_PLUGIN(...)</code> and no root <code>Package.swift</code>.</li>\n<li>An app's <code>npx cap sync ios</code> prints <code>&lt;plugin id&gt; does not have a Package.swift</code> for a plugin the user maintains.</li>\n<li>A plugin works with CocoaPods but JS gets <code>\"X\" plugin is not implemented on ios</code> in SPM apps.</li>\n<li>Preparing a plugin for Capacitor 9 / CocoaPods Trunk read-only.</li>\n</ul>\n<p>Do not use:</p>\n<ul>\n<li>App-side CocoaPods removal -&gt; <code>cocoapods-to-spm</code>.</li>\n<li>Capacitor major bumps of a plugin -&gt; <code>capacitor-plugin-upgrades</code>, <code>capacitor-plugin-upgrade-v8-to-v9</code>.</li>\n<li>Android-only plugin work, or non-Capacitor (pure Cordova, React Native) plugins.</li>\n</ul>\n<h2>Rules the CLI Enforces (non-obvious)</h2>\n<ul>\n<li><code>Package.swift</code> must be at the <strong>npm package root</strong> (next to <code>package.json</code>), not under <code>ios/</code>. The app CLI only checks <code>&lt;plugin root&gt;/Package.swift</code>.</li>\n<li>The CLI references the plugin in the app's <code>CapApp-SPM/Package.swift</code> as <code>.package(name: \"&lt;Name&gt;\", path: ...)</code> and <code>.product(name: \"&lt;Name&gt;\", package: \"&lt;Name&gt;\")</code>, where <code>&lt;Name&gt;</code> is derived from the npm name: drop <code>@</code>, turn <code>/</code> and <code>-</code> into word breaks, PascalCase. <code>@capgo/capacitor-updater</code> -&gt; <code>CapgoCapacitorUpdater</code>, <code>@acme/capacitor-foo-bar</code> -&gt; <code>AcmeCapacitorFooBar</code>. The <code>Package(name:)</code> <strong>and</strong> the <code>.library(name:)</code> product must both equal <code>&lt;Name&gt;</code>, or app builds fail to resolve the product.</li>\n<li>Runtime registration uses <code>ios/App/App/capacitor.config.json</code> -&gt; <code>packageClassList</code>, filled by scanning the plugin's iOS sources (<code>capacitor.ios.src</code> in package.json, default <code>ios</code>) for <code>@objc(ClassName)</code>. Keep <code>@objc(&lt;Class&gt;Plugin)</code> on the class; without it the plugin is never registered.</li>\n<li>The <code>capacitor-swift-pm</code> dependency must use <code>from: \"&lt;major&gt;.0.0\"</code>. If the major differs from the app's Capacitor, app sync rewrites it in <code>node_modules</code> and warns <code>&lt;id&gt; is built for Capacitor &lt;N&gt;, it might cause issues</code>.</li>\n<li>Capacitor 9: depend only on <code>.product(name: \"Capacitor\", package: \"capacitor-swift-pm\")</code>. Remove the unconditional <code>Cordova</code> product; it is only present in apps that install a Cordova plugin. Keep it on Capacitor 8 only if your code imports Cordova.</li>\n</ul>\n<h2>Procedure</h2>\n<h3>1. Inspect</h3>\n<p>Read <code>package.json</code> (name, <code>files</code>, <code>capacitor.ios.src</code>, scripts), the <code>.podspec</code> (<code>s.name</code>, <code>s.ios.deployment_target</code>, <code>s.dependency</code>, <code>s.resources</code>, <code>s.vendored_frameworks</code>), every file in <code>ios/</code>, and the <code>CAP_PLUGIN(...)</code> macro in the <code>.m</code> file.</p>\n<p>Record: SPM <code>&lt;Name&gt;</code> (rule above), class name, <code>jsName</code>, every <code>CAP_PLUGIN_METHOD(name, returnType)</code>, iOS deployment target, third-party pods, resources, vendored frameworks, ObjC/C sources other than the bridge.</p>\n<p>Check each third-party pod has an official SPM package. Report any that do not before editing; ask whether to drop, vendor as <code>.xcframework</code>, or keep the plugin CocoaPods-only.</p>\n<h3>2. Fast path: converter</h3>\n<p>If the iOS code is Swift-only apart from the <code>[Name]Plugin.m</code> / <code>.h</code> bridge, the official converter does most of the work (adds <code>CAPBridgedPlugin</code>, creates <code>Package.swift</code>, moves code to <code>ios/Sources</code> and <code>ios/Tests</code>, removes <code>Plugin.xcodeproj</code>/<code>xcworkspace</code>/<code>Podfile</code>, updates podspec <code>source_files</code>, <code>files</code>, and <code>verify:ios</code>): <a href=\"https://github.com/ionic-team/capacitor-plugin-converter\">https://github.com/ionic-team/capacitor-plugin-converter</a>. Review its diff against the rules above, especially the package/product name.</p>\n<h3>3. Manual conversion</h3>\n<ol>\n<li>Move sources: <code>ios/Plugin/</code> -&gt; <code>ios/Sources/&lt;ClassName&gt;/</code>, tests -&gt; <code>ios/Tests/&lt;ClassName&gt;Tests/</code>.</li>\n<li>Convert the class (keep method names and return types exactly as in the <code>.m</code> macro):\n<pre><code>import Capacitor\n\n@objc(FooPlugin)\npublic class FooPlugin: CAPPlugin, CAPBridgedPlugin {\n    public let identifier = \"FooPlugin\"     // first CAP_PLUGIN argument\n    public let jsName = \"Foo\"               // second CAP_PLUGIN argument (registerPlugin name)\n    public let pluginMethods: [CAPPluginMethod] = [\n        CAPPluginMethod(name: \"doThing\", returnType: CAPPluginReturnPromise),\n        CAPPluginMethod(name: \"watch\", returnType: CAPPluginReturnCallback),\n        CAPPluginMethod(name: \"fireAndForget\", returnType: CAPPluginReturnNone)\n    ]\n    @objc func doThing(_ call: CAPPluginCall) { call.resolve() }\n}\n</code></pre>\n</li>\n<li>Delete <code>FooPlugin.m</code> and <code>FooPlugin.h</code> (the <code>CAP_PLUGIN</code> bridge) and stale <code>Plugin.xcodeproj</code>, <code>Plugin.xcworkspace</code>, <code>Podfile</code>, <code>Info.plist</code> files under <code>ios/</code>.</li>\n<li>Add root <code>Package.swift</code>. Template and variants (resources, binary targets, third-party packages, mixed ObjC) in <code>references/package-swift-templates.md</code>.</li>\n<li>Update the podspec: <code>s.source_files = 'ios/Sources/**/*.{swift,h,m,c,cc,mm,cpp}'</code>, keep <code>s.dependency 'Capacitor'</code>, and mirror deployment target and resources.</li>\n<li>Update <code>package.json</code>:\n<ul>\n<li><code>files</code>: add <code>ios/Sources/</code>, <code>Package.swift</code>; keep the <code>.podspec</code>; remove old <code>ios/Plugin/</code>.</li>\n<li><code>verify:ios</code>: <code>xcodebuild -scheme &lt;Name&gt; -destination generic/platform=iOS</code>.</li>\n</ul>\n</li>\n</ol>\n<h2>Verification</h2>\n<pre><code># Package resolves and builds standalone (from plugin root)\nswift package describe &gt;/dev/null &amp;&amp; echo \"manifest ok\"\nxcodebuild -scheme &lt;Name&gt; -destination generic/platform=iOS build\n# Published tarball contains the manifest and sources\nnpm pack --dry-run 2&gt;&amp;1 | grep -E 'Package.swift|ios/Sources'\n# No leftover ObjC bridge\ngrep -rn \"CAP_PLUGIN(\" ios/ &amp;&amp; echo \"LEFTOVER BRIDGE\"\n</code></pre>\n<p>Then in an SPM example/test app (directory with <code>capacitor.config.*</code>): install the plugin (<code>npm install ../path</code> or a packed tarball), run <code>npx cap sync ios</code>, confirm no <code>does not have a Package.swift</code> warning, confirm <code>&lt;Name&gt;</code> appears in <code>ios/App/CapApp-SPM/Package.swift</code> and the class appears in <code>ios/App/App/capacitor.config.json</code> <code>packageClassList</code>, build, and call one method from JS. Also run <code>pod lib lint</code> (or a CocoaPods example app) if the podspec is still published.</p>\n<h2>Error Handling</h2>\n<table>\n<thead>\n<tr>\n<th>Error</th>\n<th>Fix</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code>product '&lt;Name&gt;' required by package 'capapp-spm' target 'CapApp-SPM' not found in package '&lt;Name&gt;'</code></td>\n<td><code>Package(name:)</code> / <code>.library(name:)</code> do not match the CLI-derived <code>&lt;Name&gt;</code>.</td>\n</tr>\n<tr>\n<td><code>\"Foo\" plugin is not implemented on ios</code></td>\n<td>Missing <code>@objc(FooPlugin)</code>, wrong <code>jsName</code>, or class not in <code>packageClassList</code>; re-sync after fixing.</td>\n</tr>\n<tr>\n<td><code>\"Foo.bar()\" is not implemented on ios</code></td>\n<td>Method missing from <code>pluginMethods</code> or not marked <code>@objc</code>.</td>\n</tr>\n<tr>\n<td><code>No such module 'Capacitor'</code> building the package</td>\n<td>Missing <code>capacitor-swift-pm</code> dependency or wrong product name.</td>\n</tr>\n<tr>\n<td><code>public headers (\"include\") directory path for 'X' is invalid or not contained in the target</code></td>\n<td>Mixed ObjC target without <code>publicHeadersPath</code>; split ObjC into its own target (see reference).</td>\n</tr>\n<tr>\n<td><code>&lt;id&gt; is built for Capacitor &lt;N&gt;, it might cause issues</code> (in app)</td>\n<td>Bump <code>capacitor-swift-pm</code> <code>from:</code> to the app's major.</td>\n</tr>\n<tr>\n<td><code>Cordova</code> product missing (Capacitor 9 app)</td>\n<td>Remove the <code>Cordova</code> product dependency.</td>\n</tr>\n<tr>\n<td>Resource not found at runtime</td>\n<td>Declare <code>resources:</code> and load via <code>Bundle.module</code>, not <code>Bundle.main</code>.</td>\n</tr>\n</tbody>\n</table>\n<h2>References</h2>\n<p>Only load when the topic is in play:</p>\n<ul>\n<li><code>references/package-swift-templates.md</code>: base manifest, resources and privacy manifest, third-party SPM dependencies, binary <code>.xcframework</code>, mixed Swift/ObjC targets, Capacitor 8 vs 9 dependency blocks.</li>\n</ul>\n","files":[{"path":"metadata.json","sizeBytes":1181,"isText":true},{"path":"references/package-swift-templates.md","sizeBytes":3661,"isText":true},{"path":"SKILL.md","sizeBytes":8293,"isText":true}],"reviewScore":null,"reviewSummary":null,"trust":{"provenance":"trusted-source-unreviewed","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow.","bodySource":null},"bodyLocked":false,"purchaseUrl":null,"sourceUrl":null,"report":{"provenance":"trusted-source-unreviewed","screen":{"ran":true,"outcome":"clean","suspicious":0,"notes":0,"hiddenCharacters":false},"virusScan":{"engine":"clamav","status":"clean","scannedAt":"2026-12-05T18:18:42.28812Z","sha256":"E52C275B45F2161B03CCB2A920C9299B6447C2D447E3704A32CA1491B7C7ECC4","sizeBytes":5627},"review":null,"source":{"repositoryUrl":"https://github.com/Cap-go/capgo-skills","path":"plugins/capacitor-plugin-dev/skills/capacitor-plugin-spm-support","license":"MIT","commit":"76462e3a0041ee8dd0d370c344d9fd3ae2c29cdb","subtreeSha":"DD5893D5305DC0B5C042440F0929E874E0B07C63C9408A8B0D3C75474F6DE9DC","lastSyncedAt":"2026-12-05T18:17:06.651351Z"},"reviewedAt":"2026-12-05T18:20:55.9199Z","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow."},"install":[{"target":"skills-cli","command":"npx skills add https://github.com/Cap-go/capgo-skills/tree/main/plugins/capacitor-plugin-dev/skills/capacitor-plugin-spm-support"},{"target":"claude-code","command":"claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install cap-go-capgo-skills@llmmart"},{"target":"git","command":"git clone https://github.com/Cap-go/capgo-skills.git"}]}