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

Commit

Permalink
Remove packr2 dep on envy (#257)
Browse files Browse the repository at this point in the history
* Remove packr2 dep on envy

Extract the only parts needed from envy. This will prevent the envy
package to load .env files on init and cause unexpected behavior.

* Fix duplicate go version in disk-pack/go.mod
  • Loading branch information
stanislas-m authored Mar 1, 2020
1 parent af4670f commit b4b6d10
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 24 deletions.
5 changes: 3 additions & 2 deletions v2/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ module github.com/gobuffalo/packr/v2
go 1.13

require (
github.com/gobuffalo/envy v1.7.1
github.com/gobuffalo/logger v1.0.1
github.com/gobuffalo/logger v1.0.3
github.com/gobuffalo/packd v0.3.0
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
github.com/rogpeppe/go-internal v1.4.0
github.com/sirupsen/logrus v1.4.2
github.com/spf13/cobra v0.0.5
github.com/stretchr/testify v1.4.0
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e
golang.org/x/sys v0.0.0-20190515120540-06a5c4944438 // indirect
golang.org/x/tools v0.0.0-20191004055002-72853e10c5a3
)
16 changes: 4 additions & 12 deletions v2/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,13 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
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/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/gobuffalo/envy v1.7.0/go.mod h1:n7DRkBerg/aorDM8kbduw5dN3oXGswK5liaSCx4T5NI=
github.com/gobuffalo/envy v1.7.1 h1:OQl5ys5MBea7OGCdvPbBJWRgnhC/fGona6QKfvFeau8=
github.com/gobuffalo/envy v1.7.1/go.mod h1:FurDp9+EDPE4aIUS3ZLyD+7/9fpx7YRt/ukY6jIHf0w=
github.com/gobuffalo/logger v1.0.1 h1:ZEgyRGgAm4ZAhAO45YXMs5Fp+bzGLESFewzAVBMKuTg=
github.com/gobuffalo/logger v1.0.1/go.mod h1:2zbswyIUa45I+c+FLXuWl9zSWEiVuthsk8ze5s8JvPs=
github.com/gobuffalo/logger v1.0.3 h1:YaXOTHNPCvkqqA7w05A4v0k2tCdpr+sgFlgINbQ6gqc=
github.com/gobuffalo/logger v1.0.3/go.mod h1:SoeejUwldiS7ZsyCBphOGURmWdwUFXs0J7TCjEhjKxM=
github.com/gobuffalo/packd v0.3.0 h1:eMwymTkA1uXsqxS0Tpoop3Lc0u3kTfiMBE6nKtQU4g4=
github.com/gobuffalo/packd v0.3.0/go.mod h1:zC7QkmNkYVGKPw4tHpBQ+ml7W/3tIebgeo1b36chA3Q=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s=
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
Expand All @@ -34,9 +29,6 @@ github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
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/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.3.2/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/rogpeppe/go-internal v1.4.0 h1:LUa41nrWTQNGhzdsZ5lTnkwbNjj6rXTdazA1cSdjkOY=
github.com/rogpeppe/go-internal v1.4.0/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
Expand All @@ -60,8 +52,8 @@ github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljT
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190621222207-cc06ce4a13d4 h1:ydJNl0ENAG67pFbB+9tfhiL2pYqLhfoaZFw/cjLhY4A=
golang.org/x/crypto v0.0.0-20190621222207-cc06ce4a13d4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191122220453-ac88ee75c92c h1:/nJuwDLoL/zrqY6gf57vxC+Pi+pZ8bfhpPkicO5H7W4=
golang.org/x/crypto v0.0.0-20191122220453-ac88ee75c92c/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859 h1:R/3boaszxrf1GEUWTVDzSKVwLmSJpwZ1yqXm8j0v2QI=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
Expand Down
3 changes: 1 addition & 2 deletions v2/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"runtime"
"strings"

"github.com/gobuffalo/envy"
"github.com/gobuffalo/packr/v2/plog"
)

Expand All @@ -31,7 +30,7 @@ func resolutionDirTestFilename(filename, og string) (string, bool) {
return ng, true
}

ng = filepath.Join(envy.GoPath(), "src", ng)
ng = filepath.Join(os.Getenv("GOPATH"), "src", ng)
if resolutionDirExists(ng, og) {
return ng, true
}
Expand Down
37 changes: 37 additions & 0 deletions v2/internal/envy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package internal

import (
"os"
"runtime"
"strings"
)

// Mods returns true when go modules supports is enabled
func Mods() bool {
go111 := os.Getenv("GO111MODULE")

if !inGoPath() {
return go111 != "off"
}

return go111 == "on"
}

func inGoPath() bool {
pwd, _ := os.Getwd()
for _, p := range GoPaths() {
if strings.HasPrefix(pwd, p) {
return true
}
}
return false
}

// GoPaths return the defined gopath list.
func GoPaths() []string {
gp := os.Getenv("GOPATH")
if runtime.GOOS == "windows" {
return strings.Split(gp, ";") // Windows uses a different separator
}
return strings.Split(gp, ":")
}
6 changes: 3 additions & 3 deletions v2/jam/store/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"compress/gzip"
"crypto/md5"
"fmt"
"github.com/gobuffalo/packr/v2/internal"
"go/build"
"html/template"
"io"
Expand All @@ -17,7 +18,6 @@ import (
"strings"
"sync"

"github.com/gobuffalo/envy"
"github.com/gobuffalo/packr/v2/file/resolver/encoding/hex"
"github.com/gobuffalo/packr/v2/plog"
"github.com/rogpeppe/go-internal/modfile"
Expand Down Expand Up @@ -254,7 +254,7 @@ func (d *Disk) Close() error {
}

var ip string
if envy.Mods() {
if internal.Mods() {
// Starting in 1.12, we can rely on Go's method for
// resolving where go.mod resides. Prior versions will
// simply return an empty string.
Expand Down Expand Up @@ -285,7 +285,7 @@ func (d *Disk) Close() error {
ip = strings.Replace(ip, "\\", "/", -1)
} else {
ip = filepath.Dir(d.DBPath)
srcs := envy.GoPaths()
srcs := internal.GoPaths()
srcs = append(srcs, build.Default.SrcDirs()...)
for _, x := range srcs {
ip = strings.TrimPrefix(ip, "/private")
Expand Down
3 changes: 0 additions & 3 deletions v2/packr2/cmd/fix/fix.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@ import (
"os"
"strings"

"github.com/gobuffalo/envy"
"github.com/gobuffalo/packr/v2/jam/store"
)

var modsOn = (strings.TrimSpace(envy.Get("GO111MODULE", "off")) == "on")

//YesToAll will be used by the command to skip the questions
var YesToAll bool

Expand Down
7 changes: 5 additions & 2 deletions v2/packr2/cmd/gocmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"path/filepath"
"strings"

"github.com/gobuffalo/envy"
"github.com/gobuffalo/packr/v2/plog"
)

Expand Down Expand Up @@ -55,7 +54,11 @@ func goCmd(name string, args ...string) error {
}
}

cp := exec.Command(envy.Get("GO_BIN", "go"), cargs...)
goBin := os.Getenv("GO_BIN")
if goBin == "" {
goBin = "go"
}
cp := exec.Command(goBin, cargs...)
plog.Logger.Debug(strings.Join(cp.Args, " "))
cp.Stderr = os.Stderr
cp.Stdin = os.Stdin
Expand Down

0 comments on commit b4b6d10

Please sign in to comment.