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

[Fix] Wrong assumption of Package.revision being non-optional #128

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,10 @@ The Settings Bundle and the UI-components are currently localized in the followi

> If a language has mistakes or is missing, feel free to create an issue or open a pull request.

## Known limitations

- SwiftPackageList won't include license files from packages that are located in a registry like Artifactory.
Copy link
Owner

Choose a reason for hiding this comment

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

I would like to play around with that but there is still not a single public registry I could easily use, right?



## License

Expand Down
8 changes: 4 additions & 4 deletions Sources/SwiftPackageList/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ public struct Package: Sendable, Hashable, Codable {

/// The exact revision/commit.
///
/// This is always present, regardless if the package's dependency-rule is version or branch.
public let revision: String
/// Could be `nil` if the package is located in a registry.
public let revision: String?
Copy link
Owner

@FelixHerrmann FelixHerrmann Nov 20, 2024

Choose a reason for hiding this comment

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

This is technically a breaking changes and requires a major version bump but I think we can get it in with a patch release because its more of a bug fix and I don't think that it's utilized often.


/// The URL to the git-repository.
public let repositoryURL: URL

Expand All @@ -44,7 +44,7 @@ public struct Package: Sendable, Hashable, Codable {
name: String,
version: String?,
branch: String?,
revision: String,
revision: String?,
repositoryURL: URL,
license: String?
) {
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftPackageListCore/Files/PackageResolved.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ extension PackageResolved.Storage {
struct V2: Decodable {
struct Pin: Decodable {
struct State: Decodable {
let revision: String
let revision: String?
let version: String?
let branch: String?
}
Expand Down
24 changes: 23 additions & 1 deletion Tests/SwiftPackageListCoreTests/PackageResolvedTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,29 @@ final class PackageResolvedTests: XCTestCase {
XCTAssertEqual((error as? RuntimeError)?.description, "Version 999 of Package.resolved is not supported")
}
}


func testPackagesFromRegistry() throws {
let url = Bundle.module.url(
forResource: "Package_registry",
withExtension: "resolved",
subdirectory: "Resources/PackageResolved"
)
let unwrappedURL = try XCTUnwrap(url)
let packageResolved = try PackageResolved(url: unwrappedURL)

guard case .v2(let packageResolved) = packageResolved.storage else {
XCTFail("\(unwrappedURL.path) was not recognized as v2")
return
}
XCTAssertEqual(packageResolved.version, 2)
XCTAssertEqual(packageResolved.pins[0].identity, "package.in.registry.like.artifactory")
XCTAssertEqual(packageResolved.pins[0].kind, "registry")
XCTAssertEqual(packageResolved.pins[0].location, "")
XCTAssertNil(packageResolved.pins[0].state.branch)
XCTAssertNil(packageResolved.pins[0].state.revision)
XCTAssertEqual(packageResolved.pins[0].state.version, "1.2.3")
}

func testVersion1IdentityConstruction() {
let remotePin = PackageResolved.Storage.V1.Object.Pin(
package: "",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"pins": [
{
"identity" : "package.in.registry.like.artifactory",
"kind" : "registry",
"location" : "",
"state" : {
"version" : "1.2.3"
}
}
],
"version": 2
}
Loading