Skip to content

Commit

Permalink
added support .nvmrc
Browse files Browse the repository at this point in the history
Before installing nvm, checks the availability of the .nvmrc file and, if it exists, takes the version from the .nvmrc file and overrides the version in the configuration
  • Loading branch information
psihachina committed Sep 28, 2022
1 parent 8c3d230 commit ac9abba
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions internal/manager/serverless/native.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"os/exec"
"path/filepath"
"strings"
)

func (sls *Manager) runNpmInstall(w io.Writer) error {
Expand Down Expand Up @@ -33,14 +34,25 @@ func (sls *Manager) runNvm(w io.Writer) error {
if len(nvmDir) == 0 {
nvmDir = "$HOME/.nvm"
}
var command string
_, err := os.Stat(filepath.Join(sls.App.Path, ".nvmrc"))
if os.IsNotExist(err) {
command = fmt.Sprintf("source %s/nvm.sh && nvm install %s", nvmDir, sls.App.NodeVersion)

command := fmt.Sprintf("source %s/nvm.sh && nvm install %s", nvmDir, sls.App.NodeVersion)
} else {
file, err := os.ReadFile(filepath.Join(sls.App.Path, ".nvmrc"))
if err != nil {
return fmt.Errorf("can't read .nvmrc: %w", err)
}
sls.App.NodeVersion = strings.TrimSpace(string(file))
command = fmt.Sprintf("source %s/nvm.sh && nvm install %s", nvmDir, sls.App.NodeVersion)
}

cmd := exec.Command("bash", "-c", command)
cmd.Stdout = w
cmd.Stderr = w
cmd.Dir = filepath.Join(sls.App.Path)
err := cmd.Run()
err = cmd.Run()
if err != nil {
return err
}
Expand Down

0 comments on commit ac9abba

Please sign in to comment.