diff --git a/CHANGELOG.md b/CHANGELOG.md index b448e66..eb01f75 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -100,6 +100,7 @@ Other changes | Version | Date | Comment | | -------------- | -------------- | -------- | +| 3.42.1 | 2018-07-03 | `versions()` bugfix git version macOS | | 3.42.0 | 2018-06-01 | `processes()` added parent process PID | | 3.41.4 | 2018-05-28 | windows exec WMIC in try catch | | 3.41.3 | 2018-05-13 | improved SunOS support `getStaticData()`, `getDynamicData()` | diff --git a/README.md b/README.md index 46c66f6..dd63c56 100644 --- a/README.md +++ b/README.md @@ -54,13 +54,13 @@ async function cpu() { (last 7 major and minor version releases) +- Version 3.42.0: added parent process PID `processes()` - Version 3.41.0: first partial `SunOS` support - Version 3.40.0: extended `versions()` (php, redis, mongodb) - Version 3.39.0: added `versions().mysql` and `versions().nginx`, start implementing `SunOS` support - Version 3.38.0: added `battery.acconnected` - Version 3.37.0: extended FreeBSD support `networkStats()` - Version 3.36.0: extended FreeBSD support `networkConnections()` -- Version 3.35.0: extended FreeBSD support `processLoad()` - ... You can find all changes here: [detailed changelog][changelog-url] diff --git a/lib/osinfo.js b/lib/osinfo.js index 4e71b7a..b6072a4 100644 --- a/lib/osinfo.js +++ b/lib/osinfo.js @@ -15,6 +15,7 @@ const os = require('os'); const exec = require('child_process').exec; const util = require('./util'); +const fs = require('fs'); let _platform = process.platform; @@ -251,10 +252,10 @@ function osInfo(callback) { callback(result); } resolve(result); - }); + }); } catch (e) { if (callback) { callback(result); } - resolve(result); + resolve(result); } } }); @@ -286,7 +287,7 @@ function versions(callback) { }; let functionProcessed = (function () { - let totalFunctions = 12; + let totalFunctions = 13; return function () { if (--totalFunctions === 0) { if (callback) { @@ -337,6 +338,30 @@ function versions(callback) { } functionProcessed(); }); + if (_darwin) { + const filename = '/Library/Developer/CommandLineTools/'; + fs.access(filename, fs.constants.F_OK, (err) => { + if (!err) { + exec('git --version', function (error, stdout) { + if (!error) { + result.git = stdout.toString().split('\n')[0] || ''; + result.git = (result.git.toLowerCase().split('version')[1] || '').trim(); + result.git = (result.git.split(' ')[0] || '').trim(); + } + functionProcessed(); + }); + } + }); + } else { + exec('git --version', function (error, stdout) { + if (!error) { + result.git = stdout.toString().split('\n')[0] || ''; + result.git = (result.git.toLowerCase().split('version')[1] || '').trim(); + result.git = (result.git.split(' ')[0] || '').trim(); + } + functionProcessed(); + }); + } exec('git --version', function (error, stdout) { if (!error) { result.git = stdout.toString().split('\n')[0] || ''; @@ -386,10 +411,10 @@ function versions(callback) { result.mongodb = (result.mongodb.toLowerCase().split(',')[0] || '').replace(/[^0-9.]/g, ''); } functionProcessed(); - }); + }); } catch (e) { if (callback) { callback(result); } - resolve(result); + resolve(result); } }); });