Skip to content

Commit

Permalink
Use binary destination set in package.json
Browse files Browse the repository at this point in the history
Fixes #31.
  • Loading branch information
kevva committed Dec 30, 2014
1 parent d62c815 commit 59a012e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
27 changes: 25 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
var binCheck = require('bin-check');
var binVersionCheck = require('bin-version-check');
var Download = require('download');
var find = require('findup-sync');
var globby = require('globby');
var isPathGlobal = require('is-path-global');
var osFilterObj = require('os-filter-obj');
Expand Down Expand Up @@ -63,8 +64,11 @@ BinWrapper.prototype.src = function (src, os, arch) {

BinWrapper.prototype.dest = function (dest) {
if (!arguments.length && !this._dest) {
this._dest = tempfile();
return this._dest;
if (this.pkg()) {
this._dest = this.pkg();
} else {
this._dest = tempfile();
}
}

if (!arguments.length) {
Expand Down Expand Up @@ -291,6 +295,25 @@ BinWrapper.prototype.get = function (cb) {
download.run(cb);
};

/**
* Get destination from package.json
*
* @api private
*/

BinWrapper.prototype.pkg = function () {
delete require.cache[__filename];

var dir = path.dirname(module.parent.filename);
var pkg = require(find('package.json', { cwd: dir }));

if (pkg.bin[path.basename(this.use())]) {
return path.resolve(path.dirname(pkg.bin[path.basename(this.use())]));
}

return path.resolve(path.dirname(pkg.bin));
};

/**
* Module exports
*/
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"bin-version-check": "^2.1.0",
"download": "^3.3.0",
"download-status": "^2.0.0",
"findup-sync": "^0.2.1",
"globby": "^1.0.0",
"is-path-global": "^1.0.0",
"lnfs": "^1.0.0",
Expand Down

0 comments on commit 59a012e

Please sign in to comment.