From 85d8e9a21b2cfe416a4ff3c4b5915f8410d59efd Mon Sep 17 00:00:00 2001 From: Michael-Rainabba Richardson Date: Sat, 19 Sep 2015 10:40:18 -0700 Subject: [PATCH 1/2] Restructure to deal with new node release structure at http://nodejs.org/dist/ This is untested because the build chain isn't one I'm prepared to deal with. --- nvm.iss | 2 +- src/nvm.go | 2 +- src/nvm/web/web.go | 69 ++++++++++++++++++++++++++-------------------- 3 files changed, 41 insertions(+), 32 deletions(-) diff --git a/nvm.iss b/nvm.iss index 39a9fee5..7e4097ab 100644 --- a/nvm.iss +++ b/nvm.iss @@ -1,7 +1,7 @@ #define MyAppName "NVM for Windows" #define MyAppShortName "nvm" #define MyAppLCShortName "nvm" -#define MyAppVersion "1.0.6" +#define MyAppVersion "1.1.0" #define MyAppPublisher "Ecor Ventures, LLC" #define MyAppURL "http://github.com/coreybutler/nvm" #define MyAppExeName "nvm.exe" diff --git a/src/nvm.go b/src/nvm.go index 52023015..329a83ff 100644 --- a/src/nvm.go +++ b/src/nvm.go @@ -18,7 +18,7 @@ import ( ) const ( - NvmVersion = "1.0.6" + NvmVersion = "1.1.0" ) type Environment struct { diff --git a/src/nvm/web/web.go b/src/nvm/web/web.go index a4f7e42e..10dd7794 100644 --- a/src/nvm/web/web.go +++ b/src/nvm/web/web.go @@ -59,26 +59,42 @@ func GetNodeJS(root string, v string, a string) bool { a = arch.Validate(a) - url := "" + vpre := "" + vers := strings.Fields(strings.Replace(v,"."," ",-1)) + main, _ := strconv.ParseInt(vers[0],0,0) + if a == "32" { - url = "http://nodejs.org/dist/v"+v+"/node.exe" - } else { - if !IsNode64bitAvailable(v) { - fmt.Println("Node.js v"+v+" is only available in 32-bit.") - return false + if main > 0 { + vpre = "win-x86/" + } else { + vpre = "" + } + } else if a == "64" { + if main > 0 { + vpre = "win-x64/" + } else { + vpre = "x64/" } - url = "http://nodejs.org/dist/v"+v+"/x64/node.exe" } - fileName := root+"\\v"+v+"\\node"+a+".exe" - - fmt.Printf("Downloading node.js version "+v+" ("+a+"-bit)... ") + + url := getNodeUrl ( v, vpre ); - if Download(url,fileName) { - fmt.Printf("Complete\n") - return true + if url == "" { + //No url should mean this version/arch isn't available + fmt.Println("Node.js v"+v+" " + a + "bit isn't available right now.") } else { - return false + fileName := root+"\\v"+v+"\\node"+a+".exe" + + fmt.Printf("Downloading node.js version "+v+" ("+a+"-bit)... ") + + if Download(url,fileName) { + fmt.Printf("Complete\n") + return true + } else { + return false + } } + return false } @@ -126,23 +142,16 @@ func GetRemoteTextFile(url string) string { return "" } -func IsNode64bitAvailable(v string) bool { - if v == "latest" { - return true - } - - // Anything below version 8 doesn't have a 64 bit version - vers := strings.Fields(strings.Replace(v,"."," ",-1)) - main, _ := strconv.ParseInt(vers[0],0,0) - minor, _ := strconv.ParseInt(vers[1],0,0) - if main == 0 && minor < 8 { - return false - } - +func getNodeUrl (v string, vpre string) string { + url := "http://nodejs.org/dist/v"+v+"/" + vpre + "/node.exe" // Check online to see if a 64 bit version exists - res, err := client.Head("http://nodejs.org/dist/v"+v+"/x64/node.exe") + res, err := client.Head( url ) if err != nil { - return false + return "" + } + if res.StatusCode == 200 { + return url + } else { + return "" } - return res.StatusCode == 200 } From 0bc5644af482c637898164e4076fafcba90d3741 Mon Sep 17 00:00:00 2001 From: Patrick Sullivan Date: Wed, 30 Sep 2015 11:46:02 -0700 Subject: [PATCH 2/2] fix: node v4 support works fix: 'install latest' works fix: current version arch works --- src/nvm.go | 20 ++++++++++---------- src/nvm/node/node.go | 26 +++++++++++++++----------- src/nvm/web/web.go | 17 +++++++++++++++++ 3 files changed, 42 insertions(+), 21 deletions(-) diff --git a/src/nvm.go b/src/nvm.go index 329a83ff..46ced549 100644 --- a/src/nvm.go +++ b/src/nvm.go @@ -120,11 +120,11 @@ func update() { } func CheckVersionExceedsLatest(version string) bool{ - content := web.GetRemoteTextFile("http://nodejs.org/dist/latest/SHASUMS.txt") + content := web.GetRemoteTextFile("http://nodejs.org/dist/latest/SHASUMS256.txt") re := regexp.MustCompile("node-v(.+)+msi") reg := regexp.MustCompile("node-v|-x.+") latest := reg.ReplaceAllString(re.FindString(content),"") - + if version <= latest { return false } else { @@ -155,6 +155,14 @@ func install(version string, cpuarch string) { cpuarch = arch.Validate(cpuarch) } + // If user specifies "latest" version, find out what version is + if version == "latest" { + content := web.GetRemoteTextFile("http://nodejs.org/dist/latest/SHASUMS256.txt") + re := regexp.MustCompile("node-v(.+)+msi") + reg := regexp.MustCompile("node-v|-x.+") + version = reg.ReplaceAllString(re.FindString(content),"") + } + if CheckVersionExceedsLatest(version) { fmt.Println("Node.js v"+version+" is not yet released or available.") return @@ -165,14 +173,6 @@ func install(version string, cpuarch string) { return } - // If user specifies "latest" version, find out what version is - if version == "latest" { - content := web.GetRemoteTextFile("http://nodejs.org/dist/latest/SHASUMS.txt") - re := regexp.MustCompile("node-v(.+)+msi") - reg := regexp.MustCompile("node-v|-x.+") - version = reg.ReplaceAllString(re.FindString(content),"") - } - // Check to see if the version is already installed if !node.IsVersionInstalled(env.root,version,cpuarch) { diff --git a/src/nvm/node/node.go b/src/nvm/node/node.go index 0e586d30..739522df 100644 --- a/src/nvm/node/node.go +++ b/src/nvm/node/node.go @@ -25,17 +25,21 @@ func GetCurrentVersion() (string, string) { cmd := exec.Command("node","-p","console.log(process.execPath)") str, _ := cmd.Output() file := strings.Trim(regexp.MustCompile("undefined").ReplaceAllString(string(str),"")," \n\r") - bit := arch.Bit(file) - if (bit == "?"){ - cmd := exec.Command("node", "-e", "console.log(process.arch)" ) - str, err := cmd.Output() - if (string(str) == "x64") { - bit := "64" - } else { - bit := "32" - } - } - return v, bit + bit := arch.Bit(file) + if (bit == "?"){ + cmd := exec.Command("node", "-e", "console.log(process.arch)" ) + str, err := cmd.Output() + if (err == nil) { + if (string(str) == "x64") { + bit = "64" + } else { + bit = "32" + } + } else { + return v, "Unknown" + } + } + return v, bit } return "Unknown","" } diff --git a/src/nvm/web/web.go b/src/nvm/web/web.go index 10dd7794..f0d927d5 100644 --- a/src/nvm/web/web.go +++ b/src/nvm/web/web.go @@ -142,6 +142,23 @@ func GetRemoteTextFile(url string) string { return "" } +func IsNode64bitAvailable(v string) bool { + if v == "latest" { + return true + } + + // Anything below version 8 doesn't have a 64 bit version + vers := strings.Fields(strings.Replace(v,"."," ",-1)) + main, _ := strconv.ParseInt(vers[0],0,0) + minor, _ := strconv.ParseInt(vers[1],0,0) + if main == 0 && minor < 8 { + return false + } + + // TODO: fixme. Assume a 64 bit version exists + return true +} + func getNodeUrl (v string, vpre string) string { url := "http://nodejs.org/dist/v"+v+"/" + vpre + "/node.exe" // Check online to see if a 64 bit version exists