-
Notifications
You must be signed in to change notification settings - Fork 984
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
WIP - feat: Add support for SPM plugins #1430
Conversation
There's a bit of Xcode mangling the project file (stripping licence comments, removing quotes around The idea of a SwiftPM subproject is a good one and will make the process of adding/removing plugins significantly easier than trying to deal with the Xcode project directly. That said, would it make sense for CordovaLib to be referenced directly from the Xcode project rather than through the SwiftPM library? One worry is that we won't be able to ship with CordovaLib pointing at |
templates/project/__PROJECT_NAME__.xcworkspace/xcshareddata/swiftpm/Package.resolved
Outdated
Show resolved
Hide resolved
Keeping CordovaLib was a good call as it allows plugins to not have a dependency to cordova-ios, I tried several things like using an environment variable for setting the cordova-ios versions to use based on the installed version, and worked when running the app from the CLI, but was not working if running from Xcode since the variable is unset when the node process stops. Also tried using cordova-ios from node_modules directly and works fine for the While I would have loved using the local version so we have the privacy manifest linked and on plugins we could run |
hmmm, I'd been hoping that we would be able to reference CordovaLib using SwiftPM, but directly in the app's Xcode project rather than through the CordovaPluginsSPM project's Package.swift... but if I'm reading your comment correctly that still causes issues for plugins? 😞 |
I didn't try that, but still, it would be a complex thing to do since if you add it to the template, when the template is turned into an app the path to cordova-ios's Package.swift will be different, so should be adjusted in the xcodeproj file. Could be possible by having a |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1430 +/- ##
==========================================
- Coverage 78.35% 77.91% -0.45%
==========================================
Files 16 16
Lines 1825 1838 +13
==========================================
+ Hits 1430 1432 +2
- Misses 395 406 +11 ☔ View full report in Codecov by Sentry. |
@@ -279,6 +279,11 @@ class Api { | |||
return this.addPodSpecs(plugin, podSpecs, installOptions); | |||
} | |||
}) | |||
.then(() => { | |||
if (plugin != null && plugin.dir && fs.existsSync(path.join(plugin.dir, 'Package.swift'))) { |
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.
Looking at this PR again, and the one thing I don't really love is the "magic" behaviour based on the existence of a Package.swift file in the plugin folder. It feels safer to rely on an explicit declaration in the plugin.xml file.
We've already overloaded the <framework>
tag to do a billion things, so adding this wouldn't be totally unreasonable. i.e.,
<framework src="Package.swift" type="spm" />
Alternatively, the lib-file
tag exists on Android but you could maybe stretch the definition to encompass Swift packages.
Using source-file
is an option, but feels like that goes back to "magic" behaviour based on file names.
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.
The point of having a Package.swift file is to turn the plugin into a swift package itself.
Having the Package.swift file makes it possible to add other swift packages the plugin wants to use as dependencies the “swift package way”.
Adding the Package.swift file in a framework tag makes no sense, in any case we could totally ditch the Package.swift file from plugins and use the framework tag to declare SPM dependencies, and then read the tag and write the dependencies in the CordovaPluginsSPM/Package.swift file but the tag will fall short for all the possible options and will end up creating a new tag in a future release as we did for CocoaPods.
The CLI should also copy the plugin files to the CordovaPluginsSPM project instead of to the app as if the plugin relies in the dependency and the dependency is in CordovaPluginsSPM project the plugin files should be there.
Anyway, I’m closing the PR, it was painful enough to address the requested changes on the project.pbxproj file, now it has conflicts that will be impossible to fix |
Remove CordovaLib from the template and instead add a local "empty" swift package, in which
cordova-plugin-add
will add the plugins as dependencies if they are swift package manager compatible.Plugin example to test with: apache/cordova-plugin-device#196
Using this approach plugins that want to add Swift Package Manager dependencies will have to be converted to be Swift Package Manager compatible and add dependences as they would to a regular Swift Package instead of relying in a new tag in
plugin.xml