The new command plugins are great, and I like the idea that a package manifest can include all the instructions it needs for building associated tools.
However, there is a category of tools - such as code formatters - that are potentially useful for any package, but are only really needed by the package developer.
Whilst an argument could be made for these tools just being installed some other way, I do think that there are compelling reasons for them being attached to the manifest.
Unfortunately adding these tools to the package is problematic as it introduces unnecessary dependencies for clients of the package.
There are potentially multiple solutions to this problem, but one practical solution that I've currently settled on is to conditionalise the dependency based on an condition which is only true when running swift package plugin ...
.
Currently I'm having to do this with an environment variable that I set externally before invoking swift
:
import Foundation
if ProcessInfo.processInfo.environment["RESOLVE_COMMAND_PLUGINS"] != nil {
package.dependencies.append(contentsOf: [
.package(url: "https://github.com/elegantchaos/ActionBuilderPlugin.git", from: "1.0.3"),
.package(url: "https://github.com/elegantchaos/SwiftFormatterPlugin.git", from: "1.0.2")
])
}
It would be better if SPM managed this itself, such that I could write something along the lines of:
import Foundation
if package.isBuildingCommands {
package.dependencies.append(contentsOf: [
.package(url: "https://github.com/elegantchaos/ActionBuilderPlugin.git", from: "1.0.3"),
.package(url: "https://github.com/elegantchaos/SwiftFormatterPlugin.git", from: "1.0.2")
])
}
Is this worth pitching? Is there another workaround already? Or something planned in a future evolution proposal?