fix(internal): improve macOS version detection

Turns out that `sw_vers -productVersion` doesn't always return a version
string with a `MAJOR.MINOR.PATCH` format, but can also just return two
digits, like `11.0` on the current beta of macOS Big Sur.

Fixes: #13
This commit is contained in:
2020-09-10 20:33:18 +01:00
parent f28ed683e2
commit c89d0a0b73

View File

@@ -45,7 +45,7 @@ end
class OSVersion
def initialize
@version = `sw_vers -productVersion`.match(
/(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)/
/(?<major>\d+)(?:\.(?<minor>\d+)(:?\.(?<patch>\d+))?)?/
)
end
@@ -54,15 +54,15 @@ class OSVersion
end
def major
@major ||= @version[:major].to_i
@major ||= @version[:major]&.to_i
end
def minor
@minor ||= @version[:minor].to_i
@minor ||= @version[:minor]&.to_i
end
def patch
@patch ||= @version[:patch].to_i
@patch ||= @version[:patch]&.to_i
end
end