Skip to content

Commit 256d694

Browse files
committed
Updated URLs to support npm >= 6.2.0. Applied several PR's. Bumped to v1.1.7
1 parent 476e11d commit 256d694

File tree

4 files changed

+30
-14
lines changed

4 files changed

+30
-14
lines changed

build.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ SET ORIG=%CD%
44
REM SET GOPATH=%CD%\src
55
SET GOBIN=%CD%\bin
66
SET GOARCH=386
7-
SET version=1.1.6
7+
SET version=1.1.7
88

99
REM Get the version number from the setup file
1010
REM for /f "tokens=*" %%i in ('findstr /n . %INNOSETUP% ^| findstr ^4:#define') do set L=%%i

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.1.6"
4+
#define MyAppVersion "1.1.7"
55
#define MyAppPublisher "Ecor Ventures LLC"
66
#define MyAppURL "http://github.com/coreybutler/nvm"
77
#define MyAppExeName "nvm.exe"

src/nvm.go

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"fmt"
5+
"log"
56
"os"
67
"os/exec"
78
"strings"
@@ -19,7 +20,7 @@ import (
1920
)
2021

2122
const (
22-
NvmVersion = "1.1.6"
23+
NvmVersion = "1.1.7"
2324
)
2425

2526
type Environment struct {
@@ -272,10 +273,19 @@ func install(version string, cpuarch string) {
272273
tempDir := filepath.Join(env.root, "temp")
273274

274275
// Extract npm to the temp directory
275-
file.Unzip(filepath.Join(tempDir, "npm-v"+npmv+".zip"), filepath.Join(tempDir, "nvm-npm"))
276+
err := file.Unzip(filepath.Join(tempDir, "npm-v"+npmv+".zip"), filepath.Join(tempDir, "nvm-npm"))
276277

277278
// Copy the npm and npm.cmd files to the installation directory
278-
tempNpmBin := filepath.Join(tempDir, "nvm-npm", "npm-"+npmv, "bin")
279+
tempNpmBin := filepath.Join(tempDir, "nvm-npm", "cli-"+npmv, "bin")
280+
281+
// Support npm < 6.2.0
282+
if file.Exists(tempNpmBin) == false {
283+
tempNpmBin = filepath.Join(tempDir, "nvm-npm", "npm-"+npmv, "bin")
284+
}
285+
286+
if file.Exists(tempNpmBin) == false {
287+
log.Fatal("Failed to extract npm. Could not find " + tempNpmBin)
288+
}
279289

280290
// Standard npm support
281291
os.Rename(filepath.Join(tempNpmBin, "npm"), filepath.Join(env.root, "v"+version, "npm"))
@@ -286,14 +296,20 @@ func install(version string, cpuarch string) {
286296
os.Rename(filepath.Join(tempNpmBin, "npx"), filepath.Join(env.root, "v"+version, "npx"))
287297
os.Rename(filepath.Join(tempNpmBin, "npx.cmd"), filepath.Join(env.root, "v"+version, "npx.cmd"))
288298
}
289-
290-
err := os.Rename(filepath.Join(tempDir, "nvm-npm", "npm-"+npmv), filepath.Join(env.root, "v"+version, "node_modules", "npm"))
291-
if err != nil {
299+
300+
npmSourcePath := filepath.Join(tempDir, "nvm-npm", "npm-"+npmv)
301+
302+
if file.Exists(npmSourcePath) == false {
303+
npmSourcePath = filepath.Join(tempDir, "nvm-npm", "cli-"+npmv)
304+
}
305+
306+
moveNpmErr := os.Rename(npmSourcePath, filepath.Join(env.root, "v"+version, "node_modules", "npm"))
307+
if moveNpmErr != nil {
292308
// sometimes Windows can take some time to enable access to large amounts of files after unzip, use exponential backoff to wait until it is ready
293309
for _, i := range [5]int{1, 2, 4, 8, 16} {
294310
time.Sleep(time.Duration(i)*time.Second)
295-
err = os.Rename(filepath.Join(tempDir, "nvm-npm", "npm-"+npmv), filepath.Join(env.root, "v"+version, "node_modules", "npm"))
296-
if err == nil { break }
311+
moveNpmErr = os.Rename(filepath.Join(tempDir, "nvm-npm", "npm-"+npmv), filepath.Join(env.root, "v"+version, "node_modules", "npm"))
312+
if moveNpmErr == nil { break }
297313
}
298314
}
299315

@@ -308,7 +324,7 @@ func install(version string, cpuarch string) {
308324
}
309325
} else {
310326
fmt.Println("Could not download npm for node v"+version+".")
311-
fmt.Println("Please visit https://github.com/npm/npm/releases/tag/v"+npmv+" to download npm.")
327+
fmt.Println("Please visit https://github.com/npm/cli/releases/tag/v"+npmv+" to download npm.")
312328
fmt.Println("It should be extracted to "+env.root+"\\v"+version)
313329
}
314330

@@ -604,7 +620,7 @@ func help() {
604620
fmt.Println(" nvm proxy [url] : Set a proxy to use for downloads. Leave [url] blank to see the current proxy.")
605621
fmt.Println(" Set [url] to \"none\" to remove the proxy.")
606622
fmt.Println(" nvm node_mirror [url] : Set the node mirror. Defaults to https://nodejs.org/dist/. Leave [url] blank to use default url.")
607-
fmt.Println(" nvm npm_mirror [url] : Set the npm mirror. Defaults to https://github.com/npm/npm/archive/. Leave [url] blank to default url.")
623+
fmt.Println(" nvm npm_mirror [url] : Set the npm mirror. Defaults to https://github.com/npm/cli/archive/. Leave [url] blank to default url.")
608624
fmt.Println(" nvm uninstall <version> : The version must be a specific version.")
609625
// fmt.Println(" nvm update : Automatically update nvm to the latest version.")
610626
fmt.Println(" nvm use [version] [arch] : Switch to use the specified version. Optionally specify 32/64bit architecture.")

src/nvm/web/web.go

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

1919
var client = &http.Client{}
2020
var nodeBaseAddress = "https://nodejs.org/dist/"
21-
var npmBaseAddress = "https://github.com/npm/npm/archive/"
21+
var npmBaseAddress = "https://github.com/npm/cli/archive/"
22+
// var oldNpmBaseAddress = "https://github.com/npm/npm/archive/"
2223

2324
func SetProxy(p string, verifyssl bool){
2425
if p != "" && p != "none" {
@@ -143,7 +144,6 @@ func GetNodeJS(root string, v string, a string) bool {
143144
}
144145

145146
func GetNpm(root string, v string) bool {
146-
//url := "https://github.com/npm/npm/archive/v"+v+".zip"
147147
url := GetFullNpmUrl("v"+v+".zip")
148148
// temp directory to download the .zip file
149149
tempDir := root+"\\temp"

0 commit comments

Comments
 (0)