resolve merge conflicts

This commit is contained in:
Corey Butler
2024-12-28 22:31:25 -06:00
6 changed files with 137 additions and 56 deletions

View File

@@ -37,7 +37,7 @@ body:
id: version
attributes:
label: Version
description: What version are you running? Run `nvm --version` to find out. **Please don't assume. Check the version.**
description: What version are you running? Run `nvm version` to find out. **Please don't assume. Check the version.**
options:
- 1.2.0 or newer (Default)
- 1.1.12

View File

@@ -1,4 +1,4 @@
<div align="center"><h2>Notice: We are working full time 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>
<div align="center"><h2>Notice: We are working 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.<br/><br/>Updates will also be posted on the <A href="https://linkedin.com/company/authorsoftware">Author Software LinkedIn Page</a>.</div>
<br/><br/>
<h1 align="center">NVM for Windows</h1>
@@ -20,8 +20,7 @@ _The original [nvm](https://github.com/nvm-sh/nvm) is a completely separate proj
<table cellpadding="5" cellspacing="0" border="0" align="center">
<tr>
<td><a href="https://linkedin.com/company/authorsoftware"><img src="https://github.com/coreybutler/staticassets/blob/master/sponsors/logo_author_software_flat.png" width="200px"/></a></td>
<td><a href="https://linkedin.com/company/authorsoftware"><img src="https://avatars.githubusercontent.com/u/8259581?s=200&v=4" width="200px"/></a></td>
<!-- <td><a href="https://metadoc.io"><img src="https://github.com/coreybutler/staticassets/raw/master/sponsors/metadoclogobig.png" width="200px"/></a></td>
<!--<td><a href="https://metadoc.io"><img src="https://github.com/coreybutler/staticassets/raw/master/sponsors/metadoclogobig.png" width="200px"/></a></td>-->
<td><a href="https://enabledb.com"><img src="https://github.com/coreybutler/staticassets/raw/master/images/logos/logo_enabledb_w_text.png" width="200px"/></a></td>
<td><a href="https://butlerlogic.com"><img src="https://github.com/coreybutler/staticassets/raw/master/sponsors/butlerlogic_logo.png" width="200px"/></a></td> -->
<td width="33%" align="center"><a href="https://github.com/microsoft"><img src="https://user-images.githubusercontent.com/770982/195955265-5c3dca78-7140-4ec6-b05a-f308518643ee.png" height="30px"/></a></td>
@@ -59,7 +58,7 @@ Manage multiple installations of node.js on a Windows computer.
**tl;dr** Similar (not identical) to [nvm](https://github.com/creationix/nvm), but for Windows. Has an installer. [Download Now](https://github.com/coreybutler/nvm-windows/releases)!
This has always been a node version manager, not an io.js manager, so there is no back-support for io.js. Node 4+ is supported. Remember when running `nvm install` or `nvm use`, Windows usually requires administrative rights (to create symlinks).
This has always been a node version manager, not an io.js manager, so there is no back-support for io.js. Node 4+ is supported. Remember when running `nvm install` or `nvm use`, Windows usually requires administrative rights (to create symlinks). To install the latest version of Node.js, run `nvm install latest`. To install the latest stable version, run `nvm install lts`.
![NVM for Windows](https://github.com/coreybutler/staticassets/raw/master/images/nvm-1.1.8-screenshot.jpg)
@@ -121,7 +120,7 @@ npm install -g yarn
NVM for Windows is a command line tool. Simply type `nvm` in the console for help. The basic commands are:
- **`nvm arch [32|64]`**: Show if node is running in 32 or 64 bit mode. Specify 32 or 64 to override the default architecture.
- **`nvm check`**: Check the NVM4W process for known problems.
- **`nvm debug`**: Check the NVM4W process for known problems.
- **`nvm current`**: Display active version.
- **`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 show a list of versions available for download.

20
nvm.iss
View File

@@ -54,7 +54,10 @@ Name: "english"; MessagesFile: "compiler:Default.isl"
Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked; OnlyBelowVersion: 0,6.1
[Files]
Source: "{#ProjectRoot}\bin\*"; DestDir: "{app}"; BeforeInstall: PreInstall; Flags: ignoreversion recursesubdirs createallsubdirs; Excludes: "{#ProjectRoot}\bin\install.cmd"
Source: "{#ProjectRoot}\bin\*"; DestDir: "{app}"; BeforeInstall: PreInstall; Flags: ignoreversion recursesubdirs createallsubdirs; Excludes: "{#ProjectRoot}\bin\install.cmd {#ProjectRoot}\bin\nvm-arm64.exe {#ProjectRoot}\bin\nvm-64.exe {#ProjectRoot}\bin\nvm.exe"
Source: "{#ProjectRoot}\bins\nvm-arm64.exe"; DestDir: "{app}"; DestName: "nvm.exe"; Check: InstallARM64; Flags: solidbreak
Source: "{#ProjectRoot}\bins\nvm-64.exe"; DestDir: "{app}"; DestName: "nvm.exe"; Check: InstallX64; Flags: solidbreak
Source: "{#ProjectRoot}\bins\nvm.exe"; DestDir: "{app}"; DestName: "nvm.exe"; Check: InstallOtherArch;
[Icons]
Name: "{group}\{#MyAppShortName}"; Filename: "{app}\{#MyAppExeName}"; IconFilename: "{#MyIcon}"
@@ -68,6 +71,21 @@ Root: HKCR; Subkey: "{#MyAppShortName}\DefaultIcon"; ValueType: string; ValueNam
Root: HKCR; Subkey: "{#MyAppShortName}\shell\launch\command"; ValueType: string; ValueName: ""; ValueData: """{app}\{#MyAppExeName}"" ""%1"""; Flags: uninsdeletekey
[Code]
function InstallX64: Boolean;
begin
Result := Is64BitInstallMode and (ProcessorArchitecture = paX64);
end;
function InstallARM64: Boolean;
begin
Result := Is64BitInstallMode and (ProcessorArchitecture = paARM64);
end;
function InstallOtherArch: Boolean;
begin
Result := not InstallX64 and not InstallARM64;
end;
var
SymlinkPage: TInputDirWizardPage;
NotificationOptionPage: TInputOptionWizardPage;

View File

@@ -1,12 +1,12 @@
package arch
import (
//"regexp"
"os"
//"os/exec"
"strings"
//"fmt"
"encoding/hex"
//"regexp"
"os"
//"os/exec"
"strings"
//"fmt"
"encoding/hex"
)
func SearchBytesInFile( path string, match string, limit int) bool {
@@ -47,9 +47,12 @@ func SearchBytesInFile( path string, match string, limit int) bool {
}
func Bit(path string) string {
isarm64 := SearchBytesInFile(path, "5045000064AA", 400)
is64 := SearchBytesInFile(path, "504500006486", 400);
is32 := SearchBytesInFile(path, "504500004C", 400);
if is64 {
if isarm64 {
return "arm64";
} else if is64 {
return "64";
} else if is32 {
return "32";
@@ -59,11 +62,13 @@ func Bit(path string) string {
func Validate(str string) (string){
if str == "" {
str = os.Getenv("PROCESSOR_ARCHITECTURE")
str = strings.ToLower(os.Getenv("PROCESSOR_ARCHITECTURE"))
}
if strings.ContainsAny("64",str) {
if strings.Contains(str, "arm64") {
return "arm64"
}
if strings.Contains(str, "64") {
return "64"
} else {
return "32"
}
}
return "32"
}

View File

@@ -57,12 +57,13 @@ type Environment struct {
var home = filepath.Clean(os.Getenv("NVM_HOME") + "\\settings.txt")
var symlink = filepath.Clean(os.Getenv("NVM_SYMLINK"))
var root = filepath.Clean(os.Getenv("NVM_HOME"))
var env = &Environment{
settings: home,
root: "",
root: root,
symlink: symlink,
arch: os.Getenv("PROCESSOR_ARCHITECTURE"),
arch: strings.ToLower(os.Getenv("PROCESSOR_ARCHITECTURE")),
node_mirror: "",
npm_mirror: "",
proxy: "none",
@@ -184,7 +185,7 @@ func main() {
detail = args[2]
}
if len(args) > 3 {
if args[3] == "32" || args[3] == "64" {
if args[3] == "32" || args[3] == "arm64" || args[3] == "64" {
procarch = args[3]
}
}
@@ -242,8 +243,8 @@ func main() {
case "arch":
if strings.Trim(detail, " \r\n") != "" {
detail = strings.Trim(detail, " \r\n")
if detail != "32" && detail != "64" {
fmt.Println("\"" + detail + "\" is an invalid architecture. Use 32 or 64.")
if detail != "32" && detail != "64" && detail != "arm64" {
fmt.Println("\"" + detail + "\" is an invalid architecture. Use 32 or 64 or arm64.")
return
}
env.arch = detail
@@ -313,8 +314,8 @@ func getVersion(version string, cpuarch string, localInstallsOnly ...bool) (stri
cpuarch = strings.ToLower(cpuarch)
if cpuarch != "" {
if cpuarch != "32" && cpuarch != "64" && cpuarch != "all" {
return version, cpuarch, errors.New("\"" + cpuarch + "\" is not a valid CPU architecture. Must be 32 or 64.")
if cpuarch != "32" && cpuarch != "arm64" && cpuarch != "64" && cpuarch != "all" {
return version, cpuarch, errors.New("\"" + cpuarch + "\" is not a valid CPU architecture. Must be 32 or 64 or arm64.")
}
} else {
cpuarch = env.arch
@@ -347,7 +348,7 @@ func getVersion(version string, cpuarch string, localInstallsOnly ...bool) (stri
version = installed[0]
}
if version == "32" || version == "64" {
if version == "32" || version == "arm64" || version == "64" {
cpuarch = version
v, _ := node.GetCurrentVersion()
version = v
@@ -540,8 +541,17 @@ func install(version string, cpuarch string) {
fmt.Println("Rollback complete.")
}
return
}
if cpuarch == "arm64" && !web.IsNodeArm64bitAvailable(version) {
fmt.Println("Node.js v" + version + " is only available in 64 and 32-bit.")
return
}
// Check to see if the version is already installed
if !node.IsVersionInstalled(env.root, version, cpuarch) {
if !node.IsVersionAvailable(version) {
url := web.GetFullNodeUrl("index.json")
fmt.Println("\nVersion " + version + " is not available.\n\nThe complete list of available versions can be found at " + url)
return
}
}()
@@ -600,25 +610,33 @@ func install(version string, cpuarch string) {
}
}
if err != nil {
if strings.Contains(err.Error(), "No Major.Minor.Patch") {
sv, sverr := semver.Make(version)
if sverr == nil {
sverr = sv.Validate()
}
if sverr != nil {
version = findLatestSubVersion(version)
if len(version) == 0 {
sverr = errors.New("Unrecognized version: \"" + requestedVersion + "\"")
}
}
err = sverr
}
if err != nil {
status <- Status{Err: err, Help: true}
// Download node
if (cpuarch == "arm64") && !node.IsVersionInstalled(env.root, version, "arm64") {
success := web.GetNodeJS(env.root, version, "arm64", false)
if !success {
os.RemoveAll(filepath.Join(env.root, "v"+version, "node_modules"))
fmt.Println("Could not download node.js v" + version + " arm64-bit executable.")
return
}
} else {
append32 := node.IsVersionInstalled(env.root, version, "64")
append64 := node.IsVersionInstalled(env.root, version, "32")
if (cpuarch == "32" || cpuarch == "all") && !node.IsVersionInstalled(env.root, version, "32") {
success := web.GetNodeJS(env.root, version, "32", append32)
if !success {
os.RemoveAll(filepath.Join(env.root, "v"+version, "node_modules"))
fmt.Println("Could not download node.js v" + version + " 32-bit executable.")
return
}
}
if (cpuarch == "64" || cpuarch == "all") && !node.IsVersionInstalled(env.root, version, "64") {
success := web.GetNodeJS(env.root, version, "64", append64)
if !success {
os.RemoveAll(filepath.Join(env.root, "v"+version, "node_modules"))
fmt.Println("Could not download node.js v" + version + " 64-bit executable.")
return
}
}
}
if err != nil {
@@ -880,7 +898,7 @@ func uninstall(version string) {
version = cleanVersion(version)
// Determine if the version exists and skip if it doesn't
if node.IsVersionInstalled(env.root, version, "32") || node.IsVersionInstalled(env.root, version, "64") {
if node.IsVersionInstalled(env.root, version, "32") || node.IsVersionInstalled(env.root, version, "64") || node.IsVersionInstalled(env.root, version, "arm64") {
fmt.Printf("Uninstalling node v" + version + "...")
v, _ := node.GetCurrentVersion()
if v == version {
@@ -1035,10 +1053,19 @@ func use(version string, cpuarch string, reload ...bool) {
notifications = true
}
go func() {
defer func() {
if notifications {
time.Sleep(1 * time.Second)
// Check if a change is needed
curVersion, curCpuarch := node.GetCurrentVersion()
if version == curVersion && cpuarch == curCpuarch {
fmt.Println("node v" + version + " (" + cpuarch + "-bit) is already in use.")
return
}
// Make sure the version is installed. If not, warn.
if !node.IsVersionInstalled(env.root, version, cpuarch) {
fmt.Println("node v" + version + " (" + cpuarch + "-bit) is not installed.")
if cpuarch == "32" {
if node.IsVersionInstalled(env.root, version, "64") {
fmt.Println("\nDid you mean node v" + version + " (64-bit)?\nIf so, type \"nvm use " + version + " 64\" to use it.")
}
wg.Done()
}()
@@ -1224,7 +1251,11 @@ func useArchitecture(a string) {
fmt.Println("This computer only supports 32-bit processing.")
return
}
if a == "32" || a == "64" {
if strings.Contains("arm64",strings.ToLower(os.Getenv("PROCESSOR_ARCHITECTURE"))) {
fmt.Println("This computer only supports arm64-bit processing.")
return
}
if a == "32" || a == "64" || a == "arm64" {
env.arch = a
saveSettings()
fmt.Println("Set to " + a + "-bit mode")
@@ -1855,6 +1886,7 @@ func saveSettings() {
content := "root: " + strings.Trim(encode(env.root), " \n\r") + "\r\narch: " + strings.Trim(encode(env.arch), " \n\r") + "\r\nproxy: " + strings.Trim(encode(env.proxy), " \n\r") + "\r\noriginalpath: " + strings.Trim(encode(env.originalpath), " \n\r") + "\r\noriginalversion: " + strings.Trim(encode(env.originalversion), " \n\r")
content = content + "\r\nnode_mirror: " + strings.Trim(encode(env.node_mirror), " \n\r") + "\r\nnpm_mirror: " + strings.Trim(encode(env.npm_mirror), " \n\r")
ioutil.WriteFile(env.settings, []byte(content), 0644)
os.Setenv("NVM_HOME", strings.Trim(encode(env.root), " \n\r"))
}
func getProcessPermissions() (admin bool, elevated bool, err error) {
@@ -1913,9 +1945,6 @@ func setup() {
m[res[0]] = strings.TrimSpace(strings.Join(res[1:], ":"))
}
if val, ok := m["root"]; ok {
env.root = filepath.Clean(val)
}
if val, ok := m["originalpath"]; ok {
env.originalpath = filepath.Clean(val)
}

View File

@@ -231,6 +231,12 @@ func GetNodeJS(root string, v string, a string, append bool) bool {
} else {
vpre = "x64/"
}
} else if a == "arm64" {
if main > 0 {
vpre = "win-arm64/"
} else {
vpre = "arm64/"
}
}
url := getNodeUrl(v, vpre, a, append)
@@ -354,14 +360,38 @@ func IsNode64bitAvailable(v string) bool {
return true
}
func IsNodeArm64bitAvailable(v string) bool {
if v == "latest" {
return true
}
// Anything below version 19.9 doesn't have a arm64 bit version
vers := strings.Fields(strings.Replace(v, ".", " ", -1))
main, _ := strconv.ParseInt(vers[0], 0, 0)
minor, _ := strconv.ParseInt(vers[1], 0, 0)
fmt.Println("main "+ strconv.FormatInt(main,10) + " minor "+strconv.FormatInt(minor,10))
if main < 19 {
return false
}
if main == 19 && minor < 9{
return false
}
// TODO: fixme. Assume a 64 bit version exists
return true
}
func getNodeUrl(v string, vpre string, arch string, append bool) string {
a := "x86"
if arch == "arm64" {
a = "arm64"
}
if arch == "64" {
a = "x64"
}
//url := "http://nodejs.org/dist/v"+v+"/" + vpre + "/node.exe"
url := GetFullNodeUrl("v" + v + "/" + vpre + "/node.exe")
url := GetFullNodeUrl("v" + v + "/" + vpre + "node.exe")
if !append {
version, err := semver.Make(v)