Created
March 9, 2024 15:56
-
-
Save jpudysz/d7d76816016fb55c9f7141ae170b1dcc to your computer and use it in GitHub Desktop.
Add Swift Package to Watch target (Expo)
This file contains 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
// this function is called from patched expo-apple-targets | |
// register all packages here | |
const swiftPackages = [ | |
{ | |
name: 'PackageName', | |
url: 'https://github.com/...', | |
version: '1.0.0' | |
} | |
] | |
const withSwiftPackages = (xcode, project) => { | |
swiftPackages.forEach(pkg => { | |
const watchTarget = project.rootObject.getMainAppTarget("watchos") | |
const watchFrameworks = watchTarget.getBuildPhase(xcode.PBXFrameworksBuildPhase) | |
// create SwiftPackageReference | |
const reference = xcode.XCRemoteSwiftPackageReference.create(project, { | |
repositoryURL: pkg.url, | |
requirement: { | |
kind: 'upToNextMajorVersion', | |
value: pkg.version | |
} | |
}) | |
// create SwiftPackageDependency | |
const dependency = xcode.XCSwiftPackageProductDependency.create(project, { | |
package: reference.uuid, | |
productName: pkg.name | |
}) | |
// add to PBXBuildFile | |
const buildFile = xcode.PBXBuildFile.create(project, { | |
productRef: dependency | |
}) | |
// add to watchOS frameworks | |
watchFrameworks.props.files.push(buildFile) | |
const productDependencies = [ | |
...watchTarget.props.packageProductDependencies ?? [], | |
dependency | |
] | |
// add watchos productDependencies | |
watchTarget.props.packageProductDependencies = productDependencies | |
const packageReferences = [ | |
...project.rootObject.props.packageReferences ?? [], | |
reference | |
] | |
// add main project packageReferences | |
project.rootObject.props.packageReferences = packageReferences | |
}) | |
} | |
module.exports = withSwiftPackages |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment