Skip to content
This repository has been archived by the owner on Jun 25, 2022. It is now read-only.

Commit

Permalink
Search for boxes in vendor directory
Browse files Browse the repository at this point in the history
  • Loading branch information
ajpetersons committed Apr 30, 2020
1 parent c6a5045 commit 2065c36
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
22 changes: 12 additions & 10 deletions v2/jam/parser/finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -57,18 +60,22 @@ 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 {
err = fmt.Errorf("no src directories found")
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
}

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion v2/jam/parser/prospect.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion v2/jam/parser/prospect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down

0 comments on commit 2065c36

Please sign in to comment.