Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var binCheck = lazyReq('bin-check');
var binVersionCheck = lazyReq('bin-version-check');
var Download = lazyReq('download');
var osFilterObj = lazyReq('os-filter-obj');
var which = require('which');

/**
* Initialize a new `BinWrapper`
Expand Down Expand Up @@ -109,6 +110,12 @@ BinWrapper.prototype.version = function (range) {
*/

BinWrapper.prototype.path = function () {
var systemBin = which.sync(this.use(), {nothrow: true})

if (systemBin) {
return systemBin;
}

return path.join(this.dest(), this.use());
};

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"download": "^4.0.0",
"each-async": "^1.1.1",
"lazy-req": "^1.0.0",
"os-filter-obj": "^1.0.0"
"os-filter-obj": "^1.0.0",
"which": "^1.3.0"
},
"devDependencies": {
"ava": "*",
Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Get the path to your binary with `bin.path()`:
console.log(bin.path()); // => path/to/vendor/gifsicle
```

> if you have the requested binary installed globally, this one will be used instead (if everything works)

## API

Expand Down
10 changes: 10 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,13 @@ test('error if no binary is found and no source is provided', t => {

t.throws(pify(bin.run.bind(bin))(), 'No binary found matching your system. It\'s probably not supported.');
});

test('can use a system binary if found in PATH', async t => {
const bin = new Fn()
.dest(tempfile())
.use(process.platform === 'win32' ? 'node.exe' : 'node');

await pify(bin.run.bind(bin))();

t.true(await pathExists(bin.path()));
});