resolve-bin
Advanced tools
Comparing version 0.3.0 to 0.4.0
28
index.js
@@ -43,1 +43,29 @@ 'use strict'; | ||
} | ||
/** | ||
* Resolves the full path to the bin file of a given package by inspecting the "bin" field in its package.json. | ||
* | ||
* @name resolveBin.sync | ||
* @function | ||
* @param {string} name module name, i.e. 'tap' | ||
* @param {Object=} opts options | ||
* @param {string} opts.executable (default: @name) executable name (e.g. 'buster-test') | ||
* @returns {string} | ||
*/ | ||
module.exports.sync = function sync (name, opts) { | ||
opts = opts || {}; | ||
var executable = opts.executable || name; | ||
var mod = require.resolve(name); | ||
var dir = findParentDir.sync(mod, 'package.json') | ||
var pack = require(path.join(dir, 'package.json')); | ||
var binfield = pack.bin; | ||
var binpath = typeof binfield === 'object' ? binfield[executable] : binfield; | ||
if (!binpath) throw new Error("No bin `" + executable + "` in module `" + name + "`"); | ||
return path.join(dir, binpath); | ||
} |
{ | ||
"name": "resolve-bin", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "Resolves the full path to the bin file of a given package by inspecting the \"bin\" field in its package.json.", | ||
@@ -15,3 +15,3 @@ "main": "index.js", | ||
"dependencies": { | ||
"find-parent-dir": "~0.1.0" | ||
"find-parent-dir": "~0.3.0" | ||
}, | ||
@@ -18,0 +18,0 @@ "devDependencies": { |
@@ -115,3 +115,75 @@ # resolve-bin [![build status](https://secure.travis-ci.org/thlorenz/resolve-bin.png)](http://travis-ci.org/thlorenz/resolve-bin) | ||
</dd> | ||
<dt> | ||
<h4 class="name" id="resolveBin::sync"><span class="type-signature"></span>resolveBin::sync<span class="signature">(name, <span class="optional">opts</span>)</span><span class="type-signature"> → {string}</span></h4> | ||
</dt> | ||
<dd> | ||
<div class="description"> | ||
<p>Synchronous version of resolveBin</p> | ||
</div> | ||
<h5>Parameters:</h5> | ||
<table class="params"> | ||
<thead> | ||
<tr> | ||
<th>Name</th> | ||
<th>Type</th> | ||
<th>Argument</th> | ||
<th class="last">Description</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<td class="name"><code>name</code></td> | ||
<td class="type"> | ||
<span class="param-type">string</span> | ||
</td> | ||
<td class="attributes"> | ||
</td> | ||
<td class="description last"><p>module name, i.e. 'tap'</p></td> | ||
</tr> | ||
<tr> | ||
<td class="name"><code>opts</code></td> | ||
<td class="type"> | ||
<span class="param-type">Object</span> | ||
</td> | ||
<td class="attributes"> | ||
<optional><br> | ||
</td> | ||
<td class="description last"><p>options</p> | ||
<h6>Properties</h6> | ||
<table class="params"> | ||
<thead> | ||
<tr> | ||
<th>Name</th> | ||
<th>Type</th> | ||
<th class="last">Description</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<td class="name"><code>executable</code></td> | ||
<td class="type"> | ||
<span class="param-type">string</span> | ||
</td> | ||
<td class="description last"><p>(default: @name) executable name (e.g. 'buster-test')</p></td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
<dl class="details"> | ||
<dt class="tag-source">Source:</dt> | ||
<dd class="tag-source"><ul class="dummy"> | ||
<li> | ||
<a href="https://github.com/thlorenz/resolve-bin/blob/master/index.js">index.js</a> | ||
<span>, </span> | ||
<a href="https://github.com/thlorenz/resolve-bin/blob/master/index.js#L55">lineno 55</a> | ||
</li> | ||
</ul></dd> | ||
</dl> | ||
</dd> | ||
</dl> | ||
</article> | ||
@@ -118,0 +190,0 @@ </section> |
@@ -20,2 +20,8 @@ 'use strict'; | ||
test('\ntap sync', function (t) { | ||
var bin = resolveBin.sync('tap'); | ||
t.equal(relative(bin), 'node_modules/tap/bin/tap.js'); | ||
t.end(); | ||
}) | ||
test('\nmocha', function (t) { | ||
@@ -54,2 +60,9 @@ resolveBin('mocha', function (err, bin) { | ||
test('\nnon-existent module sync', function (t) { | ||
t.throws(function () { | ||
resolveBin.sync('non-existent') | ||
}) | ||
t.end() | ||
}) | ||
test('\nnon-existent executable inside module', function (t) { | ||
@@ -56,0 +69,0 @@ resolveBin('mocha', { executable: "no-such-bin" }, function (err, bin) { |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
11562
143
199
4
1
+ Addedfind-parent-dir@0.3.1(transitive)
- Removedfind-parent-dir@0.1.0(transitive)
Updatedfind-parent-dir@~0.3.0