diff --git a/plugins/jsvm/jsvm.go b/plugins/jsvm/jsvm.go index d47d6419..87b3648c 100644 --- a/plugins/jsvm/jsvm.go +++ b/plugins/jsvm/jsvm.go @@ -224,7 +224,7 @@ func (p *plugin) registerHooks() error { // initialize the hooks dir watcher if p.config.HooksWatch { if err := p.watchHooks(); err != nil { - return err + color.Yellow("Unable to init hooks watcher: %v", err) } } @@ -344,13 +344,23 @@ func (p *plugin) normalizeServeExceptions(oldErrorHandler echo.HTTPErrorHandler) // // This method does nothing if the hooks directory is missing. func (p *plugin) watchHooks() error { - if _, err := os.Stat(p.config.HooksDir); err != nil { + watchDir := p.config.HooksDir + + hooksDirInfo, err := os.Lstat(p.config.HooksDir) + if err != nil { if errors.Is(err, fs.ErrNotExist) { return nil // no hooks dir to watch } return err } + if hooksDirInfo.Mode()&os.ModeSymlink == os.ModeSymlink { + watchDir, err = filepath.EvalSymlinks(p.config.HooksDir) + if err != nil { + return fmt.Errorf("failed to resolve hooksDir symink: %w", err) + } + } + watcher, err := fsnotify.NewWatcher() if err != nil { return err @@ -409,9 +419,9 @@ func (p *plugin) watchHooks() error { // add directories to watch // // @todo replace once recursive watcher is added (https://github.com/fsnotify/fsnotify/issues/18) - dirsErr := filepath.Walk(p.config.HooksDir, func(path string, info fs.FileInfo, err error) error { - // ignore hidden directories and node_modules - if !info.IsDir() || info.Name() == "node_modules" || strings.HasPrefix(info.Name(), ".") { + dirsErr := filepath.WalkDir(watchDir, func(path string, entry fs.DirEntry, err error) error { + // ignore hidden directories, node_modules, symlinks, sockets, etc. + if !entry.IsDir() || entry.Name() == "node_modules" || strings.HasPrefix(entry.Name(), ".") { return nil }