watch

package
v0.412.5 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrSkip = errors.New("skip directory")

ErrSkip can be returned by the WalkDir callback to skip a file or directory.

Functions

func DiscoverModules

func DiscoverModules(ctx context.Context, moduleDirs []string) ([]moduleconfig.UnvalidatedModuleConfig, error)

DiscoverModules recursively loads all modules under the given directories (or if none provided, the current working directory is used).

func WalkDir

func WalkDir(dir string, skipGitIgnoredFiles bool, fn func(path string, d fs.DirEntry) error) error

WalkDir performs a depth-first walk of the file tree rooted at dir, calling fn for each file or directory in the tree, including dir.

It will adhere to .gitignore files. The callback "fn" can return ErrSkip to skip recursion.

Types

type FileChange

type FileChange struct {
	Change FileChangeType
	Path   string
}

func CompareFileHashes

func CompareFileHashes(oldFiles, newFiles FileHashes) []FileChange

CompareFileHashes compares the hashes of the files in the oldFiles and newFiles maps.

Returns all file changes

type FileChangeType

type FileChangeType rune
const (
	FileAdded   FileChangeType = '+'
	FileRemoved FileChangeType = '-'
	FileChanged FileChangeType = '*'
)

func (FileChangeType) GoString

func (f FileChangeType) GoString() string

func (FileChangeType) String

func (f FileChangeType) String() string

type FileHashes

type FileHashes map[string][]byte

func ComputeFileHashes

func ComputeFileHashes(dir string, skipGitIgnoredFiles bool, patterns []string) (FileHashes, error)

ComputeFileHashes computes the SHA256 hash of all files in the given directory.

If skipGitIgnoredFiles is true, files that are ignored by git will be skipped.

type ModifyFilesTransaction

type ModifyFilesTransaction interface {
	Begin() error
	ModifiedFiles(paths ...string) error
	End() error
}

ModifyFilesTransaction allows builds to modify files in a module without triggering a watch event. This helps us avoid infinite loops with builds changing files, and those changes triggering new builds.as a no-op

type WatchEvent

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

A WatchEvent is an event that occurs when a module is added, removed, or changed.

type WatchEventModuleAdded

type WatchEventModuleAdded struct {
	Config moduleconfig.UnvalidatedModuleConfig
}

type WatchEventModuleChanged

type WatchEventModuleChanged struct {
	Config  moduleconfig.UnvalidatedModuleConfig
	Changes []FileChange
	Time    time.Time
}

func (WatchEventModuleChanged) String

func (c WatchEventModuleChanged) String() string

type WatchEventModuleRemoved

type WatchEventModuleRemoved struct {
	Config moduleconfig.UnvalidatedModuleConfig
}

type Watcher

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

func NewWatcher

func NewWatcher(patterns ...string) *Watcher

func (*Watcher) GetTransaction

func (w *Watcher) GetTransaction(moduleDir string) ModifyFilesTransaction

func (*Watcher) Watch

func (w *Watcher) Watch(ctx context.Context, period time.Duration, moduleDirs []string) (*pubsub.Topic[WatchEvent], error)

Watch the given directories for new modules, deleted modules, and changes to existing modules, publishing a change event for each.

Jump to

Keyboard shortcuts

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