packages

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2026 License: UNKNOWN not legal advice Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrPackageNotFound = errors.New("package not found")

ErrPackageNotFound is returned by Resolve when no index/FS/RPC lookup yielded the requested package path.

Functions

func CheckMissingExampleImports

func CheckMissingExampleImports(l *Loader, workspace string) []string

CheckMissingExampleImports walks the given workspace dir, parses every gno.land/* import declared in its packages, and returns the sorted, deduplicated list of imports unreachable via the loader's filesystem roots. Used when -no-examples is set to surface broken graphs at startup instead of letting them blow up at first query.

Stdlib imports are ignored. The check is FS-only and non-mutating: it never reaches the rpc fetcher and never writes to the loader's index or tracked sets, so it is safe to call before LoadWorkspace.

Returns nil if workspace is empty.

func FindWorkspace

func FindWorkspace(start string) string

FindWorkspace resolves the loader root for start, or "" when start is in neither a gnowork.toml workspace nor a gnomod.toml package directory (the caller then falls back to discovery mode). It delegates to gnovm's loader context so the workspace gnodev eager-loads is, by construction, one gnovm's own Load can satisfy — the two cannot drift on which markers define a root.

Types

type Config

type Config struct {
	// Workspace is the workspace root (dir containing gnowork.toml or gnomod.toml).
	// Empty if no workspace was detected.
	Workspace string

	// Examples, when true, includes $GNOROOT/examples in the lazy-loadable set.
	Examples bool

	// ExtraRoots are additional workspace roots supplied by the user.
	// Each must be an existing directory; invalid entries are skipped with a warning.
	ExtraRoots []string

	// ExcludeDirs is a set of directory paths to skip during scanRoot's
	// FS walk. Each entry, after filepath.Clean, is compared exactly
	// against directory paths emitted by the walker. The walker emits
	// paths in the form of the walked root (absolute when the root is
	// absolute), so entries should match that form. Empty entries are
	// ignored; entries that don't match any walked directory are no-ops.
	ExcludeDirs []string

	// GnoRoot is the installed gno root; defaults to gnoenv.RootDir().
	GnoRoot string

	// Remotes maps a chain domain (e.g. "gno.land") to the RPC URL used to
	// fetch that domain's packages. Remote fetching is opt-in per domain:
	// domains without an entry are never fetched, and an empty map disables
	// remote fetching entirely. Ignored when Fetcher is non-nil.
	Remotes map[string]string

	// Fetcher overrides the default rpcpkgfetcher. Primarily for tests that
	// use InMemoryFetcher. Leave nil in production.
	Fetcher pkgdownload.PackageFetcher

	// Logger is the slog logger used for all loader output.
	// Defaults to slog.Default() if nil.
	Logger *slog.Logger
}

Config configures the Loader.

type Kind

type Kind int

Kind classifies a package by where it lives. KindUnknown is the zero value: a package was constructed without an explicit Kind. FS packages are in a user workspace or extra root; Remote packages are fetched from a chain (RPC or modcache) and aren't user-editable.

const (
	KindUnknown Kind = iota
	KindFS
	KindRemote
)

type Loader

type Loader struct {
	// contains filtered or unexported fields
}

Loader resolves gnodev's package set using gnovm's native loader for bulk operations and a local per-path lookup (filesystem + PackageFetcher) for the proxy's lazy-resolve path.

func New

func New(cfg Config) *Loader

func (*Loader) AddLocalPackage

func (l *Loader) AddLocalPackage(importPath, dir string)

AddLocalPackage registers dir as the source of importPath for a dir that has no gnomod.toml — the `gnodev ./scratch-realm` flow, where the module path is generated from the directory name. The package is tracked so it reaches every reload, and ToMemPackage synthesizes the missing gnomod.toml at deploy time.

func (*Loader) LoadAll

func (l *Loader) LoadAll() ([]*Package, error)

LoadAll eagerly loads the workspace, every ExtraRoot, GNOROOT/examples (when Examples=true), and every tracked path. Used by the staging subcommand which wants to materialize every reachable package at startup. The returned slice is topologically sorted: dependencies precede dependents across all roots so genesis deploy can apply packages in order.

func (*Loader) LoadWorkspace

func (l *Loader) LoadWorkspace() ([]*Package, error)

LoadWorkspace eagerly loads packages in the configured workspace. Returns nil (no error) if no workspace is set.

func (*Loader) LookupFS

func (l *Loader) LookupFS(path string) bool

LookupFS reports whether path is reachable via the loader's filesystem roots (extra roots + GNOROOT/examples when enabled; the workspace is NOT consulted — it is covered by the eager load). Walks any root not yet cached. Does NOT consult the rpc fetcher and does NOT mutate l.index or l.tracked, so it is safe for diagnostic / pre-flight use.

func (*Loader) Reload

func (l *Loader) Reload() ([]*Package, error)

Reload re-runs the eager load for the workspace and every -extra-root; see reloadRoots.

func (*Loader) Resolve

func (l *Loader) Resolve(path string) (*Package, error)

Resolve returns a previously-seen Package if known, else tries FS and RPC lookups in order. Hits are memoized in the index and added to tracked.

Locking: fast path is RLock-only. The FS walk runs under the write lock (so the per-root index cache is built once). The RPC fetch runs WITHOUT the lock held, so a slow rpcLookup for one path does not block Resolve for unrelated paths. Two concurrent Resolve calls for the same missing path may both hit RPC; the second insert is a no-op via re-check.

func (*Loader) Track

func (l *Loader) Track(paths ...string)

Track registers paths to re-resolve on every Reload / LoadAll, exactly like paths previously seen by Resolve. Paths are not validated here: an unresolvable tracked path is warn-logged at reload time. Used for the -paths flag and -txs-file dependencies, which must reach genesis even though no query or transaction passes through the proxy for them.

type Package

type Package struct {
	ImportPath string
	Dir        string
	Kind       Kind
	Name       string

	// MissingGnoMod marks a package whose Dir holds no gnomod.toml — a dir
	// deployed under a module path generated from its name. ToMemPackage
	// synthesizes the file: chain-side AddPackage validation requires it.
	MissingGnoMod bool
	// contains filtered or unexported fields
}

Package is the simplified package type used by the native Loader.

func (*Package) Imports

func (p *Package) Imports() ([]string, error)

Imports returns the package's declared chain-package imports (sorted, deduplicated). Test files and stdlib imports are excluded: only imports the chain must resolve at deploy time are reported.

func (*Package) ToMemPackage

func (p *Package) ToMemPackage() (*std.MemPackage, error)

ToMemPackage reads the package content. In-memory-backed packages return the embedded MemPackage directly. Filesystem-backed packages are re-read from disk on EVERY call — never memoize this: hot reload depends on each genesis rebuild observing the current on-disk content.

Jump to

Keyboard shortcuts

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