mirror of
https://github.com/coreybutler/nvm-windows.git
synced 2026-01-14 07:03:17 +08:00
Updated URLs to support npm >= 6.2.0. Applied several PR's. Bumped to v1.1.7
This commit is contained in:
@@ -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
|
||||
|
||||
2
nvm.iss
2
nvm.iss
@@ -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"
|
||||
|
||||
36
src/nvm.go
36
src/nvm.go
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
@@ -19,7 +20,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
NvmVersion = "1.1.6"
|
||||
NvmVersion = "1.1.7"
|
||||
)
|
||||
|
||||
type Environment struct {
|
||||
@@ -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"))
|
||||
@@ -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 }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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.")
|
||||
|
||||
@@ -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" {
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user