fix(cli): generate resource entries in Package.swift#8455
Conversation
| for (const resource of resources) { | ||
| resourceEntry.push(`.copy("resources/${resource.$.src.split('/').pop()}")`); | ||
| } | ||
| return resources.length > 0 |
There was a problem hiding this comment.
A little confusing what's going on here. Could we split this up without the ternary? I thought it was returning bool, and then thought there was dead code, before I noticed what was up.
There was a problem hiding this comment.
This is in line with other string generations in the codebase:
capacitor/cli/src/ios/update.ts
Line 204 in 1f7e33f
capacitor/cli/src/ios/update.ts
Lines 189 to 192 in 1f7e33f
capacitor/cli/src/ios/update.ts
Lines 206 to 211 in 1f7e33f
Lines 137 to 144 in 1f7e33f
Co-authored-by: OS-ruimoreiramendes <rui.moreira.mendes@outsystems.com>
| return { binaryTargetsText, binaryDepsText }; | ||
| } | ||
|
|
||
| function buildResourcesText(resources: any[]) { |
There was a problem hiding this comment.
Also, not sure if this is a real concern, but buildResourcesText uses .copy() for all resource types. For resources like .xcassets, .storyboard, and .xib, SPM typically requires .process() to compile them correctly, otherwise they might not be accessible at runtime. That said, the best way to validate this would probably be with a real plugin that actually uses these file types, since the dummy plugin I created for testing had XIB/xcassets files that weren't properly generated by Xcode. If the plugin you tested already included these file types and everything worked fine, then this is probably not a concern!
There was a problem hiding this comment.
I've only found plugins using .bundle file extension and they required .copy.
For those file extensions we shouldn't even need to add a resources entry as it's supposed to auto detect them according to the docs, but having them with the copy might conflict, so we will have to revisit if some user reports that they don't work and provide some Cordova plugin to reproduce. We will merge as it is now.
When you add a resource to your Swift package, Xcode detects common resource types for Apple platforms and treats them as a resource automatically. For example, you don’t need to make changes to your package manifest for the following resources:
Interface Builder files; for example, XIB files and storyboards
Core Data files; for example, xcdatamodeld files
Asset catalogs
.lproj folders you use to provide localized resources
https://developer.apple.com/documentation/xcode/bundling-resources-with-a-swift-package
If using SPM:
SWIFTPM_MODULE_BUNDLEinstead of[NSBundle bundleForClassSWIFTPM_MODULE_BUNDLE URLForResourceinstead of[NSBundle mainBundle] URLForResource(we can't just replace all[NSBundle mainBundle]occurrences withSWIFTPM_MODULE_BUNDLEas some plugins use[NSBundle mainBundle]to get actual main bundle files such as the Info.plist information.