Skip to content

Commit fa6c6d1

Browse files
authored
Updates plugins (#20)
* Updates Reachability * Updates Package, remove AsyncAlgorithms * Adds ShortID to DependencyValues * Moves Protected into its own module, renaming Concurrency * Updates the plugin tag * Fixes the import * Makes Cache iOS 15 only Co-authored-by: danthorpe <danthorpe@users.noreply.github.com>
1 parent 35926ec commit fa6c6d1

File tree

8 files changed

+256
-99
lines changed

8 files changed

+256
-99
lines changed

Package.swift

Lines changed: 129 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -7,77 +7,151 @@ var package = Package(name: "danthorpe-utilities")
77

88
package.platforms = [
99
.macOS(.v12),
10-
.iOS(.v15),
11-
.tvOS(.v15),
12-
.watchOS(.v8)
10+
.iOS(.v14),
11+
.tvOS(.v14),
12+
.watchOS(.v7)
1313
]
1414

15-
// MARK: - Products
16-
17-
package.products = [
18-
.library(name: "Cache", targets: ["Cache"]),
19-
.library(name: "EnvironmentProviders", targets: ["EnvironmentProviders"]),
20-
.library(name: "FileManagerClient", targets: ["FileManagerClient"]),
21-
.library(name: "Reachability", targets: ["ReachabilityLive"]),
22-
.library(name: "ReachabilityMocks", targets: ["ReachabilityMocks"]),
23-
.library(name: "ShortID", targets: ["ShortID"]),
24-
.library(name: "Utilities", targets: ["Cache", "ReachabilityLive", "ShortID"]),
25-
]
26-
27-
// MARK: - Dependencies
15+
// MARK: - External Dependencies
2816

2917
package.dependencies = [
3018
.package(url: "https://github.com/apple/swift-argument-parser.git", branch: "main"),
31-
.package(url: "https://github.com/apple/swift-async-algorithms", branch: "main"),
3219
.package(url: "https://github.com/apple/swift-collections", from: "1.0.2"),
33-
.package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "0.2.1"),
34-
.package(url: "https://github.com/danthorpe/danthorpe-plugins", branch: "main"),
20+
.package(url: "https://github.com/danthorpe/danthorpe-plugins", from: "0.2.0"),
21+
.package(url: "https://github.com/pointfreeco/swift-composable-architecture", from: "0.44.0"),
22+
.package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "0.5.0"),
3523
]
3624

37-
// MARK: - Targets
38-
39-
var targets: [Target] = [
40-
41-
.target(
42-
name: "Cache",
43-
dependencies: [
44-
"Extensions",
45-
"EnvironmentProviders",
46-
.product(name: "AsyncAlgorithms", package: "swift-async-algorithms"),
47-
.product(name: "OrderedCollections", package: "swift-collections"),
48-
.product(name: "DequeModule", package: "swift-collections"),
49-
]
50-
),
51-
52-
.target(name: "Extensions"),
53-
54-
.target(name: "EnvironmentProviders"),
55-
56-
.target(name: "FileManagerClient", dependencies: [
57-
.product(name: "XCTestDynamicOverlay", package: "xctest-dynamic-overlay")
58-
]),
25+
// MARK: - Name
26+
let Cache = "Cache"
27+
let EnvironmentProviders = "EnvironmentProviders"
28+
let Extensions = "Extensions"
29+
let FileManagerClient = "FileManagerClient"
30+
let Protected = "Protected"
31+
let Reachability = "Reachability"
32+
let ShortID = "ShortID"
33+
let Utilities = "Utilities"
34+
35+
private extension String {
36+
var tests: String { "\(self)Tests" }
37+
var mocks: String { "\(self)Mocks" }
38+
var live: String { "\(self)Live" }
39+
}
5940

60-
.target(name: "Reachability"),
61-
.target(name: "ReachabilityLive", dependencies: ["Reachability"]),
62-
.target(name: "ReachabilityMocks", dependencies: ["Reachability"]),
41+
// MARK: - Products
6342

64-
.target(name: "ShortID", dependencies: ["Concurrency"]),
43+
package.products = [
44+
.library(name: Cache, targets: [Cache]),
45+
.library(name: EnvironmentProviders, targets: [EnvironmentProviders]),
46+
.library(name: FileManagerClient, targets: [FileManagerClient]),
47+
.library(name: Protected, targets: [Protected]),
48+
.library(name: Reachability, targets: [Reachability]),
49+
.library(name: ShortID, targets: [ShortID]),
50+
]
6551

66-
.target(name: "Concurrency", dependencies: []),
52+
// MARK: - Targets
6753

68-
.testTarget(name: "CacheTests", dependencies: ["Cache"]),
69-
.testTarget(name: "ConcurrencyTests", dependencies: ["Concurrency"]),
70-
.testTarget(name: "ShortIDTests", dependencies: ["ShortID"]),
71-
]
54+
extension Target {
55+
static let cache: Target = .target(
56+
name: Cache,
57+
dependencies: [
58+
.extensions,
59+
.environmentProviders,
60+
.orderedCollection,
61+
.deque
62+
]
63+
)
64+
static let cacheTests: Target = .testTarget(
65+
name: Cache.tests,
66+
dependencies: [ .cache ]
67+
)
68+
static let protected: Target = .target(
69+
name: Protected
70+
)
71+
static let protectedTests: Target = .testTarget(
72+
name: Protected.tests,
73+
dependencies: [ .protected ]
74+
)
75+
static let extensions: Target = .target(
76+
name: Extensions
77+
)
78+
static let environmentProviders: Target = .target(
79+
name: EnvironmentProviders
80+
)
81+
static let fileManagerClient: Target = .target(
82+
name: FileManagerClient,
83+
dependencies: [ .xctestDynamicOverlay ]
84+
)
85+
static let reachability: Target = .target(
86+
name: Reachability,
87+
dependencies: [ .dependencies, .xctestDynamicOverlay ]
88+
)
89+
static let shortID: Target = .target(
90+
name: ShortID,
91+
dependencies: [ .dependencies, .protected ]
92+
)
93+
static let shortIDTests: Target = .testTarget(
94+
name: ShortID.tests,
95+
dependencies: [ .shortID ]
96+
)
97+
}
7298

73-
// Set SwiftLint plugin
74-
targets = targets.update(.regular, .test, plugins: [
75-
.plugin(name: "SwiftLintPlugin", package: "danthorpe-plugins"),
99+
package.targets = [
100+
.cache,
101+
.cacheTests,
102+
.protected,
103+
.protectedTests,
104+
.extensions,
105+
.environmentProviders,
106+
.fileManagerClient,
107+
.reachability,
108+
.shortID,
109+
.shortIDTests
110+
].update(.regular, .test, plugins: [
111+
.swiftLint,
76112
])
77113

78-
// Set the targets
79-
package.targets = targets
114+
// MARK: - Internal Dependencies
115+
extension Target.Dependency {
116+
static let cache: Target.Dependency = .target(
117+
name: Cache
118+
)
119+
static let protected: Target.Dependency = .target(
120+
name: Protected
121+
)
122+
static let extensions: Target.Dependency = .target(
123+
name: Extensions
124+
)
125+
static let environmentProviders: Target.Dependency = .target(
126+
name: EnvironmentProviders
127+
)
128+
static let shortID: Target.Dependency = .target(
129+
name: ShortID
130+
)
131+
}
132+
133+
// MARK: - 3rd Party Dependencies
134+
extension Target.Dependency {
135+
static let dependencies: Target.Dependency = .product(
136+
name: "Dependencies", package: "swift-composable-architecture"
137+
)
138+
static let orderedCollection: Target.Dependency = .product(
139+
name: "OrderedCollections", package: "swift-collections"
140+
)
141+
static let deque: Target.Dependency = .product(
142+
name: "DequeModule", package: "swift-collections"
143+
)
144+
static let xctestDynamicOverlay: Target.Dependency = .product(
145+
name: "XCTestDynamicOverlay", package: "xctest-dynamic-overlay"
146+
)
147+
}
80148

149+
// MARK: - Plugin Usages
150+
extension Target.PluginUsage {
151+
static let swiftLint: Target.PluginUsage = .plugin(
152+
name: "SwiftLint", package: "danthorpe-plugins"
153+
)
154+
}
81155

82156
// MARK: - Helpers
83157

Sources/Cache/Cache.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import AsyncAlgorithms
21
import Combine
32
import Extensions
43
import DequeModule
@@ -15,6 +14,7 @@ import UIKit
1514
import AppKit
1615
#endif
1716

17+
@available(iOS 15.0, *)
1818
public actor Cache<Key: Hashable, Value> {
1919
public typealias Storage = [Key: CachedValue]
2020

@@ -134,6 +134,7 @@ public actor Cache<Key: Hashable, Value> {
134134
}
135135

136136
// MARK: - Nested Types
137+
@available(iOS 15.0, *)
137138
extension Cache {
138139
public struct CachedValue {
139140
public let value: Value
@@ -148,10 +149,12 @@ extension Cache {
148149
}
149150
}
150151

152+
@available(iOS 15.0, *)
151153
extension Cache.CachedValue: Codable where Value: Codable { }
152154

153155
// MARK: - Public API
154156

157+
@available(iOS 15.0, *)
155158
public extension Cache {
156159

157160
var events: some AsyncSequence {
@@ -178,6 +181,7 @@ public extension Cache {
178181

179182
// MARK: - Private API
180183

184+
@available(iOS 15.0, *)
181185
private extension Cache {
182186

183187
func cachedValue(forKey key: Key) -> CachedValue? {
@@ -229,6 +233,7 @@ private extension Cache {
229233

230234
// MARK: - Other Implementation Details
231235

236+
@available(iOS 15.0, *)
232237
extension Cache.SystemEvent {
233238

234239
static func publisher(notificationCenter center: NotificationCenter = .default) -> AnyPublisher<Self, Never> {
@@ -266,6 +271,7 @@ extension Cache.SystemEvent {
266271
}
267272
}
268273

274+
@available(iOS 15.0, *)
269275
extension Cache.EvictionEvent: CustomStringConvertible {
270276

271277
public var description: String {

Sources/ReachabilityLive/Live.swift renamed to Sources/Reachability/Reachability+LiveKey.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Combine
2+
import Dependencies
23
import Foundation
34
import Network
4-
import Reachability
55

66
@available(iOS 13.0, *)
77
@available(macOS 10.15, *)
@@ -51,3 +51,7 @@ extension Reachability.Path {
5151
self.init(status: .init(rawValue: rawValue.status))
5252
}
5353
}
54+
55+
extension Reachability: DependencyKey {
56+
static public let liveValue: Reachability = .live
57+
}

Sources/ReachabilityMocks/Mocks.swift renamed to Sources/Reachability/Reachability+TestKey.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Combine
2+
import Dependencies
23
import Foundation
3-
import Reachability
4+
import XCTestDynamicOverlay
45

56
@available(iOS 13.0, *)
67
@available(macOS 10.15, *)
@@ -32,3 +33,8 @@ public extension Reachability {
3233
.eraseToAnyPublisher()
3334
)
3435
}
36+
37+
extension Reachability: TestDependencyKey {
38+
static public let testValue: Reachability = .satisfied
39+
static public let previewValue: Reachability = .unsatisfied
40+
}

0 commit comments

Comments
 (0)