std.package

ExactSemverReq

A contract for exact semantic version ("semver") requirements, structured as a record.

An exact semver requirement looks like "=1.2.3" or "=1.2.3-rc1": it starts with an equals sign, must contain major, minor, and patch versions, and may contain a prerelease specifier.

This is a normalizing contract, which accepts either a string to be parsed or a record. If a string is provided, it will be parsed into a record (in the std.package.structured.ExactSemverReq format).


GitDependency

A contract identifying a dependency that can be fetched from a git repository.


GitDependency.path

Contract
String

The path of the nickel package within the git repository. If omitted, the nickel package is at the root of the git repository.


GitDependency.ref

Contract
[| 'Head, 'Branch String, 'Tag String, 'Commit std.package.GitId |]

The git ref to fetch from the repository.

If not provided, defaults to 'Head.


GitDependency.url

Contract
String

The url of a git repository.

This supports local file paths, https urls like https://example.com/example-repo, and ssh urls like user@example.com:repo.


GitId

A full git commit id. That is, a 160-bit SHA-1 hash as a lower-case hexadecimal string.

Examples

"0c0a82aa4a05cd84ba089bdba2e6a1048058f41b" | GitId
# =>  "0c0a82aa4a05cd84ba089bdba2e6a1048058f41b"

IndexDependency

A contract identifying a dependency that can be fetched from a package index.


IndexDependency.package

Contract
PackageId

The dependency's identifier within the package index, in the format "github:<organization>/<repository>".


IndexDependency.version

Contract
SemverReq

The required version of the package.

Nickel supports two kinds of requirements: semver-compatible requirements and exact version requirements. Semver-compatible requirements take the form "major.minor.patch", where minor and patch are optional. Their semantics are:

  • "1.2.3" will match all versions having major version 1, minor version 2, and patch version at least 3.
  • "1.2" will match all versions having major version 1 and minor version at least 2.
  • "1" will match all versions having major version 1.
  • a semver-compatible requirement will never match a prerelease version.

Exact version requirements take the form "=major.minor.patch-pre", where the prerelease tag is optional, but major, minor, and patch are all required.


Manifest

A contract for a Nickel package manifest.

Example

{
  name = "my-package",
  version = "1.0.0",
  minimal_nickel_version = "1.10",
  authors = ["Me <me@example.com>"],
  description = "My great package",

  dependencies = {
    my_local_dep = 'Path "../somewhere",
    git_dep = 'Git { url = "https://example.com/repo", ref = 'Tag "v1.0" },
    index_dep = 'Index { package = "github:nickel-lang/example", version = "1.0" },
  },
} | std.package.Manifest

Manifest.authors

Contract
Array String

The authors of this package.


Manifest.dependencies

Contract
{ _ : [| 'Path String, 'Git std.package.GitDependency, 'Index std.package.IndexDependency |] }
Contract
std.record.FieldsMatch "^_*[a-zA-Z][_a-zA-Z0-9-']*$"

A dictionary of package dependencies, keyed by the name that this package uses to refer to them locally.

The names must be valid Nickel identifiers.


Manifest.description

Contract
String

A description of this package.


Manifest.keywords

Contract
Array String

A list of keywords to help people find this package.


Manifest.license

Contract
String

The name of the license that this package is available under.

This is a completely free-form string, but some tooling may impose restrictions. For example, if you want to publish your package in Nickel's global package registry, the license field needs to be a valid SPDX license expression that allows redistribution.


Manifest.minimal_nickel_version

Contract
String
Contract
SemverPrefix

The minimal nickel version required for this package.


Manifest.name

Contract
String

The name of this package.


Manifest.version

Contract
String
Contract
Semver

The version of this package.

Any semantic version is accepted, but the build metadata field has no effect when matching versions.


PackageId

A contract for ids of packages in the global package index.

This is a normalizing contract, which accepts either a string to be parsed or a record. If a string is provided, it will be parsed into a record (in the std.package.structured.PackageId format).

Valid strings are of the format github:<owner>/<repo> or github:<owner>/<repo>/<path>, where <owner> and <repo> are strings made up of characters that are valid in GitHub usernames (i.e., alphanumeric, _, -, or .).

Examples

"github:nickel-lang/json-schema-lib" | std.package.PackageId
# => 'Github { org = "nickel-lang", name = "json-schema-lib" }

"github:nickel-lang/json-schema-to-nickel/lib" | std.package.PackageId
# => 'Github { org = "nickel-lang", name = "json-schema-to-nickel", path="lib" }

"github:not-enough-slashes" | std.package.PackageId
# => error

"codeberg:not-yet/supported" | std.package.PackageId
# => error

Semver

A contract for semantic version ("semver") identifiers.

This is a normalizing contract, which accepts either a string to be parsed or a record. If a string is provided, it will be parsed into a record (in the std.package.structured.Semver format).

Examples

"1.2.0-pre1" | std.package.Semver
# => { major = 1, minor = 2, patch = 0, pre = "pre1", }

{ major = 1, minor = 2, patch = 0 } | std.package.Semver
# => { major = 1, minor = 2, patch = 0, }

{ major = 1, minor = 2 } | std.package.Semver
# => error: missing definition

"1.foo" | std.package.Semver
# => error: contract broken by a value

SemverPrefix

A contract for semantic version ("semver") prefixes.

This prefix must contain a major version number. It may contain a minor version and a patch version, but it must not contain a prerelease version or build metadata.

This is a normalizing contract, which accepts either a string to be parsed or a record. If a string is provided, it will be parsed into a record (in the std.package.structured.SemverPrefix format).

Examples

"1.2" | std.package.SemverPrefix
# => { major = 1, minor = 2 }

{ major = 1, minor = 2 } | std.package.SemverPrefix
# => { major = 1, minor = 2 }

"1.foo" | std.package.SemverPrefix
# => error: contract broken by a value

SemverReq

A contract for semantic version ("semver") requirements.

This is a normalizing contract, which accepts either a string to be parsed or a record. If a string is provided, it will be parsed into a record (in the std.package.structured.SemverReq format).

Nickel supports two kinds of requirements: semver-compatible requirements and exact version requirements. Semver-compatible requirements take the form "major.minor.patch", where minor and patch are optional. Their semantics are:

  • "1.2.3" will match all versions having major version 1, minor version 2, and patch version at least 3.
  • "1.2" will match all versions having major version 1 and minor version at least 2.
  • "1" will match all versions having major version 1.
  • a semver-compatible requirement will never match a prerelease version.

Exact version requirements take the form "=major.minor.patch-pre", where the prerelease tag is optional, but major, minor, and patch are all required.

Examples

"1.2" | SemverReq
# => 'Compatible { major = 1, minor = 2 }

"=1.2" | SemverReq
# => error: contract broken by a value

"1.2.0" | SemverReq
# => 'Compatible { major = 1, minor = 2, patch = 0 }

"=1.2.0" | SemverReq
# => 'Exact { major = 1, minor = 2, patch = 0, }

"1.2.0-pre1" | SemverReq
# => error: contract broken by a value

"=1.2.0-pre1" | SemverReq
# => 'Exact { major = 1, minor = 2, patch = 0, pre = "pre1", }

structured


structured.ExactSemverReq

A contract for exact semantic version ("semver") requirements, structured as a record.

This differs from std.package.structured.Semver in that it lacks a build metadata field.


structured.ExactSemverReq.major

Contract
number.Nat

The major version number.


structured.ExactSemverReq.minor

Contract
number.Nat

The minor version number.


structured.ExactSemverReq.patch

Contract
number.Nat

The patch version.


structured.ExactSemverReq.pre

Contract
String

The prerelease identifier.


structured.PackageId

Identifies a package in the global package index.


structured.Semver

A contract for semantic version ("semver") identifiers, structured as a record.

See also std.package.Semver, which can produce one of these by parsing a string.


structured.Semver.build

Contract
String

The build metadata.

This is completely ignored while comparing versions for compatibility.


structured.Semver.major

Contract
number.Nat

The major version number.


structured.Semver.minor

Contract
number.Nat

The minor version number.


structured.Semver.patch

Contract
number.Nat

The patch version.


structured.Semver.pre

Contract
String

The prerelease identifier.

When comparing versions for compatibility, non-empty prerelease strings only match one another if they are exactly equal. See std.package.SemverReq for more details


structured.SemverPrefix

A contract for semantic version ("semver") prefixes, structured as a record.


structured.SemverPrefix.major

Contract
number.Nat

The major version number.


structured.SemverPrefix.minor

Contract
number.Nat

The minor version number.


structured.SemverPrefix.patch

Contract
number.Nat

The patch version.


structured.SemverReq