Skip to content

added .dvmrc version lock support #22

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,19 @@ $ dvm upgrade # upgrade to latest
$ dvm upgrade v0.2.0 # Update to specified version
```

### .dvmrc

You can use `.dvmrc` file to lock your deno project to a specific version

When you run the `dvm use` command, dvm will pick your deno version

```bash
# .dvmrc
v1.0.0 # this can be 1.0.0 as well

$ dvm use
```

### Uninstall

run the following command to uninstall `dvm` or remove `dvm` executable file and `$HOME/.dvm` folder by manual
Expand Down
19 changes: 19 additions & 0 deletions internal/command/use.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"path"
"runtime"
"strings"

"github.com/axetroy/dvm/internal/core"
"github.com/axetroy/dvm/internal/fs"
Expand All @@ -15,6 +16,16 @@ import (

// use Deno
func Use(version string) error {
if version == "" {
data, _ := ioutil.ReadFile(".dvmrc")

if data == nil {
return errors.New(fmt.Sprintf("No .dvmrc file found \n\nrequire argument <%s>", "version"))
} else {
version = setCharV(strings.TrimSpace(string(data)))
}
}

files, err := ioutil.ReadDir(core.ReleaseDir)

if err != nil {
Expand Down Expand Up @@ -61,3 +72,11 @@ func Use(version string) error {

return nil
}

func setCharV(version string) string {
if string(version[0]) != "v" {
return "v" + string(version)
}

return string(version)
}
8 changes: 5 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,12 @@ SOURCE CODE:
Usage: "Use specified Deno version",
ArgsUsage: "<version>",
Action: func(c *cli.Context) error {
if c.Args().Len() == 0 {
return errors.New(fmt.Sprintf("require argument <%s>", "version"))
var version string

if c.Args().Len() != 0 {
version = c.Args().First()
}
return command.Use(c.Args().First())
return command.Use(version)
},
},
{
Expand Down