Skip to content
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

Improve Naming for Swift Packages using Package.resolved v2 #192

Merged
merged 2 commits into from
Jul 29, 2022
Merged

Improve Naming for Swift Packages using Package.resolved v2 #192

merged 2 commits into from
Jul 29, 2022

Conversation

bennokress
Copy link
Contributor

@bennokress bennokress commented Jul 28, 2022

Problem (Issue #179)

With the new Package.resolved JSON version 2 (#174), which Apple introduce with Xcode 13.3 and Swift 5.6, I miss the correct package names.

Attempted Solution

Based on the idea of @ykws:

We may be able to pick up the name from Package(name:) in Package.swift, we can access each location in Package.resolved as repository url.

This PR has a solution that works in most cases by doing exactly that and falls back to a sensible default name when parsing the Package.swift fails.

In depth

What I implement here is a 3-step process to get the best name possible from the new version of Package.resolved:

  1. Make sure we don't parse a Package.resolved v1 file and instantly return the name from that otherwise (current v1 implementation)
  2. Take the Repository Name from the Github Conversion Step that is currently implemented in LicensePlist which is already an improvement on the result of Step 1 (current v2 implementation), since it has uppercased characters in all the right places. We still have some issues when dealing with Packages containing spaces though (those have dashes instead, but replacing those would break Packages that really have dashes in their names).
  3. Parse the Package.swift from the Repository by looking for the first Package object, removing all nested code inside [...] to eliminate dependency and target names and finally getting the remaining value for name. If anything fails we return nil which lets us fall back to the result of Step 2.

Edge cases I encountered are also added as Unit Tests, so you can play around in the parser with confidence.

@mono0926 mono0926 self-requested a review July 29, 2022 05:42
@mono0926 mono0926 merged commit 68b8533 into mono0926:main Jul 29, 2022
@mono0926
Copy link
Owner

Thanks, released: https://github.com/mono0926/LicensePlist/releases/tag/3.22.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants