Open hi2gage opened 1 month ago
@bnbarham Just wanted to bump this.
Thanks @hi2gage! Definitely valuable to support relative paths here.
Due to access level and not wanting to make certain enums public, I opted to use MappablePackageDependency instead of Package.Dependency to represent the values coming from the CLI command.
Which enums would those be? Ideally
MappablePackageDependency
would not be public, it really shouldn't be visible to commands.
@bnbarham No problem!
I thought I would need to make Package.Dependency.SourceControlRequirement
and Package.Dependency.RegistryRequirement
public, but I avoided doing so because of these comments:
// intentionally private to hide enum detail
private static func package(
name: String? = nil,
url: String,
requirement: Package.Dependency.SourceControlRequirement
) -> Package.Dependency {
return .init(name: name, location: url, requirement: requirement, traits: nil)
}
but looking back over this again I realized this was written prior to the package
access level being introduced. Any reason to not move these 3 functions from private
-> package
?
It would really simplify this PR to not use MappablePackageDependency
as you mentioned.
I thought I would need to make Package.Dependency.SourceControlRequirement and Package.Dependency.RegistryRequirement public, but I avoided doing so because of these comments:
Aren't they already 🤔? I assume the issue was that there's no way to create a Dependency
with them today, but couldn't you call the existing initializers (which end up mapping to these)?
Any reason to not move these 3 functions from private -> package?
If they need to be (depending on the above) - they just can't be public as this is the package manifest API.
Hey @bnbarham I just pushed up the changes to use Package.Dependency
so we can talk specifics.
I thought I would need to make Package.Dependency.SourceControlRequirement and Package.Dependency.RegistryRequirement public, but I avoided doing so because of these comments:
Aren't they already 🤔?
Yes they are public 🤦I meant to say: I thought I would need to make the Dependency initializers that contain those enums public. Not the enums themselves public.
I assume the issue was that there's no way to create a
Dependency
with them today, but couldn't you call the existing initializers (which end up mapping to these)?
Technically I could call the existing initializers, but it requires some funky switching. The changes I just pushed uses the existing initializers. So let me know what you think about that.
This being said if I made those initializers package
access level I could take this code:
let packageDependency: PackageDescription.Package.Dependency
switch (firstRequirement, to) {
case (let .exact(version), nil):
packageDependency = .package(url: self.dependency, exact: version)
case (let .range(range), let to?):
packageDependency = .package(url: self.dependency, (range.lowerBound ..< to))
case (let .range(range), nil):
packageDependency = .package(url: self.dependency, range)
case (let .revision(revision), nil):
packageDependency = .package(url: self.dependency, revision: revision)
case (let .branch(branch), nil):
packageDependency = .package(url: self.dependency, branch: branch)
case (.branch, _?), (.revision, _?), (.exact, _?):
throw StringError("--to can only be specified with --from or --up-to-next-minor-from")
case (_, _):
throw StringError("unknown requirement")
}
->
let packageDependency2: PackageDescription.Package.Dependency = .package(
url: self.dependency,
requirement: requirement,
traits: []
)
Any reason to not move these 3 functions from private -> package?
If they need to be (depending on the above) - they just can't be public as this is the package manifest API.
Agreed, they can't be public, making them package would be helpful but we can get around it if you want to keep those initializers locked down.
I'd be fine making them package
, especially to avoid that switch
😅 . @dschaefer2 / @plemarquand any opinions?
I'd be fine making them
package
, especially to avoid thatswitch
😅 . @dschaefer2 / @plemarquand any opinions?
Great! I just pushed up changes making those package
.
Enable passing relative path into
swift package add-dependency
Motivation:
Currently only
AbsolutePath
s are supported with--type path
flagThere is a need to support
RelativePath
because it's not uncommon to have a package structure inside of an xcodeproj as shown below.If we want to open
ParentPackage
by itself, it will not be able to resolve that package.This pr allows for the user to add a package with a
RelativePath
path via theswift package add-dependency --type path
command.Access level for
.package(name:url:requirement:traits:)
.package(name:url:requirement:)
.package(id:requirement:traits:)
were upgraded from
private
topackage
allowing access to these functions from thePackageCommands
module.Modifications:
swift package add-dependency
Result:
Both of the following commands are valid