From 1718fcb06ee1c4bedd53113e4188594c20c95c77 Mon Sep 17 00:00:00 2001 From: Hariom Verma Date: Mon, 27 Mar 2023 01:23:49 +0530 Subject: [PATCH] feat(mod): utilize `~/.gno` dir --- cmd/gnodev/mod.go | 6 +----- pkgs/crypto/keys/client/common.go | 4 ++-- pkgs/gnolang/gnomod/gnomod.go | 16 ++++------------ 3 files changed, 7 insertions(+), 19 deletions(-) diff --git a/cmd/gnodev/mod.go b/cmd/gnodev/mod.go index 861386234c2..682442ef1fc 100644 --- a/cmd/gnodev/mod.go +++ b/cmd/gnodev/mod.go @@ -92,12 +92,8 @@ func execModDownload(cfg *modDownloadCfg, args []string, io *commands.IO) error return fmt.Errorf("validate: %w", err) } - gnoModPath, err := gnomod.GetGnoModPath() - if err != nil { - return fmt.Errorf("get gno.mod path: %w", err) - } // fetch dependencies - if err := gnoMod.FetchDeps(gnoModPath, cfg.remote); err != nil { + if err := gnoMod.FetchDeps(gnomod.GetGnoModPath(), cfg.remote); err != nil { return fmt.Errorf("fetch: %w", err) } diff --git a/pkgs/crypto/keys/client/common.go b/pkgs/crypto/keys/client/common.go index cf070ce5040..b26ac64f540 100644 --- a/pkgs/crypto/keys/client/common.go +++ b/pkgs/crypto/keys/client/common.go @@ -13,13 +13,13 @@ type BaseOptions struct { } var DefaultBaseOptions = BaseOptions{ - Home: homeDir(), + Home: HomeDir(), Remote: "127.0.0.1:26657", Quiet: false, InsecurePasswordStdin: false, } -func homeDir() string { +func HomeDir() string { // if environment set, always use that. hd := os.Getenv("GNO_HOME") if hd != "" { diff --git a/pkgs/gnolang/gnomod/gnomod.go b/pkgs/gnolang/gnomod/gnomod.go index d47e91398f0..c0fcfb961fa 100644 --- a/pkgs/gnolang/gnomod/gnomod.go +++ b/pkgs/gnolang/gnomod/gnomod.go @@ -1,12 +1,12 @@ package gnomod import ( - "errors" "fmt" "os" "path/filepath" "strings" + "github.com/gnolang/gno/pkgs/crypto/keys/client" "github.com/gnolang/gno/pkgs/gnolang" "github.com/gnolang/gno/pkgs/std" "golang.org/x/mod/modfile" @@ -16,13 +16,8 @@ import ( const queryPathFile = "vm/qfile" // GetGnoModPath returns the path for gno modules -func GetGnoModPath() (string, error) { - goPath := os.Getenv("GOPATH") - if goPath == "" { - return "", errors.New("GOPATH not found") - } - - return filepath.Join(goPath, "pkg", "gnomod"), nil +func GetGnoModPath() string { + return filepath.Join(client.HomeDir(), "pkg", "mod") } func writePackage(remote, basePath, pkgPath string) (requirements []string, err error) { @@ -77,10 +72,7 @@ func writePackage(remote, basePath, pkgPath string) (requirements []string, err // GnoToGoMod make necessary modifications in the gno.mod // and return go.mod file. func GnoToGoMod(f File) (*File, error) { - gnoModPath, err := GetGnoModPath() - if err != nil { - return nil, err - } + gnoModPath := GetGnoModPath() if strings.HasPrefix(f.Module.Mod.Path, gnolang.GnoRealmPkgsPrefixBefore) || strings.HasPrefix(f.Module.Mod.Path, gnolang.GnoPackagePrefixBefore) {