Skip to content

Commit

Permalink
Updates plugins (#20)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
danthorpe and danthorpe authored Oct 25, 2022
1 parent 35926ec commit fa6c6d1
Show file tree
Hide file tree
Showing 8 changed files with 256 additions and 99 deletions.
184 changes: 129 additions & 55 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,77 +7,151 @@ var package = Package(name: "danthorpe-utilities")

package.platforms = [
.macOS(.v12),
.iOS(.v15),
.tvOS(.v15),
.watchOS(.v8)
.iOS(.v14),
.tvOS(.v14),
.watchOS(.v7)
]

// MARK: - Products

package.products = [
.library(name: "Cache", targets: ["Cache"]),
.library(name: "EnvironmentProviders", targets: ["EnvironmentProviders"]),
.library(name: "FileManagerClient", targets: ["FileManagerClient"]),
.library(name: "Reachability", targets: ["ReachabilityLive"]),
.library(name: "ReachabilityMocks", targets: ["ReachabilityMocks"]),
.library(name: "ShortID", targets: ["ShortID"]),
.library(name: "Utilities", targets: ["Cache", "ReachabilityLive", "ShortID"]),
]

// MARK: - Dependencies
// MARK: - External Dependencies

package.dependencies = [
.package(url: "https://github.com/apple/swift-argument-parser.git", branch: "main"),
.package(url: "https://github.com/apple/swift-async-algorithms", branch: "main"),
.package(url: "https://github.com/apple/swift-collections", from: "1.0.2"),
.package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "0.2.1"),
.package(url: "https://github.com/danthorpe/danthorpe-plugins", branch: "main"),
.package(url: "https://github.com/danthorpe/danthorpe-plugins", from: "0.2.0"),
.package(url: "https://github.com/pointfreeco/swift-composable-architecture", from: "0.44.0"),
.package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "0.5.0"),
]

// MARK: - Targets

var targets: [Target] = [

.target(
name: "Cache",
dependencies: [
"Extensions",
"EnvironmentProviders",
.product(name: "AsyncAlgorithms", package: "swift-async-algorithms"),
.product(name: "OrderedCollections", package: "swift-collections"),
.product(name: "DequeModule", package: "swift-collections"),
]
),

.target(name: "Extensions"),

.target(name: "EnvironmentProviders"),

.target(name: "FileManagerClient", dependencies: [
.product(name: "XCTestDynamicOverlay", package: "xctest-dynamic-overlay")
]),
// MARK: - Name
let Cache = "Cache"
let EnvironmentProviders = "EnvironmentProviders"
let Extensions = "Extensions"
let FileManagerClient = "FileManagerClient"
let Protected = "Protected"
let Reachability = "Reachability"
let ShortID = "ShortID"
let Utilities = "Utilities"

private extension String {
var tests: String { "\(self)Tests" }
var mocks: String { "\(self)Mocks" }
var live: String { "\(self)Live" }
}

.target(name: "Reachability"),
.target(name: "ReachabilityLive", dependencies: ["Reachability"]),
.target(name: "ReachabilityMocks", dependencies: ["Reachability"]),
// MARK: - Products

.target(name: "ShortID", dependencies: ["Concurrency"]),
package.products = [
.library(name: Cache, targets: [Cache]),
.library(name: EnvironmentProviders, targets: [EnvironmentProviders]),
.library(name: FileManagerClient, targets: [FileManagerClient]),
.library(name: Protected, targets: [Protected]),
.library(name: Reachability, targets: [Reachability]),
.library(name: ShortID, targets: [ShortID]),
]

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

.testTarget(name: "CacheTests", dependencies: ["Cache"]),
.testTarget(name: "ConcurrencyTests", dependencies: ["Concurrency"]),
.testTarget(name: "ShortIDTests", dependencies: ["ShortID"]),
]
extension Target {
static let cache: Target = .target(
name: Cache,
dependencies: [
.extensions,
.environmentProviders,
.orderedCollection,
.deque
]
)
static let cacheTests: Target = .testTarget(
name: Cache.tests,
dependencies: [ .cache ]
)
static let protected: Target = .target(
name: Protected
)
static let protectedTests: Target = .testTarget(
name: Protected.tests,
dependencies: [ .protected ]
)
static let extensions: Target = .target(
name: Extensions
)
static let environmentProviders: Target = .target(
name: EnvironmentProviders
)
static let fileManagerClient: Target = .target(
name: FileManagerClient,
dependencies: [ .xctestDynamicOverlay ]
)
static let reachability: Target = .target(
name: Reachability,
dependencies: [ .dependencies, .xctestDynamicOverlay ]
)
static let shortID: Target = .target(
name: ShortID,
dependencies: [ .dependencies, .protected ]
)
static let shortIDTests: Target = .testTarget(
name: ShortID.tests,
dependencies: [ .shortID ]
)
}

// Set SwiftLint plugin
targets = targets.update(.regular, .test, plugins: [
.plugin(name: "SwiftLintPlugin", package: "danthorpe-plugins"),
package.targets = [
.cache,
.cacheTests,
.protected,
.protectedTests,
.extensions,
.environmentProviders,
.fileManagerClient,
.reachability,
.shortID,
.shortIDTests
].update(.regular, .test, plugins: [
.swiftLint,
])

// Set the targets
package.targets = targets
// MARK: - Internal Dependencies
extension Target.Dependency {
static let cache: Target.Dependency = .target(
name: Cache
)
static let protected: Target.Dependency = .target(
name: Protected
)
static let extensions: Target.Dependency = .target(
name: Extensions
)
static let environmentProviders: Target.Dependency = .target(
name: EnvironmentProviders
)
static let shortID: Target.Dependency = .target(
name: ShortID
)
}

// MARK: - 3rd Party Dependencies
extension Target.Dependency {
static let dependencies: Target.Dependency = .product(
name: "Dependencies", package: "swift-composable-architecture"
)
static let orderedCollection: Target.Dependency = .product(
name: "OrderedCollections", package: "swift-collections"
)
static let deque: Target.Dependency = .product(
name: "DequeModule", package: "swift-collections"
)
static let xctestDynamicOverlay: Target.Dependency = .product(
name: "XCTestDynamicOverlay", package: "xctest-dynamic-overlay"
)
}

// MARK: - Plugin Usages
extension Target.PluginUsage {
static let swiftLint: Target.PluginUsage = .plugin(
name: "SwiftLint", package: "danthorpe-plugins"
)
}

// MARK: - Helpers

Expand Down
8 changes: 7 additions & 1 deletion Sources/Cache/Cache.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import AsyncAlgorithms
import Combine
import Extensions
import DequeModule
Expand All @@ -15,6 +14,7 @@ import UIKit
import AppKit
#endif

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

Expand Down Expand Up @@ -134,6 +134,7 @@ public actor Cache<Key: Hashable, Value> {
}

// MARK: - Nested Types
@available(iOS 15.0, *)
extension Cache {
public struct CachedValue {
public let value: Value
Expand All @@ -148,10 +149,12 @@ extension Cache {
}
}

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

// MARK: - Public API

@available(iOS 15.0, *)
public extension Cache {

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

// MARK: - Private API

@available(iOS 15.0, *)
private extension Cache {

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

// MARK: - Other Implementation Details

@available(iOS 15.0, *)
extension Cache.SystemEvent {

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

@available(iOS 15.0, *)
extension Cache.EvictionEvent: CustomStringConvertible {

public var description: String {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Combine
import Dependencies
import Foundation
import Network
import Reachability

@available(iOS 13.0, *)
@available(macOS 10.15, *)
Expand Down Expand Up @@ -51,3 +51,7 @@ extension Reachability.Path {
self.init(status: .init(rawValue: rawValue.status))
}
}

extension Reachability: DependencyKey {
static public let liveValue: Reachability = .live
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Combine
import Dependencies
import Foundation
import Reachability
import XCTestDynamicOverlay

@available(iOS 13.0, *)
@available(macOS 10.15, *)
Expand Down Expand Up @@ -32,3 +33,8 @@ public extension Reachability {
.eraseToAnyPublisher()
)
}

extension Reachability: TestDependencyKey {
static public let testValue: Reachability = .satisfied
static public let previewValue: Reachability = .unsatisfied
}
Loading

0 comments on commit fa6c6d1

Please sign in to comment.