mirror of
https://github.com/coreybutler/nvm-windows.git
synced 2025-09-02 02:44:36 +00:00
Merge branch 'master' of https://github.com/wsobolewski/nvm-windows
This commit is contained in:
@@ -4,7 +4,7 @@ SET ORIG=%CD%
|
||||
REM SET GOPATH=%CD%\src
|
||||
SET GOBIN=%CD%\bin
|
||||
REM Support for older architectures
|
||||
SET GOARCH=386
|
||||
SET GOARCH=amd64
|
||||
|
||||
REM Cleanup existing build if it exists
|
||||
if exist src\nvm.exe (
|
||||
|
17
nvm.iss
17
nvm.iss
@@ -37,7 +37,7 @@ Compression=lzma
|
||||
SolidCompression=yes
|
||||
ChangesEnvironment=yes
|
||||
DisableProgramGroupPage=yes
|
||||
ArchitecturesInstallIn64BitMode=x64 ia64
|
||||
ArchitecturesInstallIn64BitMode=x64 ia64 arm64
|
||||
UninstallDisplayIcon={app}\{#MyIcon}
|
||||
VersionInfoVersion={#MyAppVersion}
|
||||
VersionInfoCopyright=Copyright (C) 2018-2022 Ecor Ventures LLC, Corey Butler, and contributors.
|
||||
@@ -60,6 +60,21 @@ Name: "{group}\{#MyAppShortName}"; Filename: "{app}\{#MyAppExeName}"; IconFilena
|
||||
Name: "{group}\Uninstall {#MyAppShortName}"; Filename: "{uninstallexe}"
|
||||
|
||||
[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;
|
||||
|
||||
|
@@ -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";
|
||||
@@ -61,7 +64,10 @@ func Validate(str string) (string){
|
||||
if str == "" {
|
||||
str = os.Getenv("PROCESSOR_ARCHITECTURE")
|
||||
}
|
||||
if strings.ContainsAny("64",str) {
|
||||
if strings.Contains(str, "arm64") {
|
||||
return "arm64"
|
||||
}
|
||||
if strings.ContainsAny(str, "64") {
|
||||
return "64"
|
||||
} else {
|
||||
return "32"
|
||||
|
@@ -6,10 +6,10 @@ import (
|
||||
"nvm/arch"
|
||||
"nvm/file"
|
||||
"nvm/web"
|
||||
"os"
|
||||
"os/exec"
|
||||
"regexp"
|
||||
"strings"
|
||||
"os"
|
||||
|
||||
// "../semver"
|
||||
"github.com/blang/semver"
|
||||
@@ -33,6 +33,8 @@ func GetCurrentVersion() (string, string) {
|
||||
if err == nil {
|
||||
if string(str) == "x64" {
|
||||
bit = "64"
|
||||
} else if string(str) == "arm64" {
|
||||
bit = "arm64"
|
||||
} else {
|
||||
bit = "32"
|
||||
}
|
||||
|
60
src/nvm.go
60
src/nvm.go
@@ -56,7 +56,7 @@ var env = &Environment{
|
||||
settings: home,
|
||||
root: "",
|
||||
symlink: symlink,
|
||||
arch: os.Getenv("PROCESSOR_ARCHITECTURE"),
|
||||
arch: strings.ToLower(os.Getenv("PROCESSOR_ARCHITECTURE")),
|
||||
node_mirror: "",
|
||||
npm_mirror: "",
|
||||
proxy: "none",
|
||||
@@ -80,7 +80,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]
|
||||
}
|
||||
}
|
||||
@@ -128,8 +128,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
|
||||
@@ -301,8 +301,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
|
||||
@@ -335,7 +335,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
|
||||
@@ -433,6 +433,11 @@ func install(version string, cpuarch string) {
|
||||
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) {
|
||||
@@ -451,22 +456,31 @@ func install(version string, cpuarch string) {
|
||||
}
|
||||
|
||||
// Download node
|
||||
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 (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 + " 32-bit executable.")
|
||||
fmt.Println("Could not download node.js v" + version + " arm64-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
|
||||
} 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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -585,7 +599,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 {
|
||||
@@ -831,7 +845,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")
|
||||
|
@@ -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)
|
||||
@@ -349,8 +355,32 @@ func IsNode64bitAvailable(v string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func IsNodeArm64bitAvailable(v string) bool {
|
||||
if v == "latest" {
|
||||
return true
|
||||
}
|
||||
|
||||
// Anything below version 8 doesn't have a 64 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 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"
|
||||
}
|
||||
|
Reference in New Issue
Block a user