diff --git a/internal/examples/app/go.mod b/internal/examples/app/go.mod index 5be7710..02c4595 100644 --- a/internal/examples/app/go.mod +++ b/internal/examples/app/go.mod @@ -2,11 +2,11 @@ module github.com/markbates/pkger/internal/examples/app go 1.12 -replace github.com/markbates/pkger => ../../../ - require ( cloud.google.com/go v0.36.0 // indirect github.com/cockroachdb/cockroach-go v0.0.0-20181001143604-e0a95dfd547c // indirect github.com/gobuffalo/buffalo v0.14.7 // indirect - github.com/markbates/pkger v0.0.0-00010101000000-000000000000 + github.com/markbates/pkger v0.0.0 ) + +replace github.com/markbates/pkger => ../../../ diff --git a/parser/parser.go b/parser/parser.go index e7a6ad3..e4d2665 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -14,13 +14,15 @@ var DefaultIgnoredFolders = []string{".", "_", "vendor", "node_modules", "_fixtu func Parse(name string) (Results, error) { var r Results + c, err := pkgs.Current() + if err != nil { + return r, err + } + if name == "" || name == "." { - c, err := pkgs.Current() - if err != nil { - return r, err - } name = c.ImportPath } + pt, err := paths.Parse(name) if err != nil { return r, err @@ -34,18 +36,37 @@ func Parse(name string) (Results, error) { } m := map[paths.Path]bool{} + root := r.Path.Name if !strings.HasPrefix(root, string(filepath.Separator)) { root = string(filepath.Separator) + root } + if !strings.HasPrefix(root, her.Dir) { root = filepath.Join(her.Dir, root) } + + if name != her.Dir { + _, err = os.Stat(filepath.Join(root, "go.mod")) + if err == nil { + return Results{}, nil + } + } + err = filepath.Walk(root, func(path string, info os.FileInfo, err error) error { if err != nil { return err } + if info.IsDir() { + if path != c.Dir { + _, err = os.Stat(filepath.Join(path, "go.mod")) + if err == nil { + return filepath.SkipDir + } + } + } + base := filepath.Base(path) for _, ig := range DefaultIgnoredFolders { @@ -128,11 +149,26 @@ func sourceFiles(pt paths.Path) ([]paths.Path, error) { if !fi.IsDir() { return res, nil } + + c, err := pkgs.Current() + if err != nil { + return res, err + } + err = filepath.Walk(fp, func(p string, info os.FileInfo, err error) error { if err != nil { return err } + if info.IsDir() { + if p != c.Dir { + _, err = os.Stat(filepath.Join(p, "go.mod")) + if err == nil { + return filepath.SkipDir + } + } + } + base := filepath.Base(p) if base == "." {