Comparing version 1.0.3 to 2.0.0
74
index.js
'use strict'; | ||
var envPath = require('./PATH'); | ||
var isWindows = require('is-windows'); | ||
var path = require('path'); | ||
var fs = require('fs'); | ||
var bashPath; | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
let bashPath; | ||
function getPath() { | ||
return firstPath(envPath() || 'bash'); | ||
} | ||
/** | ||
* Default paths to search | ||
*/ | ||
function firstPath(arr) { | ||
for (var i = 0; i < arr.length; i++) { | ||
var filepath = path.resolve(arr[i], 'bash'); | ||
const DEFAULT_PATHS = [ | ||
'/bin/bash', | ||
'/sbin/bash', | ||
'/usr/bin/bash', | ||
'/usr/local/bin/bash', | ||
'/usr/local/sbin/bash', | ||
'/usr/sbin/bash', | ||
'/usr/X11/bin/bash', | ||
'/opt/local/bin', | ||
'/opt/local/sbin', | ||
'bash' | ||
]; | ||
module.exports = paths => { | ||
if (bashPath !== void 0) return bashPath; | ||
const pathList = getPaths(paths || DEFAULT_PATHS); | ||
for (let i = 0; i < pathList.length; i++) { | ||
let filepath = path.resolve(pathList[i], 'bash'); | ||
if (fs.existsSync(filepath)) { | ||
return filepath; | ||
bashPath = filepath; | ||
break; | ||
} | ||
if (isWindows()) { | ||
if (process.platform === 'win32') { | ||
if (fs.existsSync(filepath + '.cmd')) { | ||
return filepath + '.cmd'; | ||
bashPath = filepath + '.cmd'; | ||
break; | ||
} | ||
if (fs.existsSync(filepath + '.exe')) { | ||
return filepath + '.exe'; | ||
bashPath = filepath + '.exe'; | ||
break; | ||
} | ||
if (fs.existsSync(filepath + '.bat')) { | ||
return filepath + '.bat'; | ||
bashPath = filepath + '.bat'; | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
Object.defineProperty(module, 'exports', { | ||
get: function() { | ||
return bashPath || (bashPath = getPath()); | ||
// Set to null to avoid checking again later if path was not found | ||
if (!bashPath) { | ||
bashPath = null; | ||
} | ||
}); | ||
return bashPath; | ||
}; | ||
function getPaths(paths) { | ||
const compare = val => /\/use?r\//i.test(val) ? -1 : 1; | ||
const list = paths.concat(process.env.PATH.split(path.delimiter)); | ||
const unique = [...new Set(list)]; | ||
unique.sort(compare); | ||
return unique; | ||
} |
{ | ||
"name": "bash-path", | ||
"description": "Get the path to the bash binary on your OS.", | ||
"version": "1.0.3", | ||
"version": "2.0.0", | ||
"homepage": "https://github.com/micromatch/bash-path", | ||
@@ -13,3 +13,2 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)", | ||
"files": [ | ||
"PATH.js", | ||
"index.js" | ||
@@ -24,9 +23,5 @@ ], | ||
}, | ||
"dependencies": { | ||
"arr-union": "^3.1.0", | ||
"is-windows": "^1.0.1" | ||
}, | ||
"devDependencies": { | ||
"gulp-format-md": "^1.0.0", | ||
"mocha": "^3.2.0" | ||
"gulp-format-md": "^2.0.0", | ||
"mocha": "^6.0.2" | ||
}, | ||
@@ -33,0 +28,0 @@ "keywords": [ |
@@ -1,2 +0,2 @@ | ||
# bash-path [![NPM version](https://img.shields.io/npm/v/bash-path.svg?style=flat)](https://www.npmjs.com/package/bash-path) [![NPM monthly downloads](https://img.shields.io/npm/dm/bash-path.svg?style=flat)](https://npmjs.org/package/bash-path) [![NPM total downloads](https://img.shields.io/npm/dt/bash-path.svg?style=flat)](https://npmjs.org/package/bash-path) [![Linux Build Status](https://img.shields.io/travis/micromatch/bash-path.svg?style=flat&label=Travis)](https://travis-ci.org/micromatch/bash-path) [![Windows Build Status](https://img.shields.io/appveyor/ci/micromatch/bash-path.svg?style=flat&label=AppVeyor)](https://ci.appveyor.com/project/micromatch/bash-path) | ||
# bash-path [![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=W8YFZ425KND68) [![NPM version](https://img.shields.io/npm/v/bash-path.svg?style=flat)](https://www.npmjs.com/package/bash-path) [![NPM monthly downloads](https://img.shields.io/npm/dm/bash-path.svg?style=flat)](https://npmjs.org/package/bash-path) [![NPM total downloads](https://img.shields.io/npm/dt/bash-path.svg?style=flat)](https://npmjs.org/package/bash-path) [![Linux Build Status](https://img.shields.io/travis/micromatch/bash-path.svg?style=flat&label=Travis)](https://travis-ci.org/micromatch/bash-path) | ||
@@ -68,8 +68,9 @@ > Get the path to the bash binary on your OS. | ||
* [github/jonschlinkert](https://github.com/jonschlinkert) | ||
* [twitter/jonschlinkert](https://twitter.com/jonschlinkert) | ||
* [GitHub Profile](https://github.com/jonschlinkert) | ||
* [Twitter Profile](https://twitter.com/jonschlinkert) | ||
* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert) | ||
### License | ||
Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert). | ||
Copyright © 2019, [Jon Schlinkert](https://github.com/jonschlinkert). | ||
Released under the [MIT License](LICENSE). | ||
@@ -79,2 +80,2 @@ | ||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on October 19, 2017._ | ||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on March 31, 2019._ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
0
79
6080
4
56
- Removedarr-union@^3.1.0
- Removedis-windows@^1.0.1
- Removedarr-union@3.1.0(transitive)
- Removedis-windows@1.0.2(transitive)