From ac9abbac570f175895b75e2276e3ae37773acbdd Mon Sep 17 00:00:00 2001 From: psihachina Date: Wed, 28 Sep 2022 10:00:20 +0300 Subject: [PATCH] added support .nvmrc 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 --- internal/manager/serverless/native.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/internal/manager/serverless/native.go b/internal/manager/serverless/native.go index fae3eef1..66becf87 100644 --- a/internal/manager/serverless/native.go +++ b/internal/manager/serverless/native.go @@ -6,6 +6,7 @@ import ( "os" "os/exec" "path/filepath" + "strings" ) func (sls *Manager) runNpmInstall(w io.Writer) error { @@ -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 }