5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-07 13:32:18 +08:00
wails/v3/internal/doctor/doctor_common.go
Mike D Pilsbury 0833a6d6d3
[v3] Correct detection of npm with acceptable version (#3458)
* Correct detection of npm with acceptable version

* Update changelog
2024-05-06 08:29:28 +10:00

33 lines
796 B
Go

package doctor
import (
"bytes"
"os/exec"
"strconv"
"strings"
)
func checkCommonDependencies(result map[string]string, ok *bool) {
// Check for npm
npmVersion := []byte("Not Installed. Requires npm >= 7.0.0")
npmVersion, err := exec.Command("npm", "-v").Output()
if err != nil {
*ok = false
} else {
npmVersion = bytes.TrimSpace(npmVersion)
// Check that it's at least version 7 by converting first byte to int and checking if it's >= 7
// Parse the semver string
semver := strings.Split(string(npmVersion), ".")
if len(semver) > 0 {
major, _ := strconv.Atoi(semver[0])
if major < 7 {
*ok = false
npmVersion = append(npmVersion, []byte(". Installed, but requires npm >= 7.0.0")...)
} else {
*ok = true
}
}
}
result["npm"] = string(npmVersion)
}