modfile

package
v0.17.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 16, 2026 License: Apache-2.0 Imports: 16 Imported by: 8

Documentation

Overview

Package modfile provides functionality for reading and parsing the CUE module file, cue.mod/module.cue.

WARNING: THIS PACKAGE IS EXPERIMENTAL. ITS API MAY CHANGE AT ANY TIME.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoLanguageVersion = fmt.Errorf("no language version declared in module.cue")

ErrNoLanguageVersion is returned by Parse and ParseNonStrict when a cue.mod/module.cue file lacks the `language.version` field.

Functions

func EarliestClosedSchemaVersion added in v0.9.0

func EarliestClosedSchemaVersion() string

EarliestClosedSchemaVersion returns the earliest module.cue schema version that excludes unknown fields. Any version declared in a module.cue file should be at least this, because that's when we added the language.version field itself.

func Format added in v0.14.0

func Format(f *File) ([]byte, error)

Format returns a formatted representation of f in CUE syntax.

func FormatLocal added in v0.17.0

func FormatLocal(f, base *File) ([]byte, error)

FormatLocal formats f as a cue.mod/local-module.cue file: a deps-only document that omits the module path and language version, which a local-module.cue file inherits from the accompanying module.cue file.

base is the accompanying cue.mod/module.cue file (the published view). Its language version is used to validate the formatted result via ParseLocal. A dependency's version is omitted from the output whenever it is identical to that module's version in base, and its default field is omitted whenever base already marks the same module as the default; ParseLocal restores both from base when reading the file back.

Types

type Dep

type Dep = modfiledata.Dep

type File

type File = modfiledata.File

File represents the contents of a cue.mod/module.cue file.

func FixLegacy added in v0.9.0

func FixLegacy(modfile []byte, filename string) (*File, error)

FixLegacy converts a legacy module.cue file as parsed by ParseLegacy into a format suitable for parsing with Parse. It adds a language.version field and moves all unrecognized fields into custom.legacy.

If there is no module field or it is empty, it is set to "test.example".

If the file already parses OK with ParseNonStrict, it returns the result of that.

func Parse

func Parse(modfile []byte, filename string) (*File, error)

Parse verifies that the module file has correct syntax and follows the schema following the required language.version field. The file name is used for error messages. All dependencies must be specified correctly: with major versions in the module paths and canonical dependency versions.

func ParseLegacy

func ParseLegacy(modfile []byte, filename string) (*File, error)

ParseLegacy parses the legacy version of the module file that only supports the single field "module" and ignores all other fields.

func ParseLocal added in v0.17.0

func ParseLocal(data []byte, filename string, base *File) (*File, error)

ParseLocal parses a cue.mod/local-module.cue file, which holds the main-module view of dependencies, including any module replaces.

A local-module.cue file does not declare a module path or language version of its own; these are inherited from base, the already-parsed cue.mod/module.cue file. (The parameter is named base rather than main because "main module" denotes the mode that local-module.cue applies to.)

ParseLocal returns the effective main-module file: its identity (module, language, source and custom data) is taken from base, while its dependencies are taken from the local file. If the local file declares a module path that differs from base's, an error is returned.

The file name is used for error messages.

func ParseNonStrict

func ParseNonStrict(modfile []byte, filename string) (*File, error)

ParseNonStrict is like Parse but allows some laxity in the parsing:

  • if a module path lacks a version, it's taken from the version.
  • if a non-canonical version is used, it will be canonicalized.

The file name is used for error messages.

type Language

type Language = modfiledata.Language

type Source added in v0.9.0

type Source = modfiledata.Source

Source represents how to transform from a module's source to its actual contents.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL