Skip to content

Commit

Permalink
Merge pull request #128 from JanBrinker/fix/enable-registry-packages
Browse files Browse the repository at this point in the history
[Fix] Wrong assumption of `Package.revision` being non-optional
  • Loading branch information
FelixHerrmann authored Nov 20, 2024
2 parents 26732b1 + 148c6a0 commit b538985
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 6 deletions.
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.


## 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?

/// 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
}

0 comments on commit b538985

Please sign in to comment.