55 "compress/gzip"
66 "crypto/md5"
77 "fmt"
8- "go/build"
98 "html/template"
109 "io"
1110 "io/ioutil"
@@ -17,7 +16,6 @@ import (
1716 "strings"
1817 "sync"
1918
20- "github.com/gobuffalo/packr/v2/internal"
2119 "github.com/karrick/godirwalk"
2220
2321 "github.com/gobuffalo/packr/v2/file/resolver/encoding/hex"
@@ -255,49 +253,34 @@ func (d *Disk) Close() error {
255253 }
256254
257255 var ip string
258- if internal .Mods () {
259- // Starting in 1.12, we can rely on Go's method for
260- // resolving where go.mod resides. Prior versions will
261- // simply return an empty string.
262- cmd := exec .Command ("go" , "env" , "GOMOD" )
263- out , err := cmd .Output ()
264- if err != nil {
265- return fmt .Errorf ("go.mod cannot be read or does not exist while go module is enabled" )
266- }
267- mp := strings .TrimSpace (string (out ))
268- if mp == "" {
269- // We are on a prior version of Go; try and do
270- // the resolution ourselves.
271- mp = filepath .Join (filepath .Dir (d .DBPath ), "go.mod" )
272- if _ , err := os .Stat (mp ); err != nil {
273- mp = filepath .Join (d .DBPath , "go.mod" )
274- }
275- }
276-
277- moddata , err := ioutil .ReadFile (mp )
278- if err != nil {
279- return fmt .Errorf ("go.mod cannot be read or does not exist while go module is enabled" )
280- }
281- ip = modfile .ModulePath (moddata )
282- if ip == "" {
283- return fmt .Errorf ("go.mod is malformed" )
284- }
285- ip = filepath .Join (ip , strings .TrimPrefix (filepath .Dir (d .DBPath ), filepath .Dir (mp )))
286- ip = strings .Replace (ip , "\\ " , "/" , - 1 )
287- } else {
288- ip = filepath .Dir (d .DBPath )
289- srcs := internal .GoPaths ()
290- srcs = append (srcs , build .Default .SrcDirs ()... )
291- for _ , x := range srcs {
292- ip = strings .TrimPrefix (ip , "/private" )
293- ip = strings .TrimPrefix (ip , x )
256+ // Starting in 1.12, we can rely on Go's method for
257+ // resolving where go.mod resides. Prior versions will
258+ // simply return an empty string.
259+ cmd := exec .Command ("go" , "env" , "GOMOD" )
260+ out , err := cmd .Output ()
261+ if err != nil {
262+ return fmt .Errorf ("go.mod cannot be read or does not exist while go module is enabled" )
263+ }
264+ mp := strings .TrimSpace (string (out ))
265+ if mp == "" {
266+ // We are on a prior version of Go; try and do
267+ // the resolution ourselves.
268+ mp = filepath .Join (filepath .Dir (d .DBPath ), "go.mod" )
269+ if _ , err := os .Stat (mp ); err != nil {
270+ mp = filepath .Join (d .DBPath , "go.mod" )
294271 }
295- ip = strings .TrimPrefix (ip , string (filepath .Separator ))
296- ip = strings .TrimPrefix (ip , "src" )
297- ip = strings .TrimPrefix (ip , string (filepath .Separator ))
272+ }
298273
299- ip = strings .Replace (ip , "\\ " , "/" , - 1 )
274+ moddata , err := ioutil .ReadFile (mp )
275+ if err != nil {
276+ return fmt .Errorf ("go.mod cannot be read or does not exist while go module is enabled" )
277+ }
278+ ip = modfile .ModulePath (moddata )
279+ if ip == "" {
280+ return fmt .Errorf ("go.mod is malformed" )
300281 }
282+ ip = filepath .Join (ip , strings .TrimPrefix (filepath .Dir (d .DBPath ), filepath .Dir (mp )))
283+ ip = strings .Replace (ip , "\\ " , "/" , - 1 )
301284 ip = path .Join (ip , d .DBPackage )
302285
303286 for _ , n := range opts .Boxes {
0 commit comments