From d9ed3392361bd0cdeca3f1f93dd7e0f75d9591f4 Mon Sep 17 00:00:00 2001 From: Albin Ekblom Date: Tue, 25 Dec 2018 15:17:18 +0200 Subject: [PATCH] Fix version parsing when having `iOSSupportVersion` in the plist (#7) --- index.js | 14 ++++++++++++-- test.js | 24 ++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 85d710b..ef1df95 100644 --- a/index.js +++ b/index.js @@ -7,6 +7,15 @@ let version; const clean = version => version.split('.').length === 2 ? `${version}.0` : version; +const parseVersion = plist => { + const matches = /ProductVersion<\/key>[\s]*([\d.]+)<\/string>/.exec(plist); + if (!matches) { + return; + } + + return matches[1]; +}; + const getVersion = () => { if (!isMacOS) { return; @@ -14,13 +23,13 @@ const getVersion = () => { if (!version) { const file = fs.readFileSync('/System/Library/CoreServices/SystemVersion.plist', 'utf8'); - const matches = /ProductVersion<\/key>[\s\S]*([\d.]+)<\/string>/.exec(file); + const matches = parseVersion(file); if (!matches) { return; } - version = matches[1]; + version = matches; } if (version) { @@ -32,6 +41,7 @@ module.exports = getVersion; const x = module.exports; +x.parseVersion = parseVersion; x.isMacOS = isMacOS; x.is = input => { diff --git a/test.js b/test.js index bb7d1ec..704b95f 100644 --- a/test.js +++ b/test.js @@ -8,6 +8,30 @@ test('main', t => { t.is(semver.valid(version), version); }); +test('main with ios support', t => { + const plist = ` + + + + ProductBuildVersion + 18C54 + ProductCopyright + 1983-2018 Apple Inc. + ProductName + Mac OS X + ProductUserVisibleVersion + 10.14.2 + ProductVersion + 10.14.2 + iOSSupportVersion + 12.0 + +`; + const version = m.parseVersion(plist); + t.is(semver.valid(version), version); + t.is(version, '10.14.2'); +}); + test('.is()', t => { t.true(m.is('>=10.10')); t.true(m.is('>=10.10.2'));