Skip to content

Commit b89560c

Browse files
committed
Basics: make some of the private API more public
This extends the visibility of some of the private implementation to the package level to allow use for testing without `@testable` imports.
1 parent 3630c8d commit b89560c

File tree

11 files changed

+35
-35
lines changed

11 files changed

+35
-35
lines changed

Sources/Basics/Archiver/TarArchiver.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public struct TarArchiver: Archiver {
2525
private let cancellator: Cancellator
2626

2727
/// The underlying command
28-
internal let tarCommand: String
28+
package let tarCommand: String
2929

3030
/// Creates a `TarArchiver`.
3131
///

Sources/Basics/Archiver/ZipArchiver.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ public struct ZipArchiver: Archiver, Cancellable {
2929

3030
/// Absolute path to the Windows tar in the system folder
3131
#if os(Windows)
32-
internal let windowsTar: String
32+
package let windowsTar: String
3333
#else
34-
internal let unzip = "unzip"
35-
internal let zip = "zip"
34+
package let unzip = "unzip"
35+
package let zip = "zip"
3636
#endif
3737

3838
#if os(FreeBSD)

Sources/Basics/AuthorizationProvider.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ extension AuthorizationProvider {
5555

5656
public final class NetrcAuthorizationProvider: AuthorizationProvider, AuthorizationWriter {
5757
// marked internal for testing
58-
internal let path: AbsolutePath
58+
package let path: AbsolutePath
5959
private let fileSystem: FileSystem
6060

6161
private let cache = ThreadSafeKeyValueStore<String, (user: String, password: String)>()
@@ -140,7 +140,7 @@ public final class NetrcAuthorizationProvider: AuthorizationProvider, Authorizat
140140
}
141141

142142
// marked internal for testing
143-
internal var machines: [Basics.Netrc.Machine] {
143+
package var machines: [Basics.Netrc.Machine] {
144144
// this ignores any errors reading the file
145145
// initial validation is done at the time of initializing the provider
146146
// and if the file becomes corrupt at runtime it will handle it gracefully
@@ -408,16 +408,16 @@ public final class KeychainAuthorizationProvider: AuthorizationProvider, Authori
408408
return item
409409
}
410410

411-
struct ProtocolHostPort: Hashable, CustomStringConvertible {
412-
let `protocol`: String?
413-
let host: String
414-
let port: Int?
411+
package struct ProtocolHostPort: Hashable, CustomStringConvertible {
412+
package let `protocol`: String?
413+
package let host: String
414+
package let port: Int?
415415

416416
var server: String {
417417
self.host
418418
}
419419

420-
var protocolCFString: CFString {
420+
package var protocolCFString: CFString {
421421
// See
422422
// https://developer.apple.com/documentation/security/keychain_services/keychain_items/item_attribute_keys_and_values?language=swift
423423
// for a list of possible values for the `kSecAttrProtocol` attribute.
@@ -431,7 +431,7 @@ public final class KeychainAuthorizationProvider: AuthorizationProvider, Authori
431431
}
432432
}
433433

434-
init?(from url: URL) {
434+
package init?(from url: URL) {
435435
guard let host = url.host?.lowercased(), !host.isEmpty else {
436436
return nil
437437
}
@@ -441,7 +441,7 @@ public final class KeychainAuthorizationProvider: AuthorizationProvider, Authori
441441
self.port = url.port
442442
}
443443

444-
var description: String {
444+
package var description: String {
445445
"\(self.protocol.map { "\($0)://" } ?? "")\(self.host)\(self.port.map { ":\($0)" } ?? "")"
446446
}
447447
}
@@ -452,7 +452,7 @@ public final class KeychainAuthorizationProvider: AuthorizationProvider, Authori
452452

453453
public struct CompositeAuthorizationProvider: AuthorizationProvider {
454454
// marked internal for testing
455-
internal let providers: [AuthorizationProvider]
455+
package let providers: [AuthorizationProvider]
456456
private let observabilityScope: ObservabilityScope
457457

458458
public init(_ providers: AuthorizationProvider..., observabilityScope: ObservabilityScope) {

Sources/Basics/Cancellator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public final class Cancellator: Cancellable, Sendable {
144144

145145
// marked internal for testing
146146
@discardableResult
147-
internal func _cancel(deadline: DispatchTime? = .none) -> Int {
147+
package func _cancel(deadline: DispatchTime? = .none) -> Int {
148148
self.cancelling.put(true)
149149

150150
self.observabilityScope?

Sources/Basics/Concurrency/SendableBox.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,17 @@ public actor SendableBox<Value: Sendable> {
2828
}
2929

3030
extension SendableBox where Value == Int {
31-
func increment() {
31+
package func increment() {
3232
self.value = value + 1
3333
}
3434

35-
func decrement() {
35+
package func decrement() {
3636
self.value = value - 1
3737
}
3838
}
3939

4040
extension SendableBox where Value == Date {
41-
func resetDate() {
41+
package func resetDate() {
4242
value = Date()
4343
}
4444
}

Sources/Basics/Graph/AdjacencyMatrix.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
/// edge exists.
1919
///
2020
/// See https://en.wikipedia.org/wiki/Adjacency_matrix for more details.
21-
struct AdjacencyMatrix {
21+
package struct AdjacencyMatrix {
2222
let columns: Int
2323
let rows: Int
2424
private var bytes: [UInt8]
@@ -27,15 +27,15 @@ struct AdjacencyMatrix {
2727
/// - Parameters:
2828
/// - rows: Number of rows in the matrix.
2929
/// - columns: Number of columns in the matrix.
30-
init(rows: Int, columns: Int) {
30+
package init(rows: Int, columns: Int) {
3131
self.columns = columns
3232
self.rows = rows
3333

3434
let (quotient, remainder) = (rows * columns).quotientAndRemainder(dividingBy: 8)
3535
self.bytes = .init(repeating: 0, count: quotient + (remainder > 0 ? 1 : 0))
3636
}
3737

38-
var bitCount: Int {
38+
package var bitCount: Int {
3939
bytes.count * 8
4040
}
4141

@@ -44,7 +44,7 @@ struct AdjacencyMatrix {
4444
return (byteOffset: totalBitOffset / 8, bitOffsetInByte: totalBitOffset % 8)
4545
}
4646

47-
subscript(row: Int, column: Int) -> Bool {
47+
package subscript(row: Int, column: Int) -> Bool {
4848
get {
4949
let (byteOffset, bitOffsetInByte) = calculateOffsets(row: row, column: column)
5050

Sources/Basics/HTTPClient/HTTPClientHeaders.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ public struct HTTPClientHeaders: Sendable {
6464
}
6565

6666
public struct Item: Equatable, Sendable {
67-
let name: String
68-
let value: String
67+
package let name: String
68+
package let value: String
6969

7070
public init(name: String, value: String) {
7171
self.name = name

Sources/Basics/HTTPClient/HTTPMethod.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public enum HTTPMethod: Sendable {
1717
case put
1818
case delete
1919

20-
var string: String {
20+
package var string: String {
2121
switch self {
2222
case .head:
2323
return "HEAD"

Sources/Basics/HTTPClient/URLSessionHTTPClient.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ import struct TSCUtility.Versioning
1818
import FoundationNetworking
1919
#endif
2020

21-
final class URLSessionHTTPClient: Sendable {
21+
package final class URLSessionHTTPClient: Sendable {
2222
private let dataSession: URLSession
2323
private let downloadSession: URLSession
2424
private let dataTaskManager: DataTaskManager
2525
private let downloadTaskManager: DownloadTaskManager
2626

27-
init(configuration: URLSessionConfiguration = .default) {
27+
package init(configuration: URLSessionConfiguration = .default) {
2828
let dataDelegateQueue = OperationQueue()
2929
dataDelegateQueue.name = "org.swift.swiftpm.urlsession-http-client-data-delegate"
3030
dataDelegateQueue.maxConcurrentOperationCount = 1
@@ -52,7 +52,7 @@ final class URLSessionHTTPClient: Sendable {
5252
}
5353

5454
@Sendable
55-
func execute(
55+
package func execute(
5656
_ request: HTTPClient.Request,
5757
progress: HTTPClient.ProgressHandler? = nil
5858
) async throws -> LegacyHTTPClient.Response {
@@ -364,7 +364,7 @@ private final class DownloadTaskManager: NSObject, URLSessionDownloadDelegate {
364364
}
365365

366366
extension URLRequest {
367-
init(_ request: LegacyHTTPClient.Request) {
367+
package init(_ request: LegacyHTTPClient.Request) {
368368
self.init(url: request.url)
369369
self.httpMethod = request.method.string
370370
request.headers.forEach { header in

Sources/Basics/ProgressAnimation/ThrottledProgressAnimation.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ import _Concurrency
1414
import TSCUtility
1515

1616
/// A progress animation wrapper that throttles updates to a given interval.
17-
final class ThrottledProgressAnimation: ProgressAnimationProtocol {
17+
package final class ThrottledProgressAnimation: ProgressAnimationProtocol {
1818
private let animation: ProgressAnimationProtocol
1919
private let shouldUpdate: () -> Bool
2020
private var pendingUpdate: (Int, Int, String)?
2121

22-
init<C: Clock>(
22+
package init<C: Clock>(
2323
_ animation: ProgressAnimationProtocol,
2424
now: @escaping () -> C.Instant, interval: C.Duration, clock: C.Type = C.self
2525
) {
@@ -36,7 +36,7 @@ final class ThrottledProgressAnimation: ProgressAnimationProtocol {
3636
}
3737
}
3838

39-
func update(step: Int, total: Int, text: String) {
39+
package func update(step: Int, total: Int, text: String) {
4040
guard shouldUpdate() else {
4141
pendingUpdate = (step, total, text)
4242
return
@@ -45,14 +45,14 @@ final class ThrottledProgressAnimation: ProgressAnimationProtocol {
4545
animation.update(step: step, total: total, text: text)
4646
}
4747

48-
func complete(success: Bool) {
48+
package func complete(success: Bool) {
4949
if let (step, total, text) = pendingUpdate {
5050
animation.update(step: step, total: total, text: text)
5151
}
5252
animation.complete(success: success)
5353
}
5454

55-
func clear() {
55+
package func clear() {
5656
animation.clear()
5757
}
5858
}

0 commit comments

Comments
 (0)