Skip to content

Commit

Permalink
Merge branch 'master' of github.com:coreybutler/nvm-windows
Browse files Browse the repository at this point in the history
  • Loading branch information
coreybutler committed Nov 7, 2023
2 parents 3c736ab + 4b31ca3 commit 4854ee0
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 20 deletions.
45 changes: 44 additions & 1 deletion .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,51 @@ body:
- type: textarea
attributes:
label: Debug Output
description: If possible, please provide the output of `nvm debug`
description: |
If possible, please provide the output of `nvm debug`.
The output of `nvm debug` looks like this
```
<username> is not using admin or elevated rights.
PowerShell
Windows Developer Mode: UNKNOWN (user cannot read registry)
NVM4W Version: 1.1.11
NVM4W Path: C:\Users\username\AppData\Roaming\nvm\nvm.exe
NVM4W Settings: C:\Users\username\AppData\Roaming\nvm\settings.txt
NVM_HOME: C:\Users\uername\AppData\Roaming\nvm
NVM_SYMLINK: C:\Program Files\nodejs
Node Installations: C:\Users\username\AppData\Roaming\nvm
Active Node.js Version: v20.7.0
No problems detected.
Find help at https://github.com/coreybutler/nvm-windows/wiki/Common-Issues
```
If you only see the standard help menu (as shown below), then you are probably running v1.1.10 or below. Upgrade to NVM4W 1.1.11+.
```sh
Running version 1.1.11.
Usage:
nvm arch : Show if node is running in 32 or 64 bit mode.
nvm current : Display active version.
nvm debug : Check the NVM4W process for known problems (troubleshooter).
nvm install <version> [arch] : The version can be a specific version, "latest" for the latest current version, or "lts" for the
most recent LTS version. Optionally specify whether to install the 32 or 64 bit version (defaults
to system arch). Set [arch] to "all" to install 32 AND 64 bit versions.
Add --insecure to the end of this command to bypass SSL validation of the remote download server.
nvm list [available] : List the node.js installations. Type "available" at the end to see what can be installed. Aliased as ls.
nvm on : Enable node.js version management.
nvm off : Disable node.js version management.
```
render: Shell
validations:
required: true
- type: textarea
id: misc
attributes:
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/winget.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ on:

jobs:
publish:
# Action can only be run on windows
runs-on: windows-latest
runs-on: ubuntu-latest
steps:
- uses: vedantmgoyal2009/winget-releaser@v2
with:
Expand Down
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<div align="center"><h2>Notice: We have started full time work on <a href="https://github.com/coreybutler/nvm-windows/wiki/Runtime">Runtime</a>, the successor to NVM for Windows.</h2>Complete <a href="https://t.co/oGqQCM9FPx">this form</a> to provide your thoughts and sign up for progress updates</div>
<br/><br/>
<h1 align="center">NVM for Windows</h1>

<div align="center">
Expand Down Expand Up @@ -28,6 +30,12 @@ _The original [nvm](https://github.com/nvm-sh/nvm) is a completely separate proj
&nbsp;<a href="https://github.com/sponsors/coreybutler"><img src="https://img.shields.io/badge/-Become%20a%20Sponsor-yellow"/></a>
</td>
</tr>
<tr>
<td colspan="4" align="center">
<img src="https://github.blog/wp-content/uploads/2020/09/github-stars-logo_Color.png" width="50"/><br/>
<b>Can't sponsor?</b><br/>Consider <a href="https://stars.github.com/nominate/" target="_blank">nominating @coreybutler for a Github star</a>.
</td>
</tr>
</table>
</div>
<br/>
Expand Down Expand Up @@ -61,7 +69,18 @@ There are situations where the ability to switch between different versions of N

#### :star: :star: Uninstall any pre-existing Node installations!! :star: :star:

Uninstall any existing versions of Node.js before installing NVM for Windows (otherwise you'll have conflicting versions). Delete any existing Node.js installation directories (e.g., `%ProgramFiles%\nodejs`) that might remain. NVM's generated symlink will not overwrite an existing (even empty) installation directory.
The simplest (recommended) way to get NVM for Windows running properly is to uninstall any prior Node installation _before_ installing NVM for Windows. It avoids all of the pitfalls listed below. However; you may not wish to nuke your Node installation if you've highly customized it. NVM for Windows _can_ assume management of an existing installation, but there are nuances to this (dependent entirely on the permissions of the user running the installation). If you have an administrative account, it's relatively safe to install NVM for Windows before uninstalling the original Node version. If you are working in a closed environment, such as a corporate Active Directory environment where installations/uninstallations are controlled by group policy, you should really consider removing the original version of Node before installing NVM4W.

_Permission Problems_
For security reasons, Windows will not allow an application from one vendor to "uninstall" an application from a different vendor. The official NVM4W installer will attempt assume management of an existing installation of Node., but it cannot actually uninstall the original Node.js version. To work around this, NVM for Windows installer attempts to copy the original Node.js installation files to the NVM root. This includes global npm modules and configurations. Once this process is complete, the original Node.js installation can be uninstalled without losing data.

_PATH Installation Problems_
If you attempt to configure the `NVM_SYMLINK` to use an existing directory (like `C:\Program Files\nodejs`), it will fail because a symlink cannot overwrite a physical directory. This is not a problem if you choose a different symlink path (such as `C:\nvm\node`).

_PATH Conflicts_
If you do not uninstall the original version, running `nvm use` may appear to do nothing at all. Running `node -v` will always show the original installation version. This is due to a [`PATH` conflict](https://github.com/coreybutler/nvm-windows/wiki/Common-Issues#why-do-i-need-to-uninstall-nodejs-before-installing-nvm-for-windows) that presents when the same application is installed multiple times. In NVM4W 1.1.11+, run `nvm debug` to determine if you have a `PATH` conflict.

For simpliciy, we recommend uninstalling any existing versions of Node.js before using NVM for Windows. Delete any existing Node.js installation directories (e.g., `%ProgramFiles%\nodejs`) that might remain. NVM's generated symlink will not overwrite an existing (even empty) installation directory.

:eyes: **Backup any global `npmrc` config** :eyes:
(e.g. `%AppData%\npm\etc\npmrc`)
Expand Down
20 changes: 10 additions & 10 deletions build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ cd .\src
go build nvm.go

REM Group the file with the helper binaries
move nvm.exe %GOBIN%
move nvm.exe "%GOBIN%"
cd ..\

REM Codesign the executable
echo ----------------------------
echo Sign the nvm executable...
echo ----------------------------
buildtools\signtool.exe sign /debug /tr http://timestamp.sectigo.com /td sha256 /fd sha256 /a %GOBIN%\nvm.exe
buildtools\signtool.exe sign /debug /tr http://timestamp.sectigo.com /td sha256 /fd sha256 /a "%GOBIN%\nvm.exe"

for /f %%i in ('"%GOBIN%\nvm.exe" version') do set AppVersion=%%i
echo nvm.exe v%AppVersion% built.
Expand All @@ -35,7 +35,7 @@ REM Create the distribution folder
SET DIST=%CD%\dist\%AppVersion%

REM Remove old build files if they exist.
if exist %DIST% (
if exist "%DIST%" (
echo ----------------------------
echo Clearing old build in %DIST%
echo ----------------------------
Expand All @@ -54,7 +54,7 @@ echo Generating update utility...
echo ----------------------------
cd .\updater
go build nvm-update.go
move nvm-update.exe %DIST%
move nvm-update.exe "%DIST%"
cd ..\

REM Generate the installer (InnoSetup)
Expand All @@ -66,12 +66,12 @@ buildtools\iscc "%INNOSETUP%" "/o%DIST%"
echo ----------------------------
echo Sign the installer
echo ----------------------------
buildtools\signtool.exe sign /debug /tr http://timestamp.sectigo.com /td sha256 /fd sha256 /a %DIST%\nvm-setup.exe
buildtools\signtool.exe sign /debug /tr http://timestamp.sectigo.com /td sha256 /fd sha256 /a "%DIST%\nvm-setup.exe"

echo ----------------------------
echo Sign the updater...
echo ----------------------------
buildtools\signtool.exe sign /debug /tr http://timestamp.sectigo.com /td sha256 /fd sha256 /a %DIST%\nvm-update.exe
buildtools\signtool.exe sign /debug /tr http://timestamp.sectigo.com /td sha256 /fd sha256 /a "%DIST%\nvm-update.exe"

echo ----------------------------
echo Bundle the installer...
Expand All @@ -84,20 +84,20 @@ echo Bundle the updater...
echo ----------------------------
buildtools\zip -j -9 -r "%DIST%\nvm-update.zip" "%DIST%\nvm-update.exe"

del %DIST%\nvm-update.exe
del %DIST%\nvm-setup.exe
del "%DIST%\nvm-update.exe"
del "%DIST%\nvm-setup.exe"

REM Generate checksums
echo ----------------------------
echo Generating checksums...
echo ----------------------------
for %%f in (%DIST%\*.*) do (certutil -hashfile "%%f" MD5 | find /i /v "md5" | find /i /v "certutil" >> "%%f.checksum.txt")
for %%f in ("%DIST%"\*.*) do (certutil -hashfile "%%f" MD5 | find /i /v "md5" | find /i /v "certutil" >> "%%f.checksum.txt")
echo complete

echo ----------------------------
echo Cleaning up...
echo ----------------------------
del %GOBIN%\nvm.exe
del "%GOBIN%\nvm.exe"
echo complete
@REM del %GOBIN%\nvm-update.exe
@REM del %GOBIN%\nvm-setup.exe
Expand Down
3 changes: 2 additions & 1 deletion src/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os/exec"
"regexp"
"strings"
"os"

// "../semver"
"github.com/blang/semver"
Expand Down Expand Up @@ -95,7 +96,7 @@ func GetInstalled(root string) []string {
files, _ := ioutil.ReadDir(root)

for i := len(files) - 1; i >= 0; i-- {
if files[i].IsDir() {
if files[i].IsDir() || (files[i].Mode()&os.ModeSymlink == os.ModeSymlink) {
isnode, _ := regexp.MatchString("v", files[i].Name())

if isnode {
Expand Down
13 changes: 8 additions & 5 deletions src/nvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ func uninstall(version string) {
func versionNumberFrom(version string) string {
reg, _ := regexp.Compile("[^0-9]")

if reg.Match([]byte(version[:1])) {
if reg.MatchString(version[:1]) {
if version[0:1] != "v" {
url := web.GetFullNodeUrl("latest-" + version + "/SHASUMS256.txt")
content := strings.Split(web.GetRemoteTextFile(url), "\n")[0]
Expand All @@ -630,7 +630,7 @@ func versionNumberFrom(version string) string {
}
}

for reg.Match([]byte(version[:1])) {
for reg.MatchString(version[:1]) {
version = version[1:]
}

Expand Down Expand Up @@ -1339,16 +1339,19 @@ func updateRootDir(path string) {
}

func elevatedRun(name string, arg ...string) (bool, error) {
ok, err := run("cmd", append([]string{"/C", name}, arg...)...)
ok, err := run("cmd", nil, append([]string{"/C", name}, arg...)...)
if err != nil {
ok, err = run(filepath.Join(env.root, "elevate.cmd"), append([]string{"cmd", "/C", name}, arg...)...)
ok, err = run("elevate.cmd", &env.root, append([]string{"cmd", "/C", name}, arg...)...)
}

return ok, err
}

func run(name string, arg ...string) (bool, error) {
func run(name string, dir *string, arg ...string) (bool, error) {
c := exec.Command(name, arg...)
if dir != nil {
c.Dir = *dir
}
var stderr bytes.Buffer
c.Stderr = &stderr
err := c.Run()
Expand Down

0 comments on commit 4854ee0

Please sign in to comment.