mirror of
https://github.com/coreybutler/nvm-windows.git
synced 2026-01-14 07:03:17 +08:00
use new temp directory for npm
download and unzip npm in a temp directory under the nvm root. fix issue #46
This commit is contained in:
18
src/nvm.go
18
src/nvm.go
@@ -211,20 +211,24 @@ func install(version string, cpuarch string) {
|
||||
|
||||
// If successful, add npm
|
||||
npmv := getNpmVersion(version)
|
||||
success := web.GetNpm(getNpmVersion(version))
|
||||
success := web.GetNpm(env.root, getNpmVersion(version))
|
||||
if success {
|
||||
fmt.Printf("Installing npm v"+npmv+"...")
|
||||
|
||||
// new temp directory under the nvm root
|
||||
tempDir := env.root + "\\temp"
|
||||
|
||||
// Extract npm to the temp directory
|
||||
file.Unzip(os.TempDir()+"\\npm-v"+npmv+".zip",os.TempDir()+"\\nvm-npm")
|
||||
file.Unzip(tempDir+"\\npm-v"+npmv+".zip",tempDir+"\\nvm-npm")
|
||||
|
||||
// Copy the npm and npm.cmd files to the installation directory
|
||||
os.Rename(os.TempDir()+"\\nvm-npm\\npm-"+npmv+"\\bin\\npm",env.root+"\\v"+version+"\\npm")
|
||||
os.Rename(os.TempDir()+"\\nvm-npm\\npm-"+npmv+"\\bin\\npm.cmd",env.root+"\\v"+version+"\\npm.cmd")
|
||||
os.Rename(os.TempDir()+"\\nvm-npm\\npm-"+npmv,env.root+"\\v"+version+"\\node_modules\\npm")
|
||||
os.Rename(tempDir+"\\nvm-npm\\npm-"+npmv+"\\bin\\npm",env.root+"\\v"+version+"\\npm")
|
||||
os.Rename(tempDir+"\\nvm-npm\\npm-"+npmv+"\\bin\\npm.cmd",env.root+"\\v"+version+"\\npm.cmd")
|
||||
os.Rename(tempDir+"\\nvm-npm\\npm-"+npmv,env.root+"\\v"+version+"\\node_modules\\npm")
|
||||
|
||||
// Remove the source file
|
||||
os.RemoveAll(os.TempDir()+"\\nvm-npm")
|
||||
// Remove the temp directory
|
||||
// may consider keep the temp files here
|
||||
os.RemoveAll(tempDir)
|
||||
|
||||
fmt.Println("\n\nInstallation complete. If you want to use this version, type\n\nnvm use "+version)
|
||||
} else {
|
||||
|
||||
@@ -10,6 +10,7 @@ import(
|
||||
"strings"
|
||||
"strconv"
|
||||
"../arch"
|
||||
"../file"
|
||||
)
|
||||
|
||||
var client = &http.Client{}
|
||||
@@ -81,9 +82,21 @@ func GetNodeJS(root string, v string, a string) bool {
|
||||
|
||||
}
|
||||
|
||||
func GetNpm(v string) bool {
|
||||
func GetNpm(root string, v string) bool {
|
||||
url := "https://github.com/npm/npm/archive/v"+v+".zip"
|
||||
fileName := os.TempDir()+"\\"+"npm-v"+v+".zip"
|
||||
// temp directory to download the .zip file
|
||||
tempDir := root+"\\temp"
|
||||
|
||||
// if the temp directory doesn't exist, create it
|
||||
if (!file.Exists(tempDir)) {
|
||||
fmt.Println("Creating "+tempDir+"\n")
|
||||
err := os.Mkdir(tempDir, os.ModePerm)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
fileName := tempDir+"\\"+"npm-v"+v+".zip"
|
||||
|
||||
fmt.Printf("Downloading npm version "+v+"... ")
|
||||
if Download(url,fileName) {
|
||||
|
||||
Reference in New Issue
Block a user