From 16972f8f180a6206131dc2ac97c7cbeaa168fc5b Mon Sep 17 00:00:00 2001 From: Mark Bates Date: Tue, 3 Dec 2019 15:07:51 -0500 Subject: [PATCH 1/9] use gobuffalo/here fixes #49 --- cmd/pkger/cmds/pack.go | 2 +- cmd/pkger/cmds/parse.go | 2 +- cmd/pkger/cmds/path.go | 2 +- examples/http/pkger/go.sum | 5 ++ go.mod | 5 +- go.sum | 7 ++- here/current.go | 29 ---------- here/dir.go | 77 -------------------------- here/dir_test.go | 67 ----------------------- here/here.go | 50 +++-------------- here/here_test.go | 33 ------------ here/info.go | 39 -------------- here/info_map.go | 87 ------------------------------ here/module.go | 25 --------- here/parse.go | 63 ---------------------- here/parse_test.go | 63 ---------------------- here/path.go | 20 ------- here/pkg.go | 44 --------------- internal/maps/files.go | 2 +- internal/maps/infos.go | 2 +- parser/file.go | 2 +- parser/parser.go | 2 +- parser/parser_test.go | 4 +- parser/source.go | 2 +- parser/walk.go | 2 +- pkger.go | 2 +- pkging/embed/embed.go | 2 +- pkging/embed/file.go | 2 +- pkging/file.go | 2 +- pkging/file_info_test.go | 2 +- pkging/mem/add.go | 3 +- pkging/mem/add_test.go | 2 +- pkging/mem/embed.go | 2 +- pkging/mem/file.go | 2 +- pkging/mem/file_test.go | 2 +- pkging/mem/mem.go | 2 +- pkging/pkger.go | 2 +- pkging/pkgtest/load_ref.go | 2 +- pkging/pkgtest/pkgtest.go | 2 +- pkging/pkgtest/ref.go | 2 +- pkging/pkgtest/testdata/ref/go.sum | 5 ++ pkging/pkgutil/dump.go | 2 +- pkging/pkgutil/stuff.go | 2 +- pkging/pkgutil/stuff_test.go | 6 +++ pkging/stdos/file.go | 2 +- pkging/stdos/file_test.go | 2 +- pkging/stdos/stdos.go | 2 +- pkging/wrap.go | 2 +- 48 files changed, 60 insertions(+), 630 deletions(-) delete mode 100644 here/current.go delete mode 100644 here/dir.go delete mode 100644 here/dir_test.go delete mode 100644 here/here_test.go delete mode 100644 here/info.go delete mode 100644 here/info_map.go delete mode 100644 here/module.go delete mode 100644 here/parse.go delete mode 100644 here/parse_test.go delete mode 100644 here/path.go delete mode 100644 here/pkg.go diff --git a/cmd/pkger/cmds/pack.go b/cmd/pkger/cmds/pack.go index cea99da..257e1c6 100644 --- a/cmd/pkger/cmds/pack.go +++ b/cmd/pkger/cmds/pack.go @@ -8,8 +8,8 @@ import ( "sort" "strings" + "github.com/gobuffalo/here" "github.com/markbates/pkger" - "github.com/markbates/pkger/here" "github.com/markbates/pkger/parser" "github.com/markbates/pkger/pkging/pkgutil" ) diff --git a/cmd/pkger/cmds/parse.go b/cmd/pkger/cmds/parse.go index ead6334..e9ecb3f 100644 --- a/cmd/pkger/cmds/parse.go +++ b/cmd/pkger/cmds/parse.go @@ -5,7 +5,7 @@ import ( "flag" "os" - "github.com/markbates/pkger/here" + "github.com/gobuffalo/here" "github.com/markbates/pkger/parser" ) diff --git a/cmd/pkger/cmds/path.go b/cmd/pkger/cmds/path.go index e185fff..49d4a48 100644 --- a/cmd/pkger/cmds/path.go +++ b/cmd/pkger/cmds/path.go @@ -6,8 +6,8 @@ import ( "fmt" "os" + "github.com/gobuffalo/here" "github.com/markbates/pkger" - "github.com/markbates/pkger/here" ) type pathCmd struct { diff --git a/examples/http/pkger/go.sum b/examples/http/pkger/go.sum index d5f5cec..c1a59e1 100644 --- a/examples/http/pkger/go.sum +++ b/examples/http/pkger/go.sum @@ -1,6 +1,10 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/gobuffalo/here v0.5.2-0.20191203194143-8e97fc9ad6d3 h1:9NGxHWbGFujaZ5vT+uXurb9m3QoWa175cYM2Qs97nQo= +github.com/gobuffalo/here v0.5.2-0.20191203194143-8e97fc9ad6d3/go.mod h1:wAG085dHOYqUpf+Ap+WOdrPTp5IYcDAs/x7PLa8Y5fM= +github.com/gobuffalo/here v0.6.0 h1:hYrd0a6gDmWxBM4TnrGw8mQg24iSVoIkHEk7FodQcBI= +github.com/gobuffalo/here v0.6.0/go.mod h1:wAG085dHOYqUpf+Ap+WOdrPTp5IYcDAs/x7PLa8Y5fM= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= @@ -19,3 +23,4 @@ gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/go.mod b/go.mod index 05c6854..b6a7e50 100644 --- a/go.mod +++ b/go.mod @@ -3,9 +3,6 @@ module github.com/markbates/pkger go 1.13 require ( - github.com/davecgh/go-spew v1.1.1 // indirect - github.com/kr/pretty v0.1.0 // indirect + github.com/gobuffalo/here v0.6.0 github.com/stretchr/testify v1.4.0 - gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect - gopkg.in/yaml.v2 v2.2.5 // indirect ) diff --git a/go.sum b/go.sum index c67dc0a..4cc976b 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/gobuffalo/here v0.6.0 h1:hYrd0a6gDmWxBM4TnrGw8mQg24iSVoIkHEk7FodQcBI= +github.com/gobuffalo/here v0.6.0/go.mod h1:wAG085dHOYqUpf+Ap+WOdrPTp5IYcDAs/x7PLa8Y5fM= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= @@ -8,6 +10,7 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= @@ -16,5 +19,5 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33 gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.5 h1:ymVxjfMaHvXD8RqPRmzHHsB3VvucivSkIAvJFDI5O3c= -gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.7 h1:VUgggvou5XRW9mHwD/yXxIYSMtY0zoKQf/v226p2nyo= +gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/here/current.go b/here/current.go deleted file mode 100644 index cd5ee61..0000000 --- a/here/current.go +++ /dev/null @@ -1,29 +0,0 @@ -package here - -import ( - "path/filepath" - "sync" -) - -var curOnce sync.Once -var curErr error -var current Info - -func Current() (Info, error) { - (&curOnce).Do(func() { - b, err := run("go", "env", "GOMOD") - if err != nil { - curErr = err - return - } - root := filepath.Dir(string(b)) - i, err := Dir(root) - if err != nil { - curErr = err - return - } - current = i - }) - - return current, curErr -} diff --git a/here/dir.go b/here/dir.go deleted file mode 100644 index b2d3b49..0000000 --- a/here/dir.go +++ /dev/null @@ -1,77 +0,0 @@ -package here - -import ( - "encoding/json" - "fmt" - "os" - "path/filepath" -) - -// Dir attempts to gather info for the requested directory. -func Dir(p string) (Info, error) { - i, err := Cache(p, func(p string) (Info, error) { - var i Info - - fi, err := os.Stat(p) - if err != nil { - return i, err - } - - if !fi.IsDir() { - p = filepath.Dir(p) - } - - pwd, err := os.Getwd() - if err != nil { - return i, err - } - - defer os.Chdir(pwd) - - os.Chdir(p) - - b, err := run("go", "list", "-json") - // go: cannot find main module; see 'go help modules' - // build .: cannot find module for path . - // no Go files in - if err != nil { - if nonGoDirRx.MatchString(err.Error()) { - return fromNonGoDir(p) - } - return i, fmt.Errorf("%w %s", err, p) - } - - if err := json.Unmarshal(b, &i); err != nil { - return i, err - } - - return i, nil - }) - - if err != nil { - return i, err - } - - return Cache(i.ImportPath, func(p string) (Info, error) { - return i, nil - }) - -} - -func fromNonGoDir(dir string) (Info, error) { - i := Info{ - Dir: dir, - Name: filepath.Base(dir), - } - - b, err := run("go", "list", "-json", "-m") - if err != nil { - return i, err - } - - if err := json.Unmarshal(b, &i.Module); err != nil { - return i, err - } - - return i, err -} diff --git a/here/dir_test.go b/here/dir_test.go deleted file mode 100644 index 421d0be..0000000 --- a/here/dir_test.go +++ /dev/null @@ -1,67 +0,0 @@ -package here_test - -import ( - "os" - "path/filepath" - "testing" - - "github.com/markbates/pkger/here" - "github.com/markbates/pkger/pkging/pkgtest" - "github.com/stretchr/testify/require" -) - -func Test_Dir(t *testing.T) { - r := require.New(t) - - ref, err := pkgtest.NewRef() - r.NoError(err) - - root := ref.Dir - - r.NoError(err) - defer os.RemoveAll(root) - - public := filepath.Join(root, "public") - r.NoError(os.MkdirAll(public, 0755)) - - gf := filepath.Join(root, "cmd", "main.go") - r.NoError(os.MkdirAll(filepath.Dir(gf), 0755)) - - f, err := os.Create(gf) - r.NoError(err) - - _, err = f.Write([]byte("package main")) - r.NoError(err) - - r.NoError(f.Close()) - - table := []struct { - in string - err bool - }{ - {in: root, err: false}, - {in: public, err: false}, - {in: gf, err: false}, - {in: filepath.Join(root, "."), err: false}, - {in: "/unknown", err: true}, - } - for _, tt := range table { - t.Run(tt.in, func(st *testing.T) { - here.ClearCache() - r := require.New(st) - - info, err := here.Dir(tt.in) - if tt.err { - r.Error(err) - return - } - r.NoError(err) - - r.NotZero(info) - r.NotZero(info.Dir) - r.NotZero(info.Name) - r.NotZero(info.Module) - - }) - } -} diff --git a/here/here.go b/here/here.go index a825f63..81d349c 100644 --- a/here/here.go +++ b/here/here.go @@ -1,49 +1,13 @@ package here import ( - "bytes" - "fmt" - "os/exec" - "regexp" - "strings" - "sync" + "github.com/gobuffalo/here" ) -var cache = &infoMap{ - data: &sync.Map{}, -} +type Info = here.Info +type Module = here.Module +type Path = here.Path -func run(n string, args ...string) ([]byte, error) { - c := exec.Command(n, args...) - - bb := &bytes.Buffer{} - c.Stdout = bb - c.Stderr = bb - err := c.Run() - if err != nil { - return nil, fmt.Errorf("%w: %q: %s", err, strings.Join(c.Args, " "), bb) - } - - return bb.Bytes(), nil -} - -func Cache(p string, fn func(string) (Info, error)) (Info, error) { - i, ok := cache.Load(p) - if ok { - return i, nil - } - i, err := fn(p) - if err != nil { - return i, err - } - cache.Store(p, i) - return i, nil -} - -func ClearCache() { - cache = &infoMap{ - data: &sync.Map{}, - } -} - -var nonGoDirRx = regexp.MustCompile(`cannot find main|go help modules|go: |build .:|no Go files|can't load package`) +var Dir = here.Dir +var Package = here.Package +var Current = here.Current diff --git a/here/here_test.go b/here/here_test.go deleted file mode 100644 index 1f19112..0000000 --- a/here/here_test.go +++ /dev/null @@ -1,33 +0,0 @@ -package here - -import ( - "testing" - - "github.com/stretchr/testify/require" -) - -func Test_nonGoDirRx(t *testing.T) { - r := require.New(t) - r.False(nonGoDirRx.MatchString("")) - r.False(nonGoDirRx.MatchString("hello")) - - table := []string{ - "go: cannot find main module; see 'go help modules'", - "go help modules", - "go: ", - "build .:", - "no Go files", - "can't load package: package", - } - - for _, tt := range table { - t.Run(tt, func(st *testing.T) { - r := require.New(st) - - b := nonGoDirRx.MatchString(tt) - r.True(b) - - }) - } - -} diff --git a/here/info.go b/here/info.go deleted file mode 100644 index 66283ef..0000000 --- a/here/info.go +++ /dev/null @@ -1,39 +0,0 @@ -package here - -import ( - "encoding/json" -) - -// Info represents details about the directory/package -type Info struct { - Dir string - ImportPath string - Name string - Module Module -} - -func (i Info) MarshalJSON() ([]byte, error) { - mm := map[string]interface{}{ - "ImportPath": i.ImportPath, - "Name": i.Name, - "Module": i.Module, - "Dir": i.Dir, - } - - return json.Marshal(mm) -} - -// IsZero checks if the type has been filled -// with rich chocolately data goodness -func (i Info) IsZero() bool { - return i.String() == Info{}.String() -} - -func (i Info) String() string { - b, err := json.MarshalIndent(i, "", " ") - if err != nil { - return err.Error() - } - s := string(b) - return s -} diff --git a/here/info_map.go b/here/info_map.go deleted file mode 100644 index b9471ef..0000000 --- a/here/info_map.go +++ /dev/null @@ -1,87 +0,0 @@ -// Code generated by github.com/gobuffalo/mapgen. DO NOT EDIT. - -package here - -import ( - "sort" - "sync" -) - -// infoMap wraps sync.Map and uses the following types: -// key: string -// value: Info -type infoMap struct { - data *sync.Map -} - -// Delete the key from the map -func (m *infoMap) Delete(key string) { - m.data.Delete(key) -} - -// Load the key from the map. -// Returns Info or bool. -// A false return indicates either the key was not found -// or the value is not of type Info -func (m *infoMap) Load(key string) (Info, bool) { - i, ok := m.data.Load(key) - if !ok { - return Info{}, false - } - s, ok := i.(Info) - return s, ok -} - -// LoadOrStore will return an existing key or -// store the value if not already in the map -func (m *infoMap) LoadOrStore(key string, value Info) (Info, bool) { - i, _ := m.data.LoadOrStore(key, value) - s, ok := i.(Info) - return s, ok -} - -// LoadOr will return an existing key or -// run the function and store the results -func (m *infoMap) LoadOr(key string, fn func(*infoMap) (Info, bool)) (Info, bool) { - i, ok := m.Load(key) - if ok { - return i, ok - } - i, ok = fn(m) - if ok { - m.Store(key, i) - return i, ok - } - return i, false -} - -// Range over the Info values in the map -func (m *infoMap) Range(f func(key string, value Info) bool) { - m.data.Range(func(k, v interface{}) bool { - key, ok := k.(string) - if !ok { - return false - } - value, ok := v.(Info) - if !ok { - return false - } - return f(key, value) - }) -} - -// Store a Info in the map -func (m *infoMap) Store(key string, value Info) { - m.data.Store(key, value) -} - -// Keys returns a list of keys in the map -func (m *infoMap) Keys() []string { - var keys []string - m.Range(func(key string, value Info) bool { - keys = append(keys, key) - return true - }) - sort.Strings(keys) - return keys -} diff --git a/here/module.go b/here/module.go deleted file mode 100644 index bdfb969..0000000 --- a/here/module.go +++ /dev/null @@ -1,25 +0,0 @@ -package here - -import ( - "encoding/json" -) - -type Module struct { - Path string - Main bool - Dir string - GoMod string - GoVersion string -} - -func (i Module) String() string { - b, err := json.MarshalIndent(i, "", " ") - if err != nil { - return err.Error() - } - return string(b) -} - -func (i Module) IsZero() bool { - return i.String() == Module{}.String() -} diff --git a/here/parse.go b/here/parse.go deleted file mode 100644 index 9227b93..0000000 --- a/here/parse.go +++ /dev/null @@ -1,63 +0,0 @@ -package here - -import ( - "fmt" - "path/filepath" - "regexp" - "strings" -) - -func (i Info) Parse(p string) (Path, error) { - p = strings.TrimSpace(p) - p = filepath.Clean(p) - p = strings.TrimPrefix(p, i.Dir) - - p = strings.Replace(p, "\\", "/", -1) - p = strings.TrimSpace(p) - - if len(p) == 0 || p == ":" || p == "." { - return i.build("", "", "") - } - - res := pathrx.FindAllStringSubmatch(p, -1) - if len(res) == 0 { - return Path{}, fmt.Errorf("could not parse %q", p) - } - - matches := res[0] - - if len(matches) != 4 { - return Path{}, fmt.Errorf("could not parse %q", p) - } - - return i.build(p, matches[1], matches[3]) -} - -func (i Info) build(p, pkg, name string) (Path, error) { - pt := Path{ - Pkg: pkg, - Name: name, - } - - if strings.HasPrefix(pt.Pkg, "/") || len(pt.Pkg) == 0 { - pt.Name = pt.Pkg - pt.Pkg = i.Module.Path - } - - if len(pt.Name) == 0 { - pt.Name = "/" - } - - if pt.Pkg == pt.Name { - pt.Pkg = i.Module.Path - pt.Name = "/" - } - - if !strings.HasPrefix(pt.Name, "/") { - pt.Name = "/" + pt.Name - } - pt.Name = strings.TrimPrefix(pt.Name, i.Dir) - return pt, nil -} - -var pathrx = regexp.MustCompile("([^:]+)(:(/.+))?") diff --git a/here/parse_test.go b/here/parse_test.go deleted file mode 100644 index b091511..0000000 --- a/here/parse_test.go +++ /dev/null @@ -1,63 +0,0 @@ -package here_test - -import ( - "os" - "path/filepath" - "strings" - "testing" - - "github.com/markbates/pkger/here" - "github.com/markbates/pkger/pkging/pkgtest" - "github.com/stretchr/testify/require" -) - -func Test_Info_Parse(t *testing.T) { - const name = "/public/index.html" - - r := require.New(t) - - app, err := pkgtest.NewRef() - r.NoError(err) - defer os.RemoveAll(app.Dir) - - ip := app.Info.ImportPath - ip2 := "another/app" - - table := []struct { - in string - exp here.Path - err bool - }{ - {in: name, exp: here.Path{Pkg: ip, Name: name}}, - {in: "", exp: here.Path{Pkg: ip, Name: "/"}}, - {in: "/", exp: here.Path{Pkg: ip, Name: "/"}}, - {in: filepath.Join(app.Info.Dir, name), exp: here.Path{Pkg: ip, Name: name}}, - {in: ":" + name, exp: here.Path{Pkg: ip, Name: name}}, - {in: ip + ":" + name, exp: here.Path{Pkg: ip, Name: name}}, - {in: ip, exp: here.Path{Pkg: ip, Name: "/"}}, - {in: ":", exp: here.Path{Pkg: ip, Name: "/"}}, - {in: ip2 + ":" + name, exp: here.Path{Pkg: ip2, Name: name}}, - {in: ip2, exp: here.Path{Pkg: ip2, Name: "/"}}, - {in: ip2 + ":", exp: here.Path{Pkg: ip2, Name: "/"}}, - {in: filepath.Join(app.Info.Dir, "public"), exp: here.Path{Pkg: ip, Name: "/public"}}, - } - - for _, tt := range table { - for _, in := range []string{tt.in, strings.ReplaceAll(tt.in, "/", "\\")} { - t.Run(in, func(st *testing.T) { - r := require.New(st) - - pt, err := app.Info.Parse(in) - - if tt.err { - r.Error(err) - return - } - r.NoError(err) - - r.Equal(tt.exp, pt) - - }) - } - } -} diff --git a/here/path.go b/here/path.go deleted file mode 100644 index b3b3ad0..0000000 --- a/here/path.go +++ /dev/null @@ -1,20 +0,0 @@ -package here - -import ( - "fmt" -) - -type Path struct { - Pkg string - Name string -} - -func (p Path) String() string { - if p.Name == "" { - p.Name = "/" - } - if p.Pkg == "" { - return p.Name - } - return fmt.Sprintf("%s:%s", p.Pkg, p.Name) -} diff --git a/here/pkg.go b/here/pkg.go deleted file mode 100644 index 9d51c07..0000000 --- a/here/pkg.go +++ /dev/null @@ -1,44 +0,0 @@ -package here - -import ( - "encoding/json" - "fmt" -) - -// Package attempts to gather info for the requested package. -// -// From the `go help list` docs: -// The -find flag causes list to identify the named packages but not -// resolve their dependencies: the Imports and Deps lists will be empty. -// -// A workaround for this issue is to use the `Dir` field in the -// returned `Info` value and pass it to the `Dir(string) (Info, error)` -// function to return the complete data. -func Package(p string) (Info, error) { - i, err := Cache(p, func(p string) (Info, error) { - var i Info - if len(p) == 0 || p == "." { - return i, fmt.Errorf("missing package name") - } - b, err := run("go", "list", "-json", "-find", p) - if err != nil { - return i, err - } - if err := json.Unmarshal(b, &i); err != nil { - return i, err - } - - return i, nil - }) - - if err != nil { - return i, err - } - - Cache(i.Dir, func(p string) (Info, error) { - return i, nil - }) - - return i, nil - -} diff --git a/internal/maps/files.go b/internal/maps/files.go index 3b3b6ac..fd32fff 100644 --- a/internal/maps/files.go +++ b/internal/maps/files.go @@ -8,7 +8,7 @@ import ( "sort" "sync" - "github.com/markbates/pkger/here" + "github.com/gobuffalo/here" "github.com/markbates/pkger/pkging" ) diff --git a/internal/maps/infos.go b/internal/maps/infos.go index 0eed02f..cfc0604 100644 --- a/internal/maps/infos.go +++ b/internal/maps/infos.go @@ -8,7 +8,7 @@ import ( "sort" "sync" - "github.com/markbates/pkger/here" + "github.com/gobuffalo/here" ) // Infos wraps sync.Map and uses the following types: diff --git a/parser/file.go b/parser/file.go index 4b626ed..45c9748 100644 --- a/parser/file.go +++ b/parser/file.go @@ -3,7 +3,7 @@ package parser import ( "encoding/json" - "github.com/markbates/pkger/here" + "github.com/gobuffalo/here" ) type File struct { diff --git a/parser/parser.go b/parser/parser.go index 99f6ce2..4244b1c 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -11,7 +11,7 @@ import ( "strings" "sync" - "github.com/markbates/pkger/here" + "github.com/gobuffalo/here" ) var defaultIgnoredFolders = []string{".", "_", "vendor", "node_modules", "testdata"} diff --git a/parser/parser_test.go b/parser/parser_test.go index 65a0ccc..700e51b 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -8,7 +8,7 @@ import ( "strings" "testing" - "github.com/markbates/pkger/here" + "github.com/gobuffalo/here" "github.com/markbates/pkger/pkging/pkgtest" "github.com/markbates/pkger/pkging/stdos" "github.com/stretchr/testify/require" @@ -58,7 +58,6 @@ func Test_Parser_Ref_Include(t *testing.T) { }() r := require.New(t) - here.ClearCache() ref, err := pkgtest.NewRef() r.NoError(err) defer os.RemoveAll(ref.Dir) @@ -93,7 +92,6 @@ func Test_Parser_Ref_Include(t *testing.T) { func Test_Parser_Example_HTTP(t *testing.T) { r := require.New(t) - here.ClearCache() cur, err := here.Package("github.com/markbates/pkger") r.NoError(err) diff --git a/parser/source.go b/parser/source.go index 276f632..02e2b8d 100644 --- a/parser/source.go +++ b/parser/source.go @@ -8,7 +8,7 @@ import ( "strconv" "sync" - "github.com/markbates/pkger/here" + "github.com/gobuffalo/here" ) type Source struct { diff --git a/parser/walk.go b/parser/walk.go index eed6d91..51343b0 100644 --- a/parser/walk.go +++ b/parser/walk.go @@ -7,7 +7,7 @@ import ( "path/filepath" "strings" - "github.com/markbates/pkger/here" + "github.com/gobuffalo/here" ) var _ Decl = WalkDecl{} diff --git a/pkger.go b/pkger.go index 5f56a51..96d1c32 100644 --- a/pkger.go +++ b/pkger.go @@ -6,7 +6,7 @@ import ( "path/filepath" "sync" - "github.com/markbates/pkger/here" + "github.com/gobuffalo/here" "github.com/markbates/pkger/pkging" "github.com/markbates/pkger/pkging/stdos" ) diff --git a/pkging/embed/embed.go b/pkging/embed/embed.go index 29dfdf5..25d6838 100644 --- a/pkging/embed/embed.go +++ b/pkging/embed/embed.go @@ -6,7 +6,7 @@ import ( "encoding/hex" "io" - "github.com/markbates/pkger/here" + "github.com/gobuffalo/here" "github.com/markbates/pkger/internal/takeon/github.com/markbates/hepa" "github.com/markbates/pkger/internal/takeon/github.com/markbates/hepa/filters" ) diff --git a/pkging/embed/file.go b/pkging/embed/file.go index af239f8..964af15 100644 --- a/pkging/embed/file.go +++ b/pkging/embed/file.go @@ -1,7 +1,7 @@ package embed import ( - "github.com/markbates/pkger/here" + "github.com/gobuffalo/here" "github.com/markbates/pkger/pkging" ) diff --git a/pkging/file.go b/pkging/file.go index c7d12a1..6d49cca 100644 --- a/pkging/file.go +++ b/pkging/file.go @@ -4,7 +4,7 @@ import ( "net/http" "os" - "github.com/markbates/pkger/here" + "github.com/gobuffalo/here" ) type File interface { diff --git a/pkging/file_info_test.go b/pkging/file_info_test.go index 6751c0e..c0c3fec 100644 --- a/pkging/file_info_test.go +++ b/pkging/file_info_test.go @@ -6,7 +6,7 @@ import ( "testing" "time" - "github.com/markbates/pkger/here" + "github.com/gobuffalo/here" "github.com/markbates/pkger/pkging" "github.com/stretchr/testify/require" ) diff --git a/pkging/mem/add.go b/pkging/mem/add.go index 56fe549..b21c2d5 100644 --- a/pkging/mem/add.go +++ b/pkging/mem/add.go @@ -6,7 +6,7 @@ import ( "os" "path/filepath" - "github.com/markbates/pkger/here" + "github.com/gobuffalo/here" "github.com/markbates/pkger/pkging" ) @@ -19,7 +19,6 @@ func (fx *Pkger) Add(files ...*os.File) error { if err != nil { return err } - pt, err := fx.Parse(f.Name()) if err != nil { return err diff --git a/pkging/mem/add_test.go b/pkging/mem/add_test.go index 342d048..924d753 100644 --- a/pkging/mem/add_test.go +++ b/pkging/mem/add_test.go @@ -5,7 +5,7 @@ import ( "path/filepath" "testing" - "github.com/markbates/pkger/here" + "github.com/gobuffalo/here" "github.com/markbates/pkger/pkging/mem" "github.com/stretchr/testify/require" ) diff --git a/pkging/mem/embed.go b/pkging/mem/embed.go index a7086ed..76e1db7 100644 --- a/pkging/mem/embed.go +++ b/pkging/mem/embed.go @@ -3,7 +3,7 @@ package mem import ( "encoding/json" - "github.com/markbates/pkger/here" + "github.com/gobuffalo/here" "github.com/markbates/pkger/internal/maps" "github.com/markbates/pkger/pkging" "github.com/markbates/pkger/pkging/embed" diff --git a/pkging/mem/file.go b/pkging/mem/file.go index 2d4d244..18fd2b8 100644 --- a/pkging/mem/file.go +++ b/pkging/mem/file.go @@ -10,7 +10,7 @@ import ( "path/filepath" "time" - "github.com/markbates/pkger/here" + "github.com/gobuffalo/here" "github.com/markbates/pkger/pkging" ) diff --git a/pkging/mem/file_test.go b/pkging/mem/file_test.go index 5ebb32b..986c7fb 100644 --- a/pkging/mem/file_test.go +++ b/pkging/mem/file_test.go @@ -4,7 +4,7 @@ import ( "io/ioutil" "testing" - "github.com/markbates/pkger/here" + "github.com/gobuffalo/here" "github.com/stretchr/testify/require" ) diff --git a/pkging/mem/mem.go b/pkging/mem/mem.go index 1590e3e..dfa3a99 100644 --- a/pkging/mem/mem.go +++ b/pkging/mem/mem.go @@ -8,7 +8,7 @@ import ( "strings" "time" - "github.com/markbates/pkger/here" + "github.com/gobuffalo/here" "github.com/markbates/pkger/internal/maps" "github.com/markbates/pkger/pkging" ) diff --git a/pkging/pkger.go b/pkging/pkger.go index b2076f6..4a7a2fa 100644 --- a/pkging/pkger.go +++ b/pkging/pkger.go @@ -4,7 +4,7 @@ import ( "os" "path/filepath" - "github.com/markbates/pkger/here" + "github.com/gobuffalo/here" ) type Pkger interface { diff --git a/pkging/pkgtest/load_ref.go b/pkging/pkgtest/load_ref.go index e04ce7b..331b093 100644 --- a/pkging/pkgtest/load_ref.go +++ b/pkging/pkgtest/load_ref.go @@ -7,7 +7,7 @@ import ( "path/filepath" "strings" - "github.com/markbates/pkger/here" + "github.com/gobuffalo/here" "github.com/markbates/pkger/pkging" ) diff --git a/pkging/pkgtest/pkgtest.go b/pkging/pkgtest/pkgtest.go index d852fda..11585b7 100644 --- a/pkging/pkgtest/pkgtest.go +++ b/pkging/pkgtest/pkgtest.go @@ -5,7 +5,7 @@ import ( "os" "testing" - "github.com/markbates/pkger/here" + "github.com/gobuffalo/here" "github.com/markbates/pkger/pkging" "github.com/stretchr/testify/require" ) diff --git a/pkging/pkgtest/ref.go b/pkging/pkgtest/ref.go index a9a8dca..84e9ba9 100644 --- a/pkging/pkgtest/ref.go +++ b/pkging/pkgtest/ref.go @@ -8,7 +8,7 @@ import ( "path/filepath" "runtime" - "github.com/markbates/pkger/here" + "github.com/gobuffalo/here" ) type Ref struct { diff --git a/pkging/pkgtest/testdata/ref/go.sum b/pkging/pkgtest/testdata/ref/go.sum index a243cab..37f7a77 100644 --- a/pkging/pkgtest/testdata/ref/go.sum +++ b/pkging/pkgtest/testdata/ref/go.sum @@ -1,6 +1,10 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/gobuffalo/here v0.5.2-0.20191203194143-8e97fc9ad6d3 h1:9NGxHWbGFujaZ5vT+uXurb9m3QoWa175cYM2Qs97nQo= +github.com/gobuffalo/here v0.5.2-0.20191203194143-8e97fc9ad6d3/go.mod h1:wAG085dHOYqUpf+Ap+WOdrPTp5IYcDAs/x7PLa8Y5fM= +github.com/gobuffalo/here v0.6.0 h1:hYrd0a6gDmWxBM4TnrGw8mQg24iSVoIkHEk7FodQcBI= +github.com/gobuffalo/here v0.6.0/go.mod h1:wAG085dHOYqUpf+Ap+WOdrPTp5IYcDAs/x7PLa8Y5fM= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= @@ -18,3 +22,4 @@ gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/pkging/pkgutil/dump.go b/pkging/pkgutil/dump.go index 128161a..ce23c82 100644 --- a/pkging/pkgutil/dump.go +++ b/pkging/pkgutil/dump.go @@ -6,7 +6,7 @@ import ( "io" "os" - "github.com/markbates/pkger/here" + "github.com/gobuffalo/here" "github.com/markbates/pkger/pkging" ) diff --git a/pkging/pkgutil/stuff.go b/pkging/pkgutil/stuff.go index c580c4e..434e85c 100644 --- a/pkging/pkgutil/stuff.go +++ b/pkging/pkgutil/stuff.go @@ -4,7 +4,7 @@ import ( "io" "os" - "github.com/markbates/pkger/here" + "github.com/gobuffalo/here" "github.com/markbates/pkger/parser" "github.com/markbates/pkger/pkging/embed" "github.com/markbates/pkger/pkging/mem" diff --git a/pkging/pkgutil/stuff_test.go b/pkging/pkgutil/stuff_test.go index 681d3f4..68502fa 100644 --- a/pkging/pkgutil/stuff_test.go +++ b/pkging/pkgutil/stuff_test.go @@ -19,6 +19,12 @@ func Test_Stuff(t *testing.T) { r.NoError(err) defer os.RemoveAll(ref.Dir) + pwd, err := os.Getwd() + r.NoError(err) + defer os.Chdir(pwd) + + os.Chdir(ref.Dir) + disk, err := stdos.New(ref.Info) r.NoError(err) diff --git a/pkging/stdos/file.go b/pkging/stdos/file.go index 35845cf..51559f8 100644 --- a/pkging/stdos/file.go +++ b/pkging/stdos/file.go @@ -5,7 +5,7 @@ import ( "os" "path" - "github.com/markbates/pkger/here" + "github.com/gobuffalo/here" "github.com/markbates/pkger/pkging" ) diff --git a/pkging/stdos/file_test.go b/pkging/stdos/file_test.go index a33f29d..9a475bd 100644 --- a/pkging/stdos/file_test.go +++ b/pkging/stdos/file_test.go @@ -3,7 +3,7 @@ package stdos import ( "testing" - "github.com/markbates/pkger/here" + "github.com/gobuffalo/here" "github.com/stretchr/testify/require" ) diff --git a/pkging/stdos/stdos.go b/pkging/stdos/stdos.go index 75777c3..ce34624 100644 --- a/pkging/stdos/stdos.go +++ b/pkging/stdos/stdos.go @@ -6,7 +6,7 @@ import ( "path/filepath" "strings" - "github.com/markbates/pkger/here" + "github.com/gobuffalo/here" "github.com/markbates/pkger/internal/maps" "github.com/markbates/pkger/pkging" ) diff --git a/pkging/wrap.go b/pkging/wrap.go index 438f955..dee4b0a 100644 --- a/pkging/wrap.go +++ b/pkging/wrap.go @@ -5,7 +5,7 @@ import ( "os" "path/filepath" - "github.com/markbates/pkger/here" + "github.com/gobuffalo/here" ) func Wrap(parent, with Pkger) Pkger { From 10f43292e9e0a2662033f9a1e45747a37528f74b Mon Sep 17 00:00:00 2001 From: Mark Bates Date: Tue, 3 Dec 2019 15:11:25 -0500 Subject: [PATCH 2/9] github stuff --- .github/FUNDING.yml | 4 ++++ .github/workflows/release.yml | 2 +- .github/workflows/tests.yml | 18 ++++++++---------- go.sum | 2 -- 4 files changed, 13 insertions(+), 13 deletions(-) create mode 100644 .github/FUNDING.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..65b45f1 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,4 @@ +# These are supported funding model platforms + +github: markbates +patreon: buffalo diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 787c7f5..60d9d7b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -16,7 +16,7 @@ jobs: go-version: 1.13 id: go - - name: Checkout + name: Checkout Code uses: actions/checkout@master - name: Run GoReleaser diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 448a848..0c60853 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -2,24 +2,22 @@ name: Tests on: [push] jobs: - tests: - name: ${{matrix.os}} Tests + tests-on: + name: ${{matrix.go-version}} ${{matrix.os}} runs-on: ${{ matrix.os }} strategy: matrix: + go-version: [1.12.x, 1.13.x] os: [macos-latest, windows-latest, ubuntu-latest] steps: - - name: Set up Go 1.13 - uses: actions/setup-go@v1 - with: - go-version: 1.13 - id: go - - - name: Check out code into the Go module directory + - name: Checkout Code uses: actions/checkout@v1 - + with: + fetch-depth: 1 - name: Test run: | go mod download go mod tidy -v go test -race ./... + + diff --git a/go.sum b/go.sum index 4cc976b..4e6cf81 100644 --- a/go.sum +++ b/go.sum @@ -10,14 +10,12 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.7 h1:VUgggvou5XRW9mHwD/yXxIYSMtY0zoKQf/v226p2nyo= gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= From 94798bc8a614de17783efeda68df1fac4085b1ec Mon Sep 17 00:00:00 2001 From: Mark Bates Date: Tue, 3 Dec 2019 15:13:55 -0500 Subject: [PATCH 3/9] remove 1.12 --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 0c60853..1e9c2fa 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -7,7 +7,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - go-version: [1.12.x, 1.13.x] + go-version: [1.13.x] os: [macos-latest, windows-latest, ubuntu-latest] steps: - name: Checkout Code From b24faf107049e47862bf7ff73b3e5944d4f37227 Mon Sep 17 00:00:00 2001 From: Mark Bates Date: Tue, 3 Dec 2019 15:23:12 -0500 Subject: [PATCH 4/9] get -t --- .github/workflows/tests.yml | 1 + go.sum | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 1e9c2fa..d1b15c0 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -16,6 +16,7 @@ jobs: fetch-depth: 1 - name: Test run: | + go get -t ./... go mod download go mod tidy -v go test -race ./... diff --git a/go.sum b/go.sum index 4e6cf81..77e25e1 100644 --- a/go.sum +++ b/go.sum @@ -10,6 +10,7 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= From ec8c803b2751e912574ad4ff150b8d8268739467 Mon Sep 17 00:00:00 2001 From: Mark Bates Date: Tue, 3 Dec 2019 15:29:17 -0500 Subject: [PATCH 5/9] verbs --- parser/decl.go | 2 +- parser/parser.go | 10 +++++----- parser/source.go | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/parser/decl.go b/parser/decl.go index 762806c..4dd6540 100644 --- a/parser/decl.go +++ b/parser/decl.go @@ -40,7 +40,7 @@ func (decls Decls) Files() ([]*File, error) { files, err := fl.Files(v) if err != nil { - return nil, fmt.Errorf("%w: %s", err, d) + return nil, fmt.Errorf("%s: %s", err, d) } for _, f := range files { diff --git a/parser/parser.go b/parser/parser.go index 4244b1c..cd6997d 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -100,19 +100,19 @@ func (p *Parser) ParseDir(abs string, mode parser.Mode) ([]*ParsedSource, error) her, err := here.Dir(abs) if err != nil { - return nil, fmt.Errorf("%w: here.Dir failed %s", err, abs) + return nil, fmt.Errorf("%s: here.Dir failed %s", err, abs) } pt, err := her.Parse(strings.TrimPrefix(abs, filepath.Dir(abs))) if err != nil { - return nil, fmt.Errorf("%w: here.Parse failed %s", err, abs) + return nil, fmt.Errorf("%s: here.Parse failed %s", err, abs) } fset := token.NewFileSet() pkgs, err := parser.ParseDir(fset, abs, nil, 0) if err != nil { - return nil, fmt.Errorf("%w: ParseDir failed %s", err, abs) + return nil, fmt.Errorf("%s: ParseDir failed %s", err, abs) } var srcs []*ParsedSource @@ -205,13 +205,13 @@ func (p *Parser) parse() error { srcs, err := p.ParseDir(path, 0) if err != nil { - return fmt.Errorf("%w: %s", err, path) + return fmt.Errorf("%s: %s", err, path) } for _, src := range srcs { mm, err := src.DeclsMap() if err != nil { - return fmt.Errorf("%w: %s", err, src.Abs) + return fmt.Errorf("%s: %s", err, src.Abs) } for k, v := range mm { p.decls[k] = append(p.decls[k], v...) diff --git a/parser/source.go b/parser/source.go index 02e2b8d..adab985 100644 --- a/parser/source.go +++ b/parser/source.go @@ -140,26 +140,26 @@ func (p *ParsedSource) parse() error { n := ce.Args[0] val, err := p.value(n) if err != nil { - p.err = fmt.Errorf("%w: %s", err, n) + p.err = fmt.Errorf("%s: %s", err, n) return false } info, err := here.Dir(filepath.Dir(p.Abs)) if err != nil { - p.err = fmt.Errorf("%w: %s", err, p.Abs) + p.err = fmt.Errorf("%s: %s", err, p.Abs) return false } pt, err := info.Parse(val) if err != nil { - p.err = fmt.Errorf("%w: %s", err, p.Abs) + p.err = fmt.Errorf("%s: %s", err, p.Abs) return false } if pt.Pkg != info.Module.Path { info, err = here.Package(pt.Pkg) if err != nil { - p.err = fmt.Errorf("%w: %s", err, p.Abs) + p.err = fmt.Errorf("%s: %s", err, p.Abs) return false } } From e4d652a24e48ce4935ed55f67401a340c61ab003 Mon Sep 17 00:00:00 2001 From: Mark Bates Date: Tue, 3 Dec 2019 15:32:08 -0500 Subject: [PATCH 6/9] revert --- .github/workflows/tests.yml | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d1b15c0..448a848 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -2,23 +2,24 @@ name: Tests on: [push] jobs: - tests-on: - name: ${{matrix.go-version}} ${{matrix.os}} + tests: + name: ${{matrix.os}} Tests runs-on: ${{ matrix.os }} strategy: matrix: - go-version: [1.13.x] os: [macos-latest, windows-latest, ubuntu-latest] steps: - - name: Checkout Code - uses: actions/checkout@v1 + - name: Set up Go 1.13 + uses: actions/setup-go@v1 with: - fetch-depth: 1 + go-version: 1.13 + id: go + + - name: Check out code into the Go module directory + uses: actions/checkout@v1 + - name: Test run: | - go get -t ./... go mod download go mod tidy -v go test -race ./... - - From 0167919fceae46f56fc7199729f1ed8a3757a7f4 Mon Sep 17 00:00:00 2001 From: Mark Bates Date: Tue, 3 Dec 2019 17:36:58 -0500 Subject: [PATCH 7/9] ignore .tmp stuff --- pkging/pkgutil/stuff.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkging/pkgutil/stuff.go b/pkging/pkgutil/stuff.go index 434e85c..698baad 100644 --- a/pkging/pkgutil/stuff.go +++ b/pkging/pkgutil/stuff.go @@ -3,6 +3,7 @@ package pkgutil import ( "io" "os" + "strings" "github.com/gobuffalo/here" "github.com/markbates/pkger/parser" @@ -23,6 +24,9 @@ func Stuff(w io.Writer, c here.Info, decls parser.Decls) error { for _, pf := range files { err = func() error { + if strings.HasSuffix(pf.Abs, ".tmp") { + return nil + } df, err := os.Open(pf.Abs) if err != nil { return err From 64316345119d8dcc542b2ebb91d990c6feec9f9e Mon Sep 17 00:00:00 2001 From: Mark Bates Date: Tue, 3 Dec 2019 17:40:04 -0500 Subject: [PATCH 8/9] better error --- pkging/pkgutil/stuff.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkging/pkgutil/stuff.go b/pkging/pkgutil/stuff.go index 698baad..c81a83e 100644 --- a/pkging/pkgutil/stuff.go +++ b/pkging/pkgutil/stuff.go @@ -1,6 +1,7 @@ package pkgutil import ( + "fmt" "io" "os" "strings" @@ -29,7 +30,7 @@ func Stuff(w io.Writer, c here.Info, decls parser.Decls) error { } df, err := os.Open(pf.Abs) if err != nil { - return err + return fmt.Errorf("could open stuff %s: %s", pf.Abs, err) } defer df.Close() From db2f21a8c798f22f7ee36b365eced57e0153c0a1 Mon Sep 17 00:00:00 2001 From: Mark Bates Date: Tue, 17 Dec 2019 10:16:55 -0500 Subject: [PATCH 9/9] see yourself --- parser/include.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parser/include.go b/parser/include.go index cb95500..afe9433 100644 --- a/parser/include.go +++ b/parser/include.go @@ -7,7 +7,7 @@ import ( "os" "path/filepath" - "github.com/markbates/pkger/here" + "github.com/gobuffalo/here" ) var _ Decl = IncludeDecl{}