Skip to content

Commit

Permalink
feat(mod): utilize ~/.gno dir (#652)
Browse files Browse the repository at this point in the history
  • Loading branch information
harry-hov authored Mar 27, 2023
1 parent a29eb93 commit c128f13
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 19 deletions.
6 changes: 1 addition & 5 deletions cmd/gnodev/mod.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
4 changes: 2 additions & 2 deletions pkgs/crypto/keys/client/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand Down
16 changes: 4 additions & 12 deletions pkgs/gnolang/gnomod/gnomod.go
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit c128f13

Please sign in to comment.