Skip to content

Commit

Permalink
fix(compute/serve): replace separate ignore files with .fastlyignore (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Integralist authored Feb 21, 2023
1 parent 0399c01 commit 7246d7c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 28 deletions.
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ require (
github.com/mholt/archiver v3.1.1+incompatible
github.com/otiai10/copy v1.9.0
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06
github.com/tcnksm/go-gitconfig v0.1.2
github.com/theckman/yacspin v0.13.12
golang.org/x/crypto v0.0.0-20220926161630-eccd6366d1be
)
Expand All @@ -51,7 +50,6 @@ require (
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/nwaples/rardecode v1.1.2 // indirect
github.com/onsi/gomega v1.24.1 // indirect
github.com/peterhellberg/link v1.1.0 // indirect
github.com/pierrec/lz4/v4 v4.1.8 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ github.com/nicksnyder/go-i18n v1.10.1/go.mod h1:e4Di5xjP9oTVrC6y3C7C0HoSYXjSbhh/
github.com/nwaples/rardecode v1.1.0/go.mod h1:5DzqNKiOdpKKBH87u8VlvAnPZMXcGRhxWkRpHbbfGS0=
github.com/nwaples/rardecode v1.1.2 h1:Cj0yZY6T1Zx1R7AhTbyGSALm44/Mmq+BAPc4B/p/d3M=
github.com/nwaples/rardecode v1.1.2/go.mod h1:5DzqNKiOdpKKBH87u8VlvAnPZMXcGRhxWkRpHbbfGS0=
github.com/onsi/gomega v1.24.1 h1:KORJXNNTzJXzu4ScJWssJfJMnJ+2QJqhoQSRwNlze9E=
github.com/onsi/gomega v1.24.1/go.mod h1:3AOiACssS3/MajrniINInwbfOOtfZvplPzuRSmvt1jM=
github.com/otiai10/copy v1.9.0 h1:7KFNiCgZ91Ru4qW4CWPf/7jqtxLagGRmIxWldPP9VY4=
github.com/otiai10/copy v1.9.0/go.mod h1:hsfX19wcn0UWIHUQ3/4fHuehhk2UyArQ9dVFAn3FczI=
github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE=
Expand Down Expand Up @@ -119,8 +117,6 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/tcnksm/go-gitconfig v0.1.2 h1:iiDhRitByXAEyjgBqsKi9QU4o2TNtv9kPP3RgPgXBPw=
github.com/tcnksm/go-gitconfig v0.1.2/go.mod h1:/8EhP4H7oJZdIPyT+/UIsG87kTzrzM4UsLGSItWYCpE=
github.com/theckman/yacspin v0.13.12 h1:CdZ57+n0U6JMuh2xqjnjRq5Haj6v1ner2djtLQRzJr4=
github.com/theckman/yacspin v0.13.12/go.mod h1:Rd2+oG2LmQi5f3zC3yeZAOl245z8QOvrH4OPOJNZxLg=
github.com/tomnomnom/linkheader v0.0.0-20180905144013-02ca5825eb80 h1:nrZ3ySNYwJbSpD6ce9duiP+QkD3JuLCcWkdaehUS/3Y=
Expand Down
30 changes: 8 additions & 22 deletions pkg/commands/compute/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"github.com/fatih/color"
"github.com/fsnotify/fsnotify"
ignore "github.com/sabhiram/go-gitignore"
"github.com/tcnksm/go-gitconfig"
)

// ServeCommand produces and runs an artifact from files on the local disk.
Expand Down Expand Up @@ -496,7 +495,7 @@ func local(bin, file, addr, env string, debug, watch bool, watchDir cmd.Optional
// watchFiles watches the language source directory and restarts the viceroy
// executable when changes are detected.
func watchFiles(watchDir cmd.OptionalString, verbose bool, s *fstexec.Streaming, out io.Writer, restart chan<- bool) {
gi := gitIgnore(watchDir)
gi := ignoreFiles(watchDir)

watcher, err := fsnotify.NewWatcher()
if err != nil {
Expand Down Expand Up @@ -605,29 +604,16 @@ func watchFiles(watchDir cmd.OptionalString, verbose bool, s *fstexec.Streaming,
log.Fatal(err)
}

text.Info(out, "Watching files for changes (using --watch-dir=%s). To see what files are being watched, pass the --verbose flag. To ignore certain files, configure either .ignore, .gitignore or the global git ignore (uses .ignore and .gitignore from --watch-dir).", root)
text.Info(out, "Watching files for changes (using --watch-dir=%s). To see what files are being watched, pass the --verbose flag. To ignore certain files, define patterns within a .fastlyignore config file (uses .fastlyignore from --watch-dir).", root)
text.Break(out)
<-done
}

// gitIgnore returns the specific ignore rules being respected.
//
// NOTE: ignore files will be inherited in the following order:
//
// - .ignore (local)
// - .gitignore (local)
// - core.excludesfile (global)
// ignoreFiles returns the specific ignore rules being respected.
//
// NOTE: We also ignore the .git directory.
func gitIgnore(watchDir cmd.OptionalString) *ignore.GitIgnore {
var (
globalIgnore string
patterns []string
)

if f, err := gitconfig.Global("core.excludesfile"); err == nil {
globalIgnore = filesystem.ResolveAbs(f)
}
func ignoreFiles(watchDir cmd.OptionalString) *ignore.GitIgnore {
var patterns []string

root := ""
if watchDir.WasSet {
Expand All @@ -637,10 +623,10 @@ func gitIgnore(watchDir cmd.OptionalString) *ignore.GitIgnore {
}
}

localIgnore := root + ".ignore"
localGitIgnore := root + ".gitignore"
fastlyIgnore := root + ".fastlyignore"

for _, file := range []string{localIgnore, localGitIgnore, globalIgnore} {
// NOTE: Using a loop to allow for future ignore files to be respected.
for _, file := range []string{fastlyIgnore} {
patterns = append(patterns, readIgnoreFile(file)...)
}

Expand Down

0 comments on commit 7246d7c

Please sign in to comment.