Skip to content

Commit 680659b

Browse files
committed
[SwiftRefactor] PackageManifest: Make a couple of properties externally accessible
In it's current state `AddPackageTarget` does multiple things: 1. Updates the manifest to introduce new targets and dependencies. 2. Generates one or more auxiliary files depending on the type of target being added (i.e. a primary file for the target and sometimes a macro specific defintions file). We'd like to scope the refactoring action down to manifest updates only. The callers are going to be resposble for #2 from the list. In order to do that `PackageTarget.sanitizedName` and `PackageTarget.Dependency.name` have to be externally accessible (under `@_spi(PackageRefactor)` still) to form the content of the file.
1 parent 1d458d9 commit 680659b

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

Sources/SwiftRefactor/PackageManifest/AddPackageTarget.swift

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -295,18 +295,6 @@ public struct AddPackageTarget: ManifestEditRefactoringProvider {
295295
}
296296
}
297297

298-
fileprivate extension PackageTarget.Dependency {
299-
/// Retrieve the name of the dependency
300-
var name: String {
301-
switch self {
302-
case .target(let name),
303-
.byName(let name),
304-
.product(let name, package: _):
305-
return name
306-
}
307-
}
308-
}
309-
310298
/// The array of auxiliary files that can be added by a package editing
311299
/// operation.
312300
private typealias AuxiliaryFiles = [(String, SourceFileSyntax)]
@@ -346,7 +334,8 @@ fileprivate extension PackageDependency {
346334
}
347335
}
348336

349-
fileprivate extension PackageTarget {
337+
@_spi(PackageRefactor)
338+
public extension PackageTarget {
350339
var sanitizedName: String {
351340
name
352341
.mangledToC99ExtendedIdentifier()

Sources/SwiftRefactor/PackageManifest/PackageTarget.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,16 @@ public struct PackageTarget {
5151
case byName(name: String)
5252
case target(name: String)
5353
case product(name: String, package: String?)
54+
55+
/// Retrieve the name of the dependency
56+
public var name: String {
57+
switch self {
58+
case .byName(let name),
59+
.target(let name),
60+
.product(let name, package: _):
61+
return name
62+
}
63+
}
5464
}
5565

5666
public init(

0 commit comments

Comments
 (0)