Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify alpha version of a module in Package.swift?

I want to add a library called Markdown for my Swift project, which is a server-side build on Vapor.

However, it seems that the library have ditched supporting Swift 2.x, and now the latest version is 1.0.0-alpha, which is based on Swift 3.x.

Since my project is based on Swift 3.x, I want to fetch the library. The document says the following:

.Package(url: "https://github.com/crossroadlabs/Markdown.git", majorVersion: 0)

However, how can I specify the alpha version of the module in Package.swift?

like image 615
Blaszard Avatar asked Feb 05 '23 22:02

Blaszard


1 Answers

You can specify version tag with prereleaseIdentifiers

Package(url: "http://...", "1.0.0-alpha")

More Info
The Package Dependency has many convenience initializers

.Package(url: String, versions: Range<Version>)
.Package(url: String, versions: ClosedRange<Version>)
.Package(url: String, majorVersion: Int)
.Package(url: String, majorVersion: Int, minor: Int)
.Package(url: String, _ version: Version)

Use examples:

.Package(url: "https://github.com/Markdown.git", versions: Version(1,0,0)..<Version(2,0,0))
.Package(url: "https://github.com/Markdown.git", majorVersion: 1)
.Package(url: "https://github.com/Markdown.git", majorVersion: 1, minor: 4)
.Package(url: "http://github.com/Markdown.git", Version(1,0,0))
.Package(url: "http://github.com/Markdown.git", "1.0.0")

The Version struct follows semantic versioning and has following format.

Version(
    _ major: Int,
    _ minor: Int,
    _ patch: Int,
    prereleaseIdentifiers: [String] = [],
    buildMetadataIdentifier: String? = nil
)

When making a Version instance you can also specify prerelease and buildMetadata identifiers

Version(0,1,0, prereleaseIdentifiers: ["alpha"], buildMetadataIdentifier: "10")

You can find more in Swift Package Manager repo

like image 83
Kostiantyn Koval Avatar answered Mar 11 '23 00:03

Kostiantyn Koval