Skip to content

Commit

Permalink
Replace existing gno.mod file
Browse files Browse the repository at this point in the history
  • Loading branch information
harry-hov committed Aug 19, 2023
1 parent a08fc14 commit 6507caf
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions gnovm/cmd/gno/mod.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
"github.com/gnolang/gno/gnovm/pkg/gnomod"
"github.com/gnolang/gno/tm2/pkg/commands"
"github.com/gnolang/gno/tm2/pkg/errors"
"golang.org/x/mod/modfile"
"golang.org/x/mod/module"
)

type modDownloadCfg struct {
Expand Down Expand Up @@ -181,24 +183,30 @@ func execModTidy(args []string, io *commands.IO) error {
if err != nil {
return err
}
// TODO: allow from sub dir?
modPath := filepath.Join(wd, "gno.mod")
if !isFileExist(modPath) {
return errors.New("gno.mod not found")

gm, err := gnomod.ParseAt(wd)
if err != nil {
return err
}

imports, err := getGnoImports(wd)
if err != nil {
return err
}

// Print imports
// TODO: remove
for i := range imports {
fmt.Println(imports[i])
// TODO: handle edge cases
var requires []*modfile.Require

Check failure on line 198 in gnovm/cmd/gno/mod.go

View workflow job for this annotation

GitHub Actions / lint

Consider pre-allocating `requires` (prealloc)
for _, im := range imports {
requires = append(requires, &modfile.Require{
Mod: module.Version{
Path: im,
Version: "v0.0.0-latest",
},
})
}

// TODO: Add imports to gno.mod file
gm.Require = requires
// TODO: Fix: gno.mod can be in any parent dir of `wd`
gm.WriteToPath(filepath.Join(wd, "gno.mod"))

return nil
}
Expand Down

0 comments on commit 6507caf

Please sign in to comment.