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

Search for boxes in vendor directory #200

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions packr/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import (
"os"

"github.com/gobuffalo/packr/builder"
"github.com/gobuffalo/packr/v2/jam/parser"
"github.com/spf13/cobra"
)

var input string
var compress bool
var verbose bool
var includeVendored bool

var rootCmd = &cobra.Command{
Use: "packr",
Expand All @@ -36,6 +38,9 @@ var rootCmd = &cobra.Command{
RunE: func(cmd *cobra.Command, args []string) error {
b := builder.New(context.Background(), input)
b.Compress = compress
if !includeVendored {
parser.DefaultIgnoredFolders = append(parser.DefaultIgnoredFolders, "vendor")
}
return b.Run()
},
}
Expand All @@ -44,6 +49,7 @@ func init() {
pwd, _ := os.Getwd()
rootCmd.Flags().StringVarP(&input, "input", "i", pwd, "path to scan for packr Boxes")
rootCmd.Flags().BoolVarP(&compress, "compress", "z", false, "compress box contents")
rootCmd.Flags().BoolVar(&includeVendored, "vendor", false, "look for boxes in vendor directory")
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "print verbose logging information")
}

Expand Down
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/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

func init() {
parser.DefaultIgnoredFolders = []string{"vendor", ".git", "node_modules", ".idea"}
parser.DefaultIgnoredFolders = []string{".git", "node_modules", ".idea"}
}

func Test_Parser_Run(t *testing.T) {
Expand Down
4 changes: 3 additions & 1 deletion v2/jam/parser/prospect.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import (
"github.com/gobuffalo/packr/v2/plog"
)

var DefaultIgnoredFolders = []string{".", "_", "vendor", "node_modules", "_fixtures", "testdata"}
// DefaultIgnoredFolders is a list of directories where box lookup is not
// performed.
var DefaultIgnoredFolders = []string{".", "_", "node_modules", "_fixtures", "testdata"}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exported identifier "DefaultIgnoredFolders" should have comment

Suggested change
var DefaultIgnoredFolders = []string{".", "_", "node_modules", "_fixtures", "testdata"}
// DefaultIgnoredFolders ...
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