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 ¶
- func Contains(parent, child string) bool
- func GlobMatch(pattern, path string) bool
- func MimeType(path string) string
- func NormalizePath(path string) string
- func NormalizePathPattern(path string) string
- func Overlaps(a, b string) bool
- func Resolve(path string) (string, error)
- func Sanitize(pkg string) string
- func SortedFDs(fds map[int]FDConfig) []int
- func WindowsPath(path string) string
- type AppFileSystem
- func (f *AppFileSystem) EnsureDir(path string) error
- func (f *AppFileSystem) ExistsSafe(path string) bool
- func (f *AppFileSystem) FindUp(target, start string, stop ...string) ([]string, error)
- func (f *AppFileSystem) Glob(pattern string, options ...GlobOptions) ([]string, error)
- func (f *AppFileSystem) GlobUp(pattern, start string, stop ...string) ([]string, error)
- func (f *AppFileSystem) IsDir(path string) bool
- func (f *AppFileSystem) IsFile(path string) bool
- func (f *AppFileSystem) ReadDirectoryEntries(path string) ([]DirEntry, error)
- func (f *AppFileSystem) ReadFileStringSafe(path string) (string, bool, error)
- func (f *AppFileSystem) ReadJSON(path string, dst any) error
- func (f *AppFileSystem) Up(options UpOptions) ([]string, error)
- func (f *AppFileSystem) WriteJSON(path string, data any, mode ...fs.FileMode) error
- func (f *AppFileSystem) WriteStringWithDirs(path, content string, mode ...fs.FileMode) error
- func (f *AppFileSystem) WriteWithDirs(path string, content []byte, mode ...fs.FileMode) error
- type Command
- type CommandOptions
- type DirEntry
- type EntryPoint
- type EnvVar
- type FDConfig
- type FileSystemError
- type GlobOptions
- type Handle
- type IOConfig
- type InstallFailedError
- type Npm
- type PackageRequest
- type PipeOptions
- type PipedCommand
- type ReifiedNode
- type Reifier
- type SpawnSpec
- type Spawner
- type StandardCommand
- type SystemError
- type UpOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Contains ¶
Contains reports whether child is under parent: any relative path that starts with ".." counts as outside.
func GlobMatch ¶
GlobMatch matches a slash-separated path against a pattern whose "**" segment spans any number of directories. Dot files are not special here.
func MimeType ¶
MimeType returns the media type for path's extension, or application/octet-stream when it is unknown.
func NormalizePath ¶
NormalizePath canonicalizes Windows paths; it is a no-op on other systems.
func NormalizePathPattern ¶
NormalizePathPattern preserves a terminal wildcard during normalization.
func Resolve ¶
Resolve returns the real absolute path or the normalized absolute path when the target does not exist.
func Sanitize ¶
Sanitize replaces Windows-illegal package path characters. It is a no-op on non-Windows platforms.
func WindowsPath ¶
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) WriteStringWithDirs ¶
func (f *AppFileSystem) WriteStringWithDirs(path, content string, mode ...fs.FileMode) error
WriteStringWithDirs is the string overload of WriteWithDirs.
func (*AppFileSystem) WriteWithDirs ¶
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 EntryPoint ¶
type EntryPoint struct {
Directory string `json:"directory"`
Entrypoint *string `json:"entrypoint"`
}
EntryPoint is the installed package directory and optional import entry.
type FileSystemError ¶
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.
type IOConfig ¶
type IOConfig struct {
Mode string // "pipe", "inherit", "ignore"
Reader io.Reader
Writer io.Writer
}
IOConfig configures a standard stream.
type InstallFailedError ¶
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.
type PackageRequest ¶
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 ¶
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.
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