Help us shape the future of Go! Take the 2026 Go Developer Survey

require

package
v0.38.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const ID = "require"

Variables

View Source
var Directive = compiler.Directive{
	Name:    "require",
	Example: "@require ./locallib as mylib\n@require github.com/nexssp/text-tools v1.0.0 as text_tools",
	Handler: handleDirective,
}

Functions

func Bundle

func Bundle(_ map[string]string) compiler.Bundle

func GenerateGlue

func GenerateGlue(
	w io.Writer,
	packageName, cliImport string,
	mods []ResolvedModule,
) error

func HasGoFiles

func HasGoFiles(dir string) bool

func NormalizeID

func NormalizeID(target string) string

NormalizeID extracts the canonical bundle ID from any target path. e.g. "github.com/nexssp/mybundle/nexssflow" -> "mybundle" e.g. "nflow-harness/loose/localtest_e152bdd9" -> "localtest"

func ReadModuleLine

func ReadModuleLine(goModPath string) (string, error)

func ResolveBundles

func ResolveBundles(reqs []Requirement) ([]compiler.Bundle, error)

ResolveBundles resolves in-process requirements to compiler.Bundle instances.

func ResolveBundlesWith added in v0.15.0

func ResolveBundlesWith(reqs []Requirement, onBundle func(compiler.Bundle)) ([]compiler.Bundle, error)

ResolveBundlesWith resolves in-process requirements and calls onBundle immediately after each factory returns, before option validation or alias wiring. Owners can therefore retain cleanup callbacks when a later bundle fails validation or construction.

Types

type Plan

type Plan struct {
	Modules []Requirement
}

type Requirement

type Requirement struct {
	Import string
	// PackagePath is the Go import path selected for the bundle package.
	// It may differ from Import when a bare repository target defaults to
	// its nexssflow package or when Go resolves a package to a nested module.
	PackagePath string
	Alias       string
	Version     string
	// ResolvedVersion is the provider module version selected by Go for a
	// versioned remote bundle package. Local and workspace replacements may
	// leave it empty.
	ResolvedVersion string
	LocalPath       string
	ModuleRoot      string
	ModulePath      string
	IsLoose         bool
	LooseID         string
	Options         map[string]string
}

func FromMeta

func FromMeta(meta map[string]any) []Requirement

FromMeta returns requirements in declaration/include order, preserving the first declaration's options. Use SourceRequirements to report alias conflicts.

func Parse

func Parse(spec, baseDir string, opts map[string]string, file string, line int) (Requirement, error)

func SourceRequirements added in v0.36.0

func SourceRequirements(meta map[string]any) ([]Requirement, error)

SourceRequirements discovers dependencies through parsed source modules. Include does not merge requirement state; the existing @require first-wins and alias-conflict rules apply in the original source order.

func (Requirement) IsLocal

func (r Requirement) IsLocal() bool

type ResolvedModule

type ResolvedModule struct {
	Requirement Requirement
	Dir         string
	GoMod       string
}

func Resolve

func Resolve(plan Plan, _ string) ([]ResolvedModule, error)

type SourceDeclaration added in v0.37.0

type SourceDeclaration struct {
	// SourceLine is the executed header, used to reject edits after substitutions.
	SourceLine    string
	Requirement   Requirement
	Line          int
	SelectorStart int
	SelectorEnd   int
}

SourceDeclaration identifies one direct @require declaration in the source file that produced metadata. Selector offsets are byte offsets into the original, complete directive line and include any selector quote marks.

func DirectDeclarations added in v0.37.0

func DirectDeclarations(meta map[string]any) []SourceDeclaration

DirectDeclarations returns only @require directives executed in this metadata scope. Included source files retain their own declaration lists.

Jump to

Keyboard shortcuts

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