Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(mod): utilize ~/.gno dir #652

Merged
merged 1 commit into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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