Skip to content

Commit 09da8d9

Browse files
committed
Merge pull request coreybutler#94 from sullivanpt/develop
Fixed for node v4
2 parents 32b8754 + 0bc5644 commit 09da8d9

File tree

4 files changed

+70
-40
lines changed

4 files changed

+70
-40
lines changed

nvm.iss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#define MyAppName "NVM for Windows"
22
#define MyAppShortName "nvm"
33
#define MyAppLCShortName "nvm"
4-
#define MyAppVersion "1.0.6"
4+
#define MyAppVersion "1.1.0"
55
#define MyAppPublisher "Ecor Ventures, LLC"
66
#define MyAppURL "http://github.com/coreybutler/nvm"
77
#define MyAppExeName "nvm.exe"

src/nvm.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
)
1919

2020
const (
21-
NvmVersion = "1.0.6"
21+
NvmVersion = "1.1.0"
2222
)
2323

2424
type Environment struct {
@@ -120,11 +120,11 @@ func update() {
120120
}
121121

122122
func CheckVersionExceedsLatest(version string) bool{
123-
content := web.GetRemoteTextFile("http://nodejs.org/dist/latest/SHASUMS.txt")
123+
content := web.GetRemoteTextFile("http://nodejs.org/dist/latest/SHASUMS256.txt")
124124
re := regexp.MustCompile("node-v(.+)+msi")
125125
reg := regexp.MustCompile("node-v|-x.+")
126126
latest := reg.ReplaceAllString(re.FindString(content),"")
127-
127+
128128
if version <= latest {
129129
return false
130130
} else {
@@ -155,6 +155,14 @@ func install(version string, cpuarch string) {
155155
cpuarch = arch.Validate(cpuarch)
156156
}
157157

158+
// If user specifies "latest" version, find out what version is
159+
if version == "latest" {
160+
content := web.GetRemoteTextFile("http://nodejs.org/dist/latest/SHASUMS256.txt")
161+
re := regexp.MustCompile("node-v(.+)+msi")
162+
reg := regexp.MustCompile("node-v|-x.+")
163+
version = reg.ReplaceAllString(re.FindString(content),"")
164+
}
165+
158166
if CheckVersionExceedsLatest(version) {
159167
fmt.Println("Node.js v"+version+" is not yet released or available.")
160168
return
@@ -165,14 +173,6 @@ func install(version string, cpuarch string) {
165173
return
166174
}
167175

168-
// If user specifies "latest" version, find out what version is
169-
if version == "latest" {
170-
content := web.GetRemoteTextFile("http://nodejs.org/dist/latest/SHASUMS.txt")
171-
re := regexp.MustCompile("node-v(.+)+msi")
172-
reg := regexp.MustCompile("node-v|-x.+")
173-
version = reg.ReplaceAllString(re.FindString(content),"")
174-
}
175-
176176
// Check to see if the version is already installed
177177
if !node.IsVersionInstalled(env.root,version,cpuarch) {
178178

src/nvm/node/node.go

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,21 @@ func GetCurrentVersion() (string, string) {
2525
cmd := exec.Command("node","-p","console.log(process.execPath)")
2626
str, _ := cmd.Output()
2727
file := strings.Trim(regexp.MustCompile("undefined").ReplaceAllString(string(str),"")," \n\r")
28-
bit := arch.Bit(file)
29-
if (bit == "?"){
30-
cmd := exec.Command("node", "-e", "console.log(process.arch)" )
31-
str, err := cmd.Output()
32-
if (string(str) == "x64") {
33-
bit := "64"
34-
} else {
35-
bit := "32"
36-
}
37-
}
38-
return v, bit
28+
bit := arch.Bit(file)
29+
if (bit == "?"){
30+
cmd := exec.Command("node", "-e", "console.log(process.arch)" )
31+
str, err := cmd.Output()
32+
if (err == nil) {
33+
if (string(str) == "x64") {
34+
bit = "64"
35+
} else {
36+
bit = "32"
37+
}
38+
} else {
39+
return v, "Unknown"
40+
}
41+
}
42+
return v, bit
3943
}
4044
return "Unknown",""
4145
}

src/nvm/web/web.go

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,26 +59,42 @@ func GetNodeJS(root string, v string, a string) bool {
5959

6060
a = arch.Validate(a)
6161

62-
url := ""
62+
vpre := ""
63+
vers := strings.Fields(strings.Replace(v,"."," ",-1))
64+
main, _ := strconv.ParseInt(vers[0],0,0)
65+
6366
if a == "32" {
64-
url = "http://nodejs.org/dist/v"+v+"/node.exe"
65-
} else {
66-
if !IsNode64bitAvailable(v) {
67-
fmt.Println("Node.js v"+v+" is only available in 32-bit.")
68-
return false
67+
if main > 0 {
68+
vpre = "win-x86/"
69+
} else {
70+
vpre = ""
71+
}
72+
} else if a == "64" {
73+
if main > 0 {
74+
vpre = "win-x64/"
75+
} else {
76+
vpre = "x64/"
6977
}
70-
url = "http://nodejs.org/dist/v"+v+"/x64/node.exe"
7178
}
72-
fileName := root+"\\v"+v+"\\node"+a+".exe"
79+
80+
url := getNodeUrl ( v, vpre );
7381

74-
fmt.Printf("Downloading node.js version "+v+" ("+a+"-bit)... ")
75-
76-
if Download(url,fileName) {
77-
fmt.Printf("Complete\n")
78-
return true
82+
if url == "" {
83+
//No url should mean this version/arch isn't available
84+
fmt.Println("Node.js v"+v+" " + a + "bit isn't available right now.")
7985
} else {
80-
return false
86+
fileName := root+"\\v"+v+"\\node"+a+".exe"
87+
88+
fmt.Printf("Downloading node.js version "+v+" ("+a+"-bit)... ")
89+
90+
if Download(url,fileName) {
91+
fmt.Printf("Complete\n")
92+
return true
93+
} else {
94+
return false
95+
}
8196
}
97+
return false
8298

8399
}
84100

@@ -139,10 +155,20 @@ func IsNode64bitAvailable(v string) bool {
139155
return false
140156
}
141157

158+
// TODO: fixme. Assume a 64 bit version exists
159+
return true
160+
}
161+
162+
func getNodeUrl (v string, vpre string) string {
163+
url := "http://nodejs.org/dist/v"+v+"/" + vpre + "/node.exe"
142164
// Check online to see if a 64 bit version exists
143-
res, err := client.Head("http://nodejs.org/dist/v"+v+"/x64/node.exe")
165+
res, err := client.Head( url )
144166
if err != nil {
145-
return false
167+
return ""
168+
}
169+
if res.StatusCode == 200 {
170+
return url
171+
} else {
172+
return ""
146173
}
147-
return res.StatusCode == 200
148174
}

0 commit comments

Comments
 (0)