Skip to content

Commit 6ca6f2c

Browse files
committed
resolve merge conflicts
2 parents 7de073e + 28c3aa8 commit 6ca6f2c

File tree

6 files changed

+136
-55
lines changed

6 files changed

+136
-55
lines changed

.github/ISSUE_TEMPLATE/bug_report.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ body:
3737
id: version
3838
attributes:
3939
label: Version
40-
description: What version are you running? Run `nvm --version` to find out. **Please don't assume. Check the version.**
40+
description: What version are you running? Run `nvm version` to find out. **Please don't assume. Check the version.**
4141
options:
4242
- 1.2.0 or newer (Default)
4343
- 1.1.12

README.md

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<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>
1+
<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>
22
<br/><br/>
33
<h1 align="center">NVM for Windows</h1>
44

@@ -20,8 +20,7 @@ _The original [nvm](https://github.com/nvm-sh/nvm) is a completely separate proj
2020
<table cellpadding="5" cellspacing="0" border="0" align="center">
2121
<tr>
2222
<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>
23-
<td><a href="https://linkedin.com/company/authorsoftware"><img src="https://avatars.githubusercontent.com/u/8259581?s=200&v=4" width="200px"/></a></td>
24-
<!-- <td><a href="https://metadoc.io"><img src="https://github.com/coreybutler/staticassets/raw/master/sponsors/metadoclogobig.png" width="200px"/></a></td>
23+
<!--<td><a href="https://metadoc.io"><img src="https://github.com/coreybutler/staticassets/raw/master/sponsors/metadoclogobig.png" width="200px"/></a></td>-->
2524
<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>
2625
<td><a href="https://butlerlogic.com"><img src="https://github.com/coreybutler/staticassets/raw/master/sponsors/butlerlogic_logo.png" width="200px"/></a></td> -->
2726
<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.
5958

6059
**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)!
6160

62-
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).
61+
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`.
6362

6463
![NVM for Windows](https://github.com/coreybutler/staticassets/raw/master/images/nvm-1.1.8-screenshot.jpg)
6564

@@ -121,7 +120,7 @@ npm install -g yarn
121120
NVM for Windows is a command line tool. Simply type `nvm` in the console for help. The basic commands are:
122121

123122
- **`nvm arch [32|64]`**: Show if node is running in 32 or 64 bit mode. Specify 32 or 64 to override the default architecture.
124-
- **`nvm check`**: Check the NVM4W process for known problems.
123+
- **`nvm debug`**: Check the NVM4W process for known problems.
125124
- **`nvm current`**: Display active version.
126125
- **`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.
127126
- **`nvm list [available]`**: List the node.js installations. Type `available` at the end to show a list of versions available for download.

nvm.iss

+19-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ Name: "english"; MessagesFile: "compiler:Default.isl"
5454
Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked; OnlyBelowVersion: 0,6.1
5555

5656
[Files]
57-
Source: "{#ProjectRoot}\bin\*"; DestDir: "{app}"; BeforeInstall: PreInstall; Flags: ignoreversion recursesubdirs createallsubdirs; Excludes: "{#ProjectRoot}\bin\install.cmd"
57+
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"
58+
Source: "{#ProjectRoot}\bins\nvm-arm64.exe"; DestDir: "{app}"; DestName: "nvm.exe"; Check: InstallARM64; Flags: solidbreak
59+
Source: "{#ProjectRoot}\bins\nvm-64.exe"; DestDir: "{app}"; DestName: "nvm.exe"; Check: InstallX64; Flags: solidbreak
60+
Source: "{#ProjectRoot}\bins\nvm.exe"; DestDir: "{app}"; DestName: "nvm.exe"; Check: InstallOtherArch;
5861

5962
[Icons]
6063
Name: "{group}\{#MyAppShortName}"; Filename: "{app}\{#MyAppExeName}"; IconFilename: "{#MyIcon}"
@@ -68,6 +71,21 @@ Root: HKCR; Subkey: "{#MyAppShortName}\DefaultIcon"; ValueType: string; ValueNam
6871
Root: HKCR; Subkey: "{#MyAppShortName}\shell\launch\command"; ValueType: string; ValueName: ""; ValueData: """{app}\{#MyAppExeName}"" ""%1"""; Flags: uninsdeletekey
6972

7073
[Code]
74+
function InstallX64: Boolean;
75+
begin
76+
Result := Is64BitInstallMode and (ProcessorArchitecture = paX64);
77+
end;
78+
79+
function InstallARM64: Boolean;
80+
begin
81+
Result := Is64BitInstallMode and (ProcessorArchitecture = paARM64);
82+
end;
83+
84+
function InstallOtherArch: Boolean;
85+
begin
86+
Result := not InstallX64 and not InstallARM64;
87+
end;
88+
7189
var
7290
SymlinkPage: TInputDirWizardPage;
7391
NotificationOptionPage: TInputOptionWizardPage;

src/arch/arch.go

+17-12
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package arch
22

33
import (
4-
//"regexp"
5-
"os"
6-
//"os/exec"
7-
"strings"
8-
//"fmt"
9-
"encoding/hex"
4+
//"regexp"
5+
"os"
6+
//"os/exec"
7+
"strings"
8+
//"fmt"
9+
"encoding/hex"
1010
)
1111

1212
func SearchBytesInFile( path string, match string, limit int) bool {
@@ -47,9 +47,12 @@ func SearchBytesInFile( path string, match string, limit int) bool {
4747
}
4848

4949
func Bit(path string) string {
50+
isarm64 := SearchBytesInFile(path, "5045000064AA", 400)
5051
is64 := SearchBytesInFile(path, "504500006486", 400);
5152
is32 := SearchBytesInFile(path, "504500004C", 400);
52-
if is64 {
53+
if isarm64 {
54+
return "arm64";
55+
} else if is64 {
5356
return "64";
5457
} else if is32 {
5558
return "32";
@@ -59,11 +62,13 @@ func Bit(path string) string {
5962

6063
func Validate(str string) (string){
6164
if str == "" {
62-
str = os.Getenv("PROCESSOR_ARCHITECTURE")
65+
str = strings.ToLower(os.Getenv("PROCESSOR_ARCHITECTURE"))
6366
}
64-
if strings.ContainsAny("64",str) {
65-
return "64"
66-
} else {
67-
return "32"
67+
if strings.Contains(str, "arm64") {
68+
return "arm64"
6869
}
70+
if strings.Contains(str, "64") {
71+
return "64"
72+
}
73+
return "32"
6974
}

src/nvm.go

+64-35
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,13 @@ type Environment struct {
5757

5858
var home = filepath.Clean(os.Getenv("NVM_HOME") + "\\settings.txt")
5959
var symlink = filepath.Clean(os.Getenv("NVM_SYMLINK"))
60+
var root = filepath.Clean(os.Getenv("NVM_HOME"))
6061

6162
var env = &Environment{
6263
settings: home,
63-
root: "",
64+
root: root,
6465
symlink: symlink,
65-
arch: os.Getenv("PROCESSOR_ARCHITECTURE"),
66+
arch: strings.ToLower(os.Getenv("PROCESSOR_ARCHITECTURE")),
6667
node_mirror: "",
6768
npm_mirror: "",
6869
proxy: "none",
@@ -184,7 +185,7 @@ func main() {
184185
detail = args[2]
185186
}
186187
if len(args) > 3 {
187-
if args[3] == "32" || args[3] == "64" {
188+
if args[3] == "32" || args[3] == "arm64" || args[3] == "64" {
188189
procarch = args[3]
189190
}
190191
}
@@ -242,8 +243,8 @@ func main() {
242243
case "arch":
243244
if strings.Trim(detail, " \r\n") != "" {
244245
detail = strings.Trim(detail, " \r\n")
245-
if detail != "32" && detail != "64" {
246-
fmt.Println("\"" + detail + "\" is an invalid architecture. Use 32 or 64.")
246+
if detail != "32" && detail != "64" && detail != "arm64" {
247+
fmt.Println("\"" + detail + "\" is an invalid architecture. Use 32 or 64 or arm64.")
247248
return
248249
}
249250
env.arch = detail
@@ -313,8 +314,8 @@ func getVersion(version string, cpuarch string, localInstallsOnly ...bool) (stri
313314
cpuarch = strings.ToLower(cpuarch)
314315

315316
if cpuarch != "" {
316-
if cpuarch != "32" && cpuarch != "64" && cpuarch != "all" {
317-
return version, cpuarch, errors.New("\"" + cpuarch + "\" is not a valid CPU architecture. Must be 32 or 64.")
317+
if cpuarch != "32" && cpuarch != "arm64" && cpuarch != "64" && cpuarch != "all" {
318+
return version, cpuarch, errors.New("\"" + cpuarch + "\" is not a valid CPU architecture. Must be 32 or 64 or arm64.")
318319
}
319320
} else {
320321
cpuarch = env.arch
@@ -347,7 +348,7 @@ func getVersion(version string, cpuarch string, localInstallsOnly ...bool) (stri
347348
version = installed[0]
348349
}
349350

350-
if version == "32" || version == "64" {
351+
if version == "32" || version == "arm64" || version == "64" {
351352
cpuarch = version
352353
v, _ := node.GetCurrentVersion()
353354
version = v
@@ -540,8 +541,17 @@ func install(version string, cpuarch string) {
540541
fmt.Println("Rollback complete.")
541542
}
542543

543-
return
544-
}
544+
if cpuarch == "arm64" && !web.IsNodeArm64bitAvailable(version) {
545+
fmt.Println("Node.js v" + version + " is only available in 64 and 32-bit.")
546+
return
547+
}
548+
549+
// Check to see if the version is already installed
550+
if !node.IsVersionInstalled(env.root, version, cpuarch) {
551+
if !node.IsVersionAvailable(version) {
552+
url := web.GetFullNodeUrl("index.json")
553+
fmt.Println("\nVersion " + version + " is not available.\n\nThe complete list of available versions can be found at " + url)
554+
return
545555
}
546556
}()
547557

@@ -600,24 +610,32 @@ func install(version string, cpuarch string) {
600610
}
601611
}
602612

603-
if err != nil {
604-
if strings.Contains(err.Error(), "No Major.Minor.Patch") {
605-
sv, sverr := semver.Make(version)
606-
if sverr == nil {
607-
sverr = sv.Validate()
608-
}
609-
if sverr != nil {
610-
version = findLatestSubVersion(version)
611-
if len(version) == 0 {
612-
sverr = errors.New("Unrecognized version: \"" + requestedVersion + "\"")
613-
}
613+
// Download node
614+
if (cpuarch == "arm64") && !node.IsVersionInstalled(env.root, version, "arm64") {
615+
success := web.GetNodeJS(env.root, version, "arm64", false)
616+
if !success {
617+
os.RemoveAll(filepath.Join(env.root, "v"+version, "node_modules"))
618+
fmt.Println("Could not download node.js v" + version + " arm64-bit executable.")
619+
return
620+
}
621+
} else {
622+
append32 := node.IsVersionInstalled(env.root, version, "64")
623+
append64 := node.IsVersionInstalled(env.root, version, "32")
624+
if (cpuarch == "32" || cpuarch == "all") && !node.IsVersionInstalled(env.root, version, "32") {
625+
success := web.GetNodeJS(env.root, version, "32", append32)
626+
if !success {
627+
os.RemoveAll(filepath.Join(env.root, "v"+version, "node_modules"))
628+
fmt.Println("Could not download node.js v" + version + " 32-bit executable.")
629+
return
614630
}
615-
err = sverr
616631
}
617-
618-
if err != nil {
619-
status <- Status{Err: err, Help: true}
620-
return
632+
if (cpuarch == "64" || cpuarch == "all") && !node.IsVersionInstalled(env.root, version, "64") {
633+
success := web.GetNodeJS(env.root, version, "64", append64)
634+
if !success {
635+
os.RemoveAll(filepath.Join(env.root, "v"+version, "node_modules"))
636+
fmt.Println("Could not download node.js v" + version + " 64-bit executable.")
637+
return
638+
}
621639
}
622640
}
623641

@@ -880,7 +898,7 @@ func uninstall(version string) {
880898
version = cleanVersion(version)
881899

882900
// Determine if the version exists and skip if it doesn't
883-
if node.IsVersionInstalled(env.root, version, "32") || node.IsVersionInstalled(env.root, version, "64") {
901+
if node.IsVersionInstalled(env.root, version, "32") || node.IsVersionInstalled(env.root, version, "64") || node.IsVersionInstalled(env.root, version, "arm64") {
884902
fmt.Printf("Uninstalling node v" + version + "...")
885903
v, _ := node.GetCurrentVersion()
886904
if v == version {
@@ -1035,10 +1053,19 @@ func use(version string, cpuarch string, reload ...bool) {
10351053
notifications = true
10361054
}
10371055

1038-
go func() {
1039-
defer func() {
1040-
if notifications {
1041-
time.Sleep(1 * time.Second)
1056+
// Check if a change is needed
1057+
curVersion, curCpuarch := node.GetCurrentVersion()
1058+
if version == curVersion && cpuarch == curCpuarch {
1059+
fmt.Println("node v" + version + " (" + cpuarch + "-bit) is already in use.")
1060+
return
1061+
}
1062+
1063+
// Make sure the version is installed. If not, warn.
1064+
if !node.IsVersionInstalled(env.root, version, cpuarch) {
1065+
fmt.Println("node v" + version + " (" + cpuarch + "-bit) is not installed.")
1066+
if cpuarch == "32" {
1067+
if node.IsVersionInstalled(env.root, version, "64") {
1068+
fmt.Println("\nDid you mean node v" + version + " (64-bit)?\nIf so, type \"nvm use " + version + " 64\" to use it.")
10421069
}
10431070
wg.Done()
10441071
}()
@@ -1224,7 +1251,11 @@ func useArchitecture(a string) {
12241251
fmt.Println("This computer only supports 32-bit processing.")
12251252
return
12261253
}
1227-
if a == "32" || a == "64" {
1254+
if strings.Contains("arm64",strings.ToLower(os.Getenv("PROCESSOR_ARCHITECTURE"))) {
1255+
fmt.Println("This computer only supports arm64-bit processing.")
1256+
return
1257+
}
1258+
if a == "32" || a == "64" || a == "arm64" {
12281259
env.arch = a
12291260
saveSettings()
12301261
fmt.Println("Set to " + a + "-bit mode")
@@ -1855,6 +1886,7 @@ func saveSettings() {
18551886
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")
18561887
content = content + "\r\nnode_mirror: " + strings.Trim(encode(env.node_mirror), " \n\r") + "\r\nnpm_mirror: " + strings.Trim(encode(env.npm_mirror), " \n\r")
18571888
ioutil.WriteFile(env.settings, []byte(content), 0644)
1889+
os.Setenv("NVM_HOME", strings.Trim(encode(env.root), " \n\r"))
18581890
}
18591891

18601892
func getProcessPermissions() (admin bool, elevated bool, err error) {
@@ -1913,9 +1945,6 @@ func setup() {
19131945
m[res[0]] = strings.TrimSpace(strings.Join(res[1:], ":"))
19141946
}
19151947

1916-
if val, ok := m["root"]; ok {
1917-
env.root = filepath.Clean(val)
1918-
}
19191948
if val, ok := m["originalpath"]; ok {
19201949
env.originalpath = filepath.Clean(val)
19211950
}

src/web/web.go

+31-1
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,12 @@ func GetNodeJS(root string, v string, a string, append bool) bool {
231231
} else {
232232
vpre = "x64/"
233233
}
234+
} else if a == "arm64" {
235+
if main > 0 {
236+
vpre = "win-arm64/"
237+
} else {
238+
vpre = "arm64/"
239+
}
234240
}
235241

236242
url := getNodeUrl(v, vpre, a, append)
@@ -354,14 +360,38 @@ func IsNode64bitAvailable(v string) bool {
354360
return true
355361
}
356362

363+
func IsNodeArm64bitAvailable(v string) bool {
364+
if v == "latest" {
365+
return true
366+
}
367+
368+
// Anything below version 19.9 doesn't have a arm64 bit version
369+
vers := strings.Fields(strings.Replace(v, ".", " ", -1))
370+
main, _ := strconv.ParseInt(vers[0], 0, 0)
371+
minor, _ := strconv.ParseInt(vers[1], 0, 0)
372+
fmt.Println("main "+ strconv.FormatInt(main,10) + " minor "+strconv.FormatInt(minor,10))
373+
if main < 19 {
374+
return false
375+
}
376+
if main == 19 && minor < 9{
377+
return false
378+
}
379+
380+
// TODO: fixme. Assume a 64 bit version exists
381+
return true
382+
}
383+
357384
func getNodeUrl(v string, vpre string, arch string, append bool) string {
358385
a := "x86"
386+
if arch == "arm64" {
387+
a = "arm64"
388+
}
359389
if arch == "64" {
360390
a = "x64"
361391
}
362392

363393
//url := "http://nodejs.org/dist/v"+v+"/" + vpre + "/node.exe"
364-
url := GetFullNodeUrl("v" + v + "/" + vpre + "/node.exe")
394+
url := GetFullNodeUrl("v" + v + "/" + vpre + "node.exe")
365395

366396
if !append {
367397
version, err := semver.Make(v)

0 commit comments

Comments
 (0)