From 2065c36b3fa2798e616f4211093ecd2450852d8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Art=C5=ABrs=20J=C4=81nis=20P=C4=93tersons?= Date: Sun, 12 May 2019 20:46:06 +0100 Subject: [PATCH] Search for boxes in vendor directory --- v2/jam/parser/finder.go | 22 ++++++++++++---------- v2/jam/parser/prospect.go | 2 +- v2/jam/parser/prospect_test.go | 2 +- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/v2/jam/parser/finder.go b/v2/jam/parser/finder.go index 2ad808e..4462a15 100644 --- a/v2/jam/parser/finder.go +++ b/v2/jam/parser/finder.go @@ -30,6 +30,9 @@ func (fd *finder) findAllGoFiles(dir string) ([]string, error) { plog.Debug(fd, "findAllGoFiles", "dir", dir) callback := func(path string, do *godirwalk.Dirent) error { + if filepath.Base(path) == "vendor" { + return filepath.SkipDir + } ext := filepath.Ext(path) if ext != ".go" { return nil @@ -57,9 +60,13 @@ func (fd *finder) findAllGoFiles(dir string) ([]string, error) { } func (fd *finder) findAllGoFilesImports(dir string) ([]string, error) { + return fd.findAllGoFilesImportsIn(".", dir) +} + +func (fd *finder) findAllGoFilesImportsIn(path, dir string) ([]string, error) { var err error var names []string - oncer.Do(fd.key("findAllGoFilesImports", dir), func() { + oncer.Do(fd.key("findAllGoFilesImports", filepath.Join(dir, path)), func() { ctx := build.Default if len(ctx.SrcDirs()) == 0 { @@ -67,8 +74,8 @@ func (fd *finder) findAllGoFilesImports(dir string) ([]string, error) { return } - pkg, err := ctx.ImportDir(dir, 0) - if strings.HasPrefix(pkg.ImportPath, "github.com/gobuffalo/packr") { + pkg, err := ctx.Import(path, dir, 0) + if strings.Contains(pkg.ImportPath, "github.com/gobuffalo/packr") { return } @@ -90,17 +97,12 @@ func (fd *finder) findAllGoFilesImports(dir string) ([]string, error) { plog.Debug(fd, "findAllGoFilesImports", "dir", dir) - names, _ = fd.findAllGoFiles(dir) + names, _ = fd.findAllGoFiles(pkg.Dir) for _, n := range pkg.GoFiles { names = append(names, filepath.Join(pkg.Dir, n)) } for _, imp := range pkg.Imports { - if len(ctx.SrcDirs()) == 0 { - continue - } - d := ctx.SrcDirs()[len(ctx.SrcDirs())-1] - ip := filepath.Join(d, imp) - n, err := fd.findAllGoFilesImports(ip) + n, err := fd.findAllGoFilesImportsIn(imp, dir) if err != nil && len(n) != 0 { names = n return diff --git a/v2/jam/parser/prospect.go b/v2/jam/parser/prospect.go index 652db5b..afb5cf2 100644 --- a/v2/jam/parser/prospect.go +++ b/v2/jam/parser/prospect.go @@ -9,7 +9,7 @@ import ( "github.com/gobuffalo/packr/v2/plog" ) -var DefaultIgnoredFolders = []string{".", "_", "vendor", "node_modules", "_fixtures", "testdata"} +var DefaultIgnoredFolders = []string{".", "_", "node_modules", "_fixtures", "testdata"} func IsProspect(path string, ignore ...string) (status bool) { // plog.Debug("parser", "IsProspect", "path", path, "ignore", ignore) diff --git a/v2/jam/parser/prospect_test.go b/v2/jam/parser/prospect_test.go index f023f81..1699b91 100644 --- a/v2/jam/parser/prospect_test.go +++ b/v2/jam/parser/prospect_test.go @@ -18,7 +18,7 @@ func Test_IsProspect(t *testing.T) { {"a/b.go", true}, {"a/b_test.go", false}, {"a/b-packr.go", false}, - {"a/vendor/b.go", false}, + {"a/vendor/b.go", true}, {"a/_c/c.go", false}, {"a/_c/e/fe/f/c.go", false}, {"a/d/_d.go", false},