Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

resolve-bin

Package Overview
Dependencies
Maintainers
2
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

resolve-bin - npm Package Compare versions

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);
}

4

package.json
{
"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"> &rarr; {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">
&lt;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) {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc