jkasten2 opened a new issue #121: URL: https://github.com/apache/cordova-node-xcode/issues/121
# Description ## One Line Summary `addTargetDependency` misses some dependency links if `PBXTargetDependency` or `PBXContainerItemProxy` are not present. ## Affect Projects Calls made to calls `addTarget` or `addTargetDependency` with any `.xcodeproj` that only has one target, these do NOT have `PBXTargetDependency` or `PBXContainerItemProxy`. ## Details ### The root cause The following if statement in the `addTargetDependency` function skips the dependencies and other steps if it is missing. https://github.com/apache/cordova-node-xcode/blob/8b98cabc5978359db88dc9ff2d4c015cba40f150/lib/pbxProject.js#L860 ### Possible fixes #### Option 1 - Smallest number changes A simple way to fix this would be to use short-circuit evaluation where these `vars` are assigned to handle `null`, `undefined`, or if no key exists when reading from `hash.project.objects`. https://github.com/apache/cordova-node-xcode/blob/8b98cabc5978359db88dc9ff2d4c015cba40f150/lib/pbxProject.js#L834-L835 This could become the following to fix this issue: ```javascript pbxTargetDependencySection = this.hash.project.objects[pbxTargetDependency] || {}, pbxContainerItemProxySection = this.hash.project.objects[pbxContainerItemProxy] || {}; ``` #### Option 2 - Larger Refactor - Fix some clean up Same fix as option 1, but clean up the hard coded strings. 1. Put these at the top of the file: ```javascript const PBX_TARGET_DEPENDECY = "PBXTargetDependency"; const PBX_CONTAINER_ITEM_PROXY = "PBXContainerItemProxy"; ``` 2. Use them here and remove the old vars: ```javascript const pbxTargetDependencySection = this.hash.project.objects[PBXTargetDependency] || {}; const pbxContainerItemProxySection = this.hash.project.objects[PBXContainerItemProxy] || {}; ``` ## Workaround ```javascript // Add code anytime before calling addTarget or addTargetDependency const projObjects = xcodeProject.hash.project.objects; projObjects['PBXTargetDependency'] = projObjects['PBXTargetDependency'] || {}; projObjects['PBXContainerItemProxy'] = projObjects['PBXTargetDependency'] || {}; ``` ## Submitting a PR - Is this an active library? It has been over a year since there has been a release or even a commit. If the maintainers could chime in I'd be happy to create one. I have read the [CONTRIBUTING.md](https://github.com/apache/cordova-node-xcode/blob/master/CONTRIBUTING.md) guide, is there any more to it than that? I see there is a good number of tests, I'll make sure to add one to cover the code change. Lastly let me know which of the possible fixes you prefer or if you have another idea. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
