fixed merge conflicts

This commit is contained in:
coreybutler
2021-09-11 01:13:13 -05:00
2 changed files with 63 additions and 21 deletions

View File

@@ -5,6 +5,7 @@ import (
"fmt"
"io/ioutil"
"log"
"net/url"
"os"
"os/exec"
"path/filepath"
@@ -179,6 +180,7 @@ func update() {
*/
func install(version string, cpuarch string) {
requestedVersion := version
args := os.Args
lastarg := args[len(args)-1]
@@ -225,6 +227,17 @@ func install(version string, cpuarch string) {
version = cleanVersion(version)
}
v, err := semver.Make(version)
if err == nil {
err = v.Validate()
}
if err != nil {
fmt.Println("\"" + requestedVersion + "\" is not a valid version.")
fmt.Println("Please use a valid semantic version number, \"lts\", or \"latest\".")
return
}
if checkVersionExceedsLatest(version) {
fmt.Println("Node.js v" + version + " is not yet released or available.")
return
@@ -368,6 +381,20 @@ func uninstall(version string) {
return
}
if strings.ToLower(version) == "latest" {
version = getLatest()
} else if strings.ToLower(version) == "lts" {
version = getLTS()
} else if strings.ToLower(version) == "newest" {
installed := node.GetInstalled(env.root)
if len(installed) == 0 {
fmt.Println("No versions of node.js found. Try installing the latest by typing nvm install latest")
return
}
version = installed[0]
}
version = cleanVersion(version)
// Determine if the version exists and skip if it doesn't
@@ -786,28 +813,43 @@ func setup() {
}
// Process each line and extract the value
m := make(map[string]string)
for _, line := range lines {
line = strings.Trim(line, " \r\n")
line = strings.TrimSpace(line)
line = os.ExpandEnv(line)
if strings.HasPrefix(line, "root:") {
env.root = filepath.Clean(strings.TrimSpace(regexp.MustCompile("^root:").ReplaceAllString(line, "")))
} else if strings.HasPrefix(line, "originalpath:") {
env.originalpath = filepath.Clean(strings.TrimSpace(regexp.MustCompile("^originalpath:").ReplaceAllString(line, "")))
} else if strings.HasPrefix(line, "originalversion:") {
env.originalversion = strings.TrimSpace(regexp.MustCompile("^originalversion:").ReplaceAllString(line, ""))
} else if strings.HasPrefix(line, "arch:") {
env.arch = strings.TrimSpace(regexp.MustCompile("^arch:").ReplaceAllString(line, ""))
} else if strings.HasPrefix(line, "node_mirror:") {
env.node_mirror = strings.TrimSpace(regexp.MustCompile("^node_mirror:").ReplaceAllString(line, ""))
} else if strings.HasPrefix(line, "npm_mirror:") {
env.npm_mirror = strings.TrimSpace(regexp.MustCompile("^npm_mirror:").ReplaceAllString(line, ""))
} else if strings.HasPrefix(line, "proxy:") {
env.proxy = strings.TrimSpace(regexp.MustCompile("^proxy:").ReplaceAllString(line, ""))
if env.proxy != "none" && env.proxy != "" {
if strings.ToLower(env.proxy[0:4]) != "http" {
env.proxy = "http://" + env.proxy
}
web.SetProxy(env.proxy, env.verifyssl)
res := strings.Split(line, ":")
if len(res) < 2 {
continue
}
m[res[0]] = strings.TrimSpace(strings.Join(res[1:], ":"))
}
if val, ok := m["root"]; ok {
env.root = filepath.Clean(val)
}
if val, ok := m["originalpath"]; ok {
env.originalpath = filepath.Clean(val)
}
if val, ok := m["originalversion"]; ok {
env.originalversion = val
}
if val, ok := m["arch"]; ok {
env.arch = val
}
if val, ok := m["node_mirror"]; ok {
env.node_mirror = val
}
if val, ok := m["npm_mirror"]; ok {
env.npm_mirror = val
}
if val, ok := m["proxy"]; ok {
if val != "none" && val != "" {
if strings.ToLower(val[0:4]) != "http" {
val = "http://" + val
}
res, err := url.Parse(val)
if err != nil {
web.SetProxy(res.String(), env.verifyssl)
}
}
}