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

Commit 75bfdbd

Browse files
author
Artūrs Jānis Pētersons
committed
Search for boxes in vendor directory
1 parent e226b8c commit 75bfdbd

3 files changed

Lines changed: 14 additions & 12 deletions

File tree

v2/jam/parser/finder.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ func (fd *finder) findAllGoFiles(dir string) ([]string, error) {
2929
plog.Debug(fd, "findAllGoFiles", "dir", dir)
3030

3131
callback := func(path string, do *godirwalk.Dirent) error {
32+
if filepath.Base(path) == "vendor" {
33+
return filepath.SkipDir
34+
}
3235
ext := filepath.Ext(path)
3336
if ext != ".go" {
3437
return nil
@@ -46,18 +49,22 @@ func (fd *finder) findAllGoFiles(dir string) ([]string, error) {
4649
}
4750

4851
func (fd *finder) findAllGoFilesImports(dir string) ([]string, error) {
52+
return fd.findAllGoFilesImportsIn(".", dir)
53+
}
54+
55+
func (fd *finder) findAllGoFilesImportsIn(path, dir string) ([]string, error) {
4956
var err error
5057
var names []string
51-
oncer.Do(fd.key("findAllGoFilesImports", dir), func() {
58+
oncer.Do(fd.key("findAllGoFilesImports", filepath.Join(dir, path)), func() {
5259
ctx := build.Default
5360

5461
if len(ctx.SrcDirs()) == 0 {
5562
err = errors.New("no src directories found")
5663
return
5764
}
5865

59-
pkg, err := ctx.ImportDir(dir, 0)
60-
if strings.HasPrefix(pkg.ImportPath, "github.com/gobuffalo/packr") {
66+
pkg, err := ctx.Import(path, dir, 0)
67+
if strings.Contains(pkg.ImportPath, "github.com/gobuffalo/packr") {
6168
return
6269
}
6370

@@ -79,17 +86,12 @@ func (fd *finder) findAllGoFilesImports(dir string) ([]string, error) {
7986

8087
plog.Debug(fd, "findAllGoFilesImports", "dir", dir)
8188

82-
names, _ = fd.findAllGoFiles(dir)
89+
names, _ = fd.findAllGoFiles(pkg.Dir)
8390
for _, n := range pkg.GoFiles {
8491
names = append(names, filepath.Join(pkg.Dir, n))
8592
}
8693
for _, imp := range pkg.Imports {
87-
if len(ctx.SrcDirs()) == 0 {
88-
continue
89-
}
90-
d := ctx.SrcDirs()[len(ctx.SrcDirs())-1]
91-
ip := filepath.Join(d, imp)
92-
n, err := fd.findAllGoFilesImports(ip)
94+
n, err := fd.findAllGoFilesImportsIn(imp, dir)
9395
if err != nil && len(n) != 0 {
9496
names = n
9597
return

v2/jam/parser/prospect.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/gobuffalo/packr/v2/plog"
1010
)
1111

12-
var DefaultIgnoredFolders = []string{".", "_", "vendor", "node_modules", "_fixtures", "testdata"}
12+
var DefaultIgnoredFolders = []string{".", "_", "node_modules", "_fixtures", "testdata"}
1313

1414
func IsProspect(path string, ignore ...string) (status bool) {
1515
// plog.Debug("parser", "IsProspect", "path", path, "ignore", ignore)

v2/jam/parser/prospect_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func Test_IsProspect(t *testing.T) {
1818
{"a/b.go", true},
1919
{"a/b_test.go", false},
2020
{"a/b-packr.go", false},
21-
{"a/vendor/b.go", false},
21+
{"a/vendor/b.go", true},
2222
{"a/_c/c.go", false},
2323
{"a/_c/e/fe/f/c.go", false},
2424
{"a/d/_d.go", false},

0 commit comments

Comments
 (0)