gnomod

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2024 License: UNKNOWN not legal advice Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrGnoModNotFound = errors.New("gno.mod file not found in current or any parent directory")

ErrGnoModNotFound is returned by FindRootDir when, even after traversing up to the root directory, a gno.mod file could not be found.

Functions

func CreateGnoModFile

func CreateGnoModFile(rootDir, modPath string) error

func FindRootDir

func FindRootDir(absPath string) (string, error)

FindRootDir determines the root directory of the project which contains the gno.mod file. If no gno.mod file is found, ErrGnoModNotFound is returned. The given path must be absolute.

func ModCachePath

func ModCachePath() string

ModCachePath returns the path for gno modules

func ModulePath

func ModulePath(mod []byte) string

ModulePath returns the module path from the gomod file text. If it cannot find a module path, it returns an empty string. It is tolerant of unrelated problems in the go.mod file.

func PackageDir

func PackageDir(root string, v module.Version) string

PackageDir resolves a given module.Version to the path on the filesystem. If root is dir, it is defaulted to the value of ModCachePath.

Types

type File

type File struct {
	Draft   bool
	Module  *modfile.Module
	Go      *modfile.Go
	Require []*modfile.Require
	Replace []*modfile.Replace

	Syntax *modfile.FileSyntax
}

Parsed gno.mod file.

func GnoToGoMod

func GnoToGoMod(f File) (*File, error)

GnoToGoMod make necessary modifications in the gno.mod and return go.mod file.

func Parse

func Parse(file string, data []byte) (*File, error)

Parse parses and returns a gno.mod file.

- file is the name of the file, used in positions and errors. - data is the content of the file.

func ParseAt

func ParseAt(dir string) (*File, error)

ParseAt parses, validates and returns a gno.mod file located at dir or at dir's parents.

func ParseGnoMod

func ParseGnoMod(fname string) (*File, error)

tries to parse gno mod file given the filename, using Parse and Validate from the gnomod package

TODO(tb): replace by `gnomod.ParseAt` ? The key difference is the latter looks for gno.mod in parent directories, while this function doesn't.

func (*File) AddComment

func (f *File) AddComment(text string)

func (*File) AddModuleStmt

func (f *File) AddModuleStmt(path string) error

func (*File) AddNewRequire

func (f *File) AddNewRequire(path, vers string, indirect bool)

AddNewRequire adds a new require line for path at version vers at the end of the last require block, regardless of any existing require lines for path.

func (*File) AddReplace

func (f *File) AddReplace(oldPath, oldVers, newPath, newVers string) error

func (*File) AddRequire

func (f *File) AddRequire(path, vers string) error

AddRequire sets the first require line for path to version vers, preserving any existing comments for that line and removing all other lines for path.

If no line currently exists for path, AddRequire adds a new line at the end of the last require block.

func (*File) DropReplace

func (f *File) DropReplace(oldPath, oldVers string) error

func (*File) DropRequire

func (f *File) DropRequire(path string) error

func (*File) FetchDeps

func (f *File) FetchDeps(path string, remote string, verbose bool) error

FetchDeps fetches and writes gno.mod packages in GOPATH/pkg/gnomod/

func (*File) Resolve

func (f *File) Resolve(r *modfile.Require) module.Version

Resolve takes a Require directive from File and returns any adequate replacement following the Replace directives.

func (*File) Sanitize

func (f *File) Sanitize()

func (*File) Validate

func (f *File) Validate() error

Validate validates gno.mod

func (*File) Write

func (f *File) Write(fname string) error

writes file to the given absolute file path

type Pkg

type Pkg struct {
	Dir      string   // absolute path to package dir
	Name     string   // package name
	Requires []string // dependencies
	Draft    bool     // whether the package is a draft
}

type PkgList

type PkgList []Pkg

func ListPkgs

func ListPkgs(root string) (PkgList, error)

ListPkgs lists all gno packages in the given root directory.

func (PkgList) Sort

func (pl PkgList) Sort() (SortedPkgList, error)

sortPkgs sorts the given packages by their dependencies.

type SortedPkgList

type SortedPkgList []Pkg

func (SortedPkgList) GetNonDraftPkgs

func (sp SortedPkgList) GetNonDraftPkgs() SortedPkgList

GetNonDraftPkgs returns packages that are not draft and have no direct or indirect draft dependencies.

type SubPkg

type SubPkg struct {
	Dir        string   // absolute path to package dir
	ImportPath string   // import path of package
	Root       string   // Root dir containing this package, i.e dir containing gno.mod file
	Imports    []string // imports used by this package

	GnoFiles         []string // .gno source files (excluding TestGnoFiles, FiletestGnoFiles)
	TestGnoFiles     []string // _test.gno source files
	FiletestGnoFiles []string // _filetest.gno source files
}

func GnoFileSubPkg

func GnoFileSubPkg(files []string) (*SubPkg, error)

GnoFileSubPkg returns a subpackage from the given .gno files.

func SubPkgsFromPaths

func SubPkgsFromPaths(paths []string) ([]*SubPkg, error)

SubPkgsFromPaths returns a list of subpackages from the given paths.

Jump to

Keyboard shortcuts

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