Skip to content

Commit

Permalink
Added npx support. Closes coreybutler#288
Browse files Browse the repository at this point in the history
  • Loading branch information
coreybutler committed Jul 21, 2017
1 parent c6c5d2a commit ce75602
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/nvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,19 @@ func install(version string, cpuarch string) {
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
os.Rename(filepath.Join(tempDir, "nvm-npm", "npm-"+npmv, "bin", "npm"),filepath.Join(env.root, "v"+version, "npm"))
os.Rename(filepath.Join(tempDir, "nvm-npm", "npm-"+npmv, "bin", "npm.cmd"),filepath.Join(env.root, "v"+version, "npm.cmd"))
os.Rename(filepath.Join(tempDir, "nvm-npm", "npm-"+npmv),filepath.Join(env.root, "v"+version, "node_modules", "npm"))
tempNpmBin := filepath.Join(tempDir, "nvm-npm", "npm-"+npmv, "bin")

// Standard npm support
os.Rename(filepath.Join(tempNpmBin, "npm"), filepath.Join(env.root, "v"+version, "npm"))
os.Rename(filepath.Join(tempNpmBin, "npm.cmd"),filepath.Join(env.root, "v"+version, "npm.cmd"))

// npx support
if _, err := os.Stat(filepath.Join(tempNpmBin, "npx")); err == nil {
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"))
}

os.Rename(filepath.Join(tempDir, "nvm-npm", "npm-"+npmv), filepath.Join(env.root, "v"+version, "node_modules", "npm"))

// Remove the temp directory
// may consider keep the temp files here
Expand Down

0 comments on commit ce75602

Please sign in to comment.