Skip to content

Commit

Permalink
Updated URLs to support npm >= 6.2.0. Applied several PR's. Bumped to…
Browse files Browse the repository at this point in the history
… v1.1.7
  • Loading branch information
coreybutler committed Aug 2, 2018
1 parent 476e11d commit 256d694
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 14 deletions.
2 changes: 1 addition & 1 deletion build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ SET ORIG=%CD%
REM SET GOPATH=%CD%\src
SET GOBIN=%CD%\bin
SET GOARCH=386
SET version=1.1.6
SET version=1.1.7

REM Get the version number from the setup file
REM for /f "tokens=*" %%i in ('findstr /n . %INNOSETUP% ^| findstr ^4:#define') do set L=%%i
Expand Down
2 changes: 1 addition & 1 deletion nvm.iss
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#define MyAppName "NVM for Windows"
#define MyAppShortName "nvm"
#define MyAppLCShortName "nvm"
#define MyAppVersion "1.1.6"
#define MyAppVersion "1.1.7"
#define MyAppPublisher "Ecor Ventures LLC"
#define MyAppURL "http://github.com/coreybutler/nvm"
#define MyAppExeName "nvm.exe"
Expand Down
36 changes: 26 additions & 10 deletions src/nvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"log"
"os"
"os/exec"
"strings"
Expand All @@ -19,7 +20,7 @@ import (
)

const (
NvmVersion = "1.1.6"
NvmVersion = "1.1.7"
)

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

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

// Copy the npm and npm.cmd files to the installation directory
tempNpmBin := filepath.Join(tempDir, "nvm-npm", "npm-"+npmv, "bin")
tempNpmBin := filepath.Join(tempDir, "nvm-npm", "cli-"+npmv, "bin")

// Support npm < 6.2.0
if file.Exists(tempNpmBin) == false {
tempNpmBin = filepath.Join(tempDir, "nvm-npm", "npm-"+npmv, "bin")
}

if file.Exists(tempNpmBin) == false {
log.Fatal("Failed to extract npm. Could not find " + tempNpmBin)
}

// Standard npm support
os.Rename(filepath.Join(tempNpmBin, "npm"), filepath.Join(env.root, "v"+version, "npm"))
Expand All @@ -286,14 +296,20 @@ func install(version string, cpuarch string) {
os.Rename(filepath.Join(tempNpmBin, "npx"), filepath.Join(env.root, "v"+version, "npx"))
os.Rename(filepath.Join(tempNpmBin, "npx.cmd"), filepath.Join(env.root, "v"+version, "npx.cmd"))
}

err := os.Rename(filepath.Join(tempDir, "nvm-npm", "npm-"+npmv), filepath.Join(env.root, "v"+version, "node_modules", "npm"))
if err != nil {

npmSourcePath := filepath.Join(tempDir, "nvm-npm", "npm-"+npmv)

if file.Exists(npmSourcePath) == false {
npmSourcePath = filepath.Join(tempDir, "nvm-npm", "cli-"+npmv)
}

moveNpmErr := os.Rename(npmSourcePath, filepath.Join(env.root, "v"+version, "node_modules", "npm"))
if moveNpmErr != nil {
// 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
for _, i := range [5]int{1, 2, 4, 8, 16} {
time.Sleep(time.Duration(i)*time.Second)
err = os.Rename(filepath.Join(tempDir, "nvm-npm", "npm-"+npmv), filepath.Join(env.root, "v"+version, "node_modules", "npm"))
if err == nil { break }
moveNpmErr = os.Rename(filepath.Join(tempDir, "nvm-npm", "npm-"+npmv), filepath.Join(env.root, "v"+version, "node_modules", "npm"))
if moveNpmErr == nil { break }
}
}

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

Expand Down Expand Up @@ -604,7 +620,7 @@ func help() {
fmt.Println(" nvm proxy [url] : Set a proxy to use for downloads. Leave [url] blank to see the current proxy.")
fmt.Println(" Set [url] to \"none\" to remove the proxy.")
fmt.Println(" nvm node_mirror [url] : Set the node mirror. Defaults to https://nodejs.org/dist/. Leave [url] blank to use default url.")
fmt.Println(" nvm npm_mirror [url] : Set the npm mirror. Defaults to https://github.com/npm/npm/archive/. Leave [url] blank to default url.")
fmt.Println(" nvm npm_mirror [url] : Set the npm mirror. Defaults to https://github.com/npm/cli/archive/. Leave [url] blank to default url.")
fmt.Println(" nvm uninstall <version> : The version must be a specific version.")
// fmt.Println(" nvm update : Automatically update nvm to the latest version.")
fmt.Println(" nvm use [version] [arch] : Switch to use the specified version. Optionally specify 32/64bit architecture.")
Expand Down
4 changes: 2 additions & 2 deletions src/nvm/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import(

var client = &http.Client{}
var nodeBaseAddress = "https://nodejs.org/dist/"
var npmBaseAddress = "https://github.com/npm/npm/archive/"
var npmBaseAddress = "https://github.com/npm/cli/archive/"
// var oldNpmBaseAddress = "https://github.com/npm/npm/archive/"

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

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

0 comments on commit 256d694

Please sign in to comment.