core

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Application filesystem. Plain writes and write-with-parent-directory retry are distinct methods.

Npm package helper. Installation is behind the narrow Reifier interface; the default implementation invokes npm with save/ignore-scripts settings.

Process spawner: argv/env/cwd/stdio configuration, pipelines and process-group kill.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contains

func Contains(parent, child string) bool

Contains reports whether child is under parent: any relative path that starts with ".." counts as outside.

func GlobMatch

func GlobMatch(pattern, path string) bool

GlobMatch matches a slash-separated path against a pattern whose "**" segment spans any number of directories. Dot files are not special here.

func MimeType

func MimeType(path string) string

MimeType returns the media type for path's extension, or application/octet-stream when it is unknown.

func NormalizePath

func NormalizePath(path string) string

NormalizePath canonicalizes Windows paths; it is a no-op on other systems.

func NormalizePathPattern

func NormalizePathPattern(path string) string

NormalizePathPattern preserves a terminal wildcard during normalization.

func Overlaps

func Overlaps(a, b string) bool

Overlaps reports whether either path is within the other.

func Resolve

func Resolve(path string) (string, error)

Resolve returns the real absolute path or the normalized absolute path when the target does not exist.

func Sanitize

func Sanitize(pkg string) string

Sanitize replaces Windows-illegal package path characters. It is a no-op on non-Windows platforms.

func SortedFDs

func SortedFDs(fds map[int]FDConfig) []int

SortedFDs returns the valid additional fd numbers (>= 3) in ascending order.

func WindowsPath

func WindowsPath(path string) string

WindowsPath translates common POSIX drive spellings on Windows.

Types

type AppFileSystem

type AppFileSystem struct{}

AppFileSystem is the concrete application filesystem service.

func NewFileSystem

func NewFileSystem() *AppFileSystem

NewFileSystem constructs the default OS-backed service.

func (*AppFileSystem) EnsureDir

func (f *AppFileSystem) EnsureDir(path string) error

EnsureDir creates path recursively.

func (*AppFileSystem) ExistsSafe

func (f *AppFileSystem) ExistsSafe(path string) bool

ExistsSafe swallows all stat failures.

func (*AppFileSystem) FindUp

func (f *AppFileSystem) FindUp(target, start string, stop ...string) ([]string, error)

FindUp finds target at start and each parent, nearest first.

func (*AppFileSystem) Glob

func (f *AppFileSystem) Glob(pattern string, options ...GlobOptions) ([]string, error)

Glob scans from options.Cwd using minimatch-style ** path segments.

func (*AppFileSystem) GlobUp

func (f *AppFileSystem) GlobUp(pattern, start string, stop ...string) ([]string, error)

GlobUp scans each ancestor and swallows per-directory glob errors.

func (*AppFileSystem) IsDir

func (f *AppFileSystem) IsDir(path string) bool

IsDir returns false on every stat failure.

func (*AppFileSystem) IsFile

func (f *AppFileSystem) IsFile(path string) bool

IsFile returns false on every stat failure.

func (*AppFileSystem) ReadDirectoryEntries

func (f *AppFileSystem) ReadDirectoryEntries(path string) ([]DirEntry, error)

ReadDirectoryEntries preserves the operating system's readdir order.

func (*AppFileSystem) ReadFileStringSafe

func (f *AppFileSystem) ReadFileStringSafe(path string) (string, bool, error)

ReadFileStringSafe maps only NotExist to an absent result.

func (*AppFileSystem) ReadJSON

func (f *AppFileSystem) ReadJSON(path string, dst any) error

ReadJSON decodes a JSON file into dst; numbers decode as float64.

func (*AppFileSystem) Up

func (f *AppFileSystem) Up(options UpOptions) ([]string, error)

Up finds all target names at every ancestor.

func (*AppFileSystem) WriteJSON

func (f *AppFileSystem) WriteJSON(path string, data any, mode ...fs.FileMode) error

WriteJSON does not create parent directories.

func (*AppFileSystem) WriteStringWithDirs

func (f *AppFileSystem) WriteStringWithDirs(path, content string, mode ...fs.FileMode) error

WriteStringWithDirs is the string overload of WriteWithDirs.

func (*AppFileSystem) WriteWithDirs

func (f *AppFileSystem) WriteWithDirs(path string, content []byte, mode ...fs.FileMode) error

WriteWithDirs retries a missing-parent write after creating the parent.

type Command

type Command interface {
	// contains filtered or unexported methods
}

Command is a StandardCommand or PipedCommand.

type CommandOptions

type CommandOptions struct {
	Cwd       string
	Env       []EnvVar
	EnvSet    bool
	ExtendEnv *bool

	Stdin  IOConfig
	Stdout IOConfig
	Stderr IOConfig

	AdditionalFDs  map[int]FDConfig
	Detached       *bool
	Shell          string // "", "true", or an explicit shell path
	KillSignal     os.Signal
	ForceKillAfter time.Duration
}

CommandOptions configures a StandardCommand.

type DirEntry

type DirEntry struct {
	Name string `json:"name"`
	Type string `json:"type"`
}

DirEntry is the portable directory-entry shape from AppFileSystem.

type EntryPoint

type EntryPoint struct {
	Directory  string  `json:"directory"`
	Entrypoint *string `json:"entrypoint"`
}

EntryPoint is the installed package directory and optional import entry.

type EnvVar

type EnvVar struct {
	Name  string
	Value string
}

EnvVar is one environment assignment. A slice preserves declaration order.

type FDConfig

type FDConfig struct {
	Type   string // "input" or "output"
	Reader io.Reader
	Writer io.Writer
}

FDConfig configures one fd >= 3.

type FileSystemError

type FileSystemError struct {
	Method string
	Cause  error
}

FileSystemError wraps operations implemented outside the basic os package.

func (*FileSystemError) Error

func (e *FileSystemError) Error() string

func (*FileSystemError) Unwrap

func (e *FileSystemError) Unwrap() error

type GlobOptions

type GlobOptions struct {
	Cwd      string
	Absolute bool
	Include  string // "file" (default) or "all"
	Dot      bool
	Symlink  bool
}

GlobOptions configures Glob.

type Handle

type Handle struct {
	PID    int
	Stdin  io.WriteCloser
	Stdout io.ReadCloser
	Stderr io.ReadCloser
	All    io.Reader
	// contains filtered or unexported fields
}

Handle is a running command or pipeline. Stdout/Stderr belong to the final command.

func (*Handle) IsRunning

func (h *Handle) IsRunning() bool

IsRunning reports whether Wait has completed.

func (*Handle) Kill

func (h *Handle) Kill() error

Kill sends the configured signal and optionally escalates to SIGKILL.

func (*Handle) Wait

func (h *Handle) Wait() (int, error)

Wait waits for the pipeline and returns the final command's exit code.

type IOConfig

type IOConfig struct {
	Mode   string // "pipe", "inherit", "ignore"
	Reader io.Reader
	Writer io.Writer
}

IOConfig configures a standard stream.

type InstallFailedError

type InstallFailedError struct {
	Add   []string
	Dir   string
	Cause error
}

InstallFailedError is the tagged npm installation failure.

func (*InstallFailedError) Error

func (e *InstallFailedError) Error() string

func (*InstallFailedError) Unwrap

func (e *InstallFailedError) Unwrap() error

type Npm

type Npm struct {
	CacheDir string
	FS       *AppFileSystem
	Reifier  Reifier
	// contains filtered or unexported fields
}

Npm is an npm package-cache service.

func NewNpm

func NewNpm(cacheDir string, reifier Reifier) *Npm

NewNpm constructs an npm helper rooted at cacheDir.

func (*Npm) Add

func (n *Npm) Add(ctx context.Context, pkg string) (EntryPoint, error)

Add installs pkg in its isolated package cache.

func (*Npm) Install

func (n *Npm) Install(ctx context.Context, dir string, input ...[]PackageRequest) error

Install reifies dir when node_modules is absent or the root lockfile omits a declared dependency. An unwritable directory is silently skipped.

func (*Npm) Which

func (n *Npm) Which(ctx context.Context, pkg string, bin ...string) (string, bool)

Which finds a package-provided executable, repairing the isolated install once when no bin exists.

type PackageRequest

type PackageRequest struct {
	Name    string
	Version string
}

PackageRequest is an extra dependency requested by Install.

type PipeOptions

type PipeOptions struct {
	From string // stdout (default), stderr, all, fdN
	To   string // stdin (default), fdN
}

PipeOptions selects the source and destination of a pipeline edge.

type PipedCommand

type PipedCommand struct {
	Left    Command
	Right   Command
	Options PipeOptions
}

PipedCommand connects Left to Right.

func Pipe

func Pipe(left, right Command, options ...PipeOptions) PipedCommand

Pipe constructs a piped command.

type ReifiedNode

type ReifiedNode struct {
	Name string
	Path string
}

ReifiedNode is the package a reify installed.

type Reifier

type Reifier interface {
	Reify(ctx context.Context, dir string, add []string) (*ReifiedNode, error)
}

Reifier performs one npm reify operation.

type SpawnSpec

type SpawnSpec struct {
	Path     string
	Args     []string
	Cwd      string
	Env      []string
	EnvSet   bool
	Detached bool
	Shell    string
}

SpawnSpec is the fully resolved command passed to os/exec.

func BuildSpawnSpec

func BuildSpawnSpec(command StandardCommand) (SpawnSpec, error)

BuildSpawnSpec performs the pure argv/env/cwd construction.

type Spawner

type Spawner struct{}

Spawner starts commands and pipelines.

func NewSpawner

func NewSpawner() *Spawner

NewSpawner constructs the default spawner.

func (*Spawner) Run

func (s *Spawner) Run(ctx context.Context, command StandardCommand) ([]byte, []byte, int, error)

Run captures stdout/stderr and waits for one command.

func (*Spawner) Spawn

func (s *Spawner) Spawn(ctx context.Context, command Command) (*Handle, error)

Spawn starts command and returns after every child has started.

type StandardCommand

type StandardCommand struct {
	Command string
	Args    []string
	Options CommandOptions
}

StandardCommand is one executable plus argv.

func MakeCommand

func MakeCommand(command string, args []string, options ...CommandOptions) StandardCommand

MakeCommand constructs a standard command.

type SystemError

type SystemError struct {
	Tag              string
	Module           string
	Method           string
	PathOrDescriptor string
	Syscall          string
	Cause            error
}

SystemError is a tagged spawn or I/O failure.

func (*SystemError) Error

func (e *SystemError) Error() string

func (*SystemError) Unwrap

func (e *SystemError) Unwrap() error

type UpOptions

type UpOptions struct {
	Targets []string
	Start   string
	Stop    string
}

UpOptions configures Up.

Jump to

Keyboard shortcuts

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