watch

package
v0.384.0 Latest Latest
Warning

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

Go to latest
Published: Oct 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, 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 FileChangeType

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

func CompareFileHashes

func CompareFileHashes(oldFiles, newFiles FileHashes) (FileChangeType, string, bool)

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

Returns true if the hashes are equal, false otherwise.

If false, the returned string will be a file that caused the difference and the returned FileChangeType will be the type of change that occurred.

func (FileChangeType) GoString

func (f FileChangeType) GoString() string

func (FileChangeType) String

func (f FileChangeType) String() string

type FileHashes

type FileHashes map[string][]byte

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
	Change FileChangeType
	Path   string
	Time   time.Time
}

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