Skip to content

preserve old formatting of Package.resolved in tools-version < 5.6 #3931

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

Merged
merged 1 commit into from
Dec 13, 2021
Merged
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
37 changes: 36 additions & 1 deletion Sources/PackageGraph/PinsStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ fileprivate struct PinsStorage {
data = try self.encoder.encode(container)
} else {
let container = try V1(pins: pins, mirrors: mirrors)
data = try self.encoder.encode(container)
let json = container.toLegacyJSON()
let bytes = json.toBytes(prettyPrint: true)
data = Data(bytes.contents)
}
#if !os(Windows)
// rdar://83646952: add newline for POSIXy systems
Expand Down Expand Up @@ -231,8 +233,23 @@ fileprivate struct PinsStorage {
)
}

// backwards compatibility of JSON format
func toLegacyJSON() -> JSON {
return .init([
"version": self.version.toJSON(),
"object": self.object.toLegacyJSON()
])
}

struct Container: Codable {
var pins: [Pin]

// backwards compatibility of JSON format
func toLegacyJSON() -> JSON {
return .init([
"pins": self.pins.map { $0.toLegacyJSON() },
])
}
}

struct Pin: Codable {
Expand All @@ -256,6 +273,15 @@ fileprivate struct PinsStorage {
self.repositoryURL = mirrors.originalURL(for: location) ?? location
self.state = try .init(pin.state)
}

// backwards compatibility of JSON format
func toLegacyJSON() -> JSON {
return .init([
"package": self.package.toJSON(),
"repositoryURL": self.repositoryURL.toJSON(),
"state": self.state.toLegacyJSON()
])
}
}

struct State: Codable {
Expand All @@ -281,6 +307,15 @@ fileprivate struct PinsStorage {
throw StringError("invalid pin state: \(state)")
}
}

// backwards compatibility of JSON format
func toLegacyJSON() -> JSON {
return .init([
"revision": self.revision.toJSON(),
"version": self.version.toJSON(),
"branch": self.branch.toJSON()
])
}
}
}

Expand Down