Skip to content

fix(cli): generate resource entries in Package.swift#8455

Merged
jcesarmobile merged 2 commits intomainfrom
RMET-5157
May 5, 2026
Merged

fix(cli): generate resource entries in Package.swift#8455
jcesarmobile merged 2 commits intomainfrom
RMET-5157

Conversation

@jcesarmobile
Copy link
Copy Markdown
Member

If using SPM:

  • copy the resources to the plugin folder instead of a separate resources folder.
  • generate resources entry in Package.swift
  • patch code to use SWIFTPM_MODULE_BUNDLE instead of [NSBundle bundleForClass
  • patch code to use SWIFTPM_MODULE_BUNDLE URLForResource instead of [NSBundle mainBundle] URLForResource (we can't just replace all [NSBundle mainBundle] occurrences with SWIFTPM_MODULE_BUNDLE as some plugins use [NSBundle mainBundle] to get actual main bundle files such as the Info.plist information.

Comment thread cli/src/ios/update.ts
Comment thread cli/src/ios/update.ts
for (const resource of resources) {
resourceEntry.push(`.copy("resources/${resource.$.src.split('/').pop()}")`);
}
return resources.length > 0
Copy link
Copy Markdown
Member

@markemer markemer May 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is in line with other string generations in the codebase:

const libraryTypeText = hasWeakFrameworks ? `\n type: .dynamic,` : '';

headerFiles.length > 0
? `,
publicHeadersPath: "."`
: '';

requiredSystemFrameworks.length > 0
? `,
linkerSettings: [
${requiredSystemFrameworks.map((f: any) => ` .linkedFramework("${f.$.src.replace('.framework', '')}")`).join(',\n')}
]`
: '';

const traitsSuffix = traits?.length
? `, traits: [${traits
.map((t) => {
// Any trait is written with quotes, with the exception of .defaults
return /^\.?defaults?$/i.test(t) ? '.defaults' : `"${t}"`;
})
.join(', ')}]`
: '';

Comment thread cli/src/ios/update.ts Outdated
Co-authored-by: OS-ruimoreiramendes <rui.moreira.mendes@outsystems.com>
Comment thread cli/src/ios/update.ts
return { binaryTargetsText, binaryDepsText };
}

function buildResourcesText(resources: any[]) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@jcesarmobile jcesarmobile merged commit 790bd27 into main May 5, 2026
6 checks passed
@jcesarmobile jcesarmobile deleted the RMET-5157 branch May 5, 2026 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants