-
Notifications
You must be signed in to change notification settings - Fork 278
docs: SPM Migration Docs #411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
markemer
wants to merge
2
commits into
main
Choose a base branch
from
spm-migrate
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ title: Swift Package Manager | |
description: SPM Basics | ||
contributors: | ||
- giralte-ionic | ||
- markemer | ||
slug: /ios/spm | ||
--- | ||
|
||
|
@@ -14,21 +15,20 @@ Since Capacitor 6, you can choose between using CocoaPods or Swift Package Manag | |
|
||
We've tried our best to make sure you don't have to change much about how you work with Capacitor to use SPM, but there are a few things to understand. | ||
|
||
### How it works | ||
## How it works | ||
|
||
When a Capacitor project is using SPM we use a 'Base SPM' package that will serve as the place that references all of your projects dependencies: | ||
|
||
 | ||
|
||
The Capacitor CLI will modify the CapAPP-SPM package when you sync new plugins. It is important you do not touch the contents here because the CLI can and will change things. | ||
|
||
### Using SPM in a new Capacitor project | ||
## Using SPM in a new Capacitor project | ||
|
||
First we'll start with our normal `npm init @capacitor/app@latest`: | ||
|
||
 | ||
|
||
|
||
Now we want to add the iOS platform to our project: | ||
|
||
`npm install @capacitor/ios` | ||
|
@@ -45,7 +45,7 @@ Now you can use `npx cap open ios` to open the iOS project and run your app from | |
|
||
--- | ||
|
||
### Add and use a Capactior Plugin with SPM | ||
### Add and use a Capacitor Plugin with SPM | ||
|
||
So let's add a plugin to this project and do something with that plugin. | ||
|
||
|
@@ -59,7 +59,45 @@ Then let's sync the web app. This will add the App plugin SPM to the iOS project | |
|
||
You can now use the App plugin normally. | ||
|
||
<em>More details coming soon</em> | ||
## Using SPM in an existing Capacitor Project | ||
|
||
### Using our migration tool | ||
|
||
The Capacitor CLI has a command to help migrate from CocoaPods to Swift Package Manager. However, one manual step is still required. In addition, projects with Cordova plugins will not be migrated correctly and neither will projects that use plugins that do not have SPM versions available. | ||
|
||
To start, run `npx cap migrate-to-spm` in the root of your project. | ||
|
||
This tool will: | ||
- Run `pod deintegrate` removing CocoaPods | ||
- Delete the `Podfile`, `App.xcworkspace`, and `Podfile.lock` | ||
- Create a `CapApp-SPM` directory with the needed files | ||
- Generate a `Package.swift` from your plugins, and warn you if any can't included. | ||
|
||
After this is run, run a `npx cap sync` again. | ||
|
||
Then run `npx cap open ios` and you should see something similar to this: | ||
|
||
 | ||
|
||
Highlight App, and Select the Package Dependencies tab, and on this page press the + symbol to add a dependency: | ||
|
||
 | ||
|
||
You should see something similar to the below - select Add Local... from the dialog: | ||
|
||
 | ||
|
||
Select CapApp-SPM in this dialog and click Add Package: | ||
|
||
 | ||
|
||
Click Add Package again when this screen shows up: | ||
|
||
 | ||
|
||
When you are done, you should see a screen like this. At this point you're done and can build and work as normal: | ||
|
||
 | ||
|
||
### Converting existing plugins to SPM | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The ticket also mentioned
But this section is unchanged, should be updated too |
||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a first section could mention the possibility of removing
ios
folder and adding it back withnpx cap add ios --packagemanager SPM
in case the user didn't do any custom changes to the project, since that's the "easiest" migration and requires no manual steps.