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

resolve-bin

Package Overview
Dependencies
Maintainers
1
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.1.1 to 0.2.0

12

examples/mocha.js

@@ -5,3 +5,3 @@ 'use strict';

// package.json:
// package.json:
// "bin": {

@@ -13,5 +13,13 @@ // "mocha": "./bin/mocha",

if (err) return console.error(err);
console.log(bin);
console.log(bin);
});
// => [..]/resolve-bin/node_modules/mocha/bin/mocha
resolveBin('mocha', { executable: '_mocha' }, function (err, bin) {
if (err) return console.error(err);
console.log(bin);
});
// => [..]/resolve-bin/node_modules/mocha/bin/_mocha

18

index.js

@@ -7,10 +7,18 @@ 'use strict';

/**
* Resolves the full path to the bin file of a given package by inspecting the "bin" field in its package.json.
* Resolves the full path to the bin file of a given package by inspecting the "bin" field in its package.json.
*
* @name resolveBin
* @function
* @param name {String} module name, i.e. 'tap'
* @param cb {Function} called back with the full path to the bin file of the module or an error if it couldn't be resolved
* @param {string} name module name, i.e. 'tap'
* @param {Object=} opts options
* @param {string} opts.executable (default: @name) executable name (e.g. 'buster-test')
* @param {function} cb called back with the full path to the bin file of the module or an error if it couldn't be resolved
*/
module.exports = function (name, cb) {
module.exports = function (name, opts, cb) {
if (typeof opts === "function") {
cb = opts;
opts = {};
}
var executable = opts.executable || name;
var mod;

@@ -29,3 +37,3 @@ try {

var binpath = typeof binfield === 'object' ? binfield[name] : binfield;
var binpath = typeof binfield === 'object' ? binfield[executable] : binfield;
var bin = path.join(dir, binpath);

@@ -32,0 +40,0 @@ cb(null, bin);

{
"name": "resolve-bin",
"version": "0.1.1",
"version": "0.2.0",
"description": "Resolves the full path to the bin file of a given package by inspecting the \"bin\" field in its package.json.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -23,17 +23,105 @@ # resolve-bin [![build status](https://secure.travis-ci.org/thlorenz/resolve-bin.png)](http://travis-ci.org/thlorenz/resolve-bin)

###*resolveBin(name, cb)*
```
/**
* Resolves the full path to the bin file of a given package by inspecting the "bin" field in its package.json.
*
* @name resolveBin
* @function
* @param name {String} module name, i.e. 'tap'
* @param cb {Function} called back with the full path to the bin file of the module or an error if it couldn't be resolved
*/
```
<!-- START docme generated API please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN docme TO UPDATE -->
<div>
<div class="jsdoc-githubify">
<section>
<article>
<div class="container-overview">
<dl class="details">
</dl>
</div>
<dl>
<dt>
<h4 class="name" id="resolveBin"><span class="type-signature"></span>resolveBin<span class="signature">(name, <span class="optional">opts</span>, cb)</span><span class="type-signature"></span></h4>
</dt>
<dd>
<div class="description">
<p>Resolves the full path to the bin file of a given package by inspecting the &quot;bin&quot; field in its package.json.</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>
<tr>
<td class="name"><code>cb</code></td>
<td class="type">
<span class="param-type">function</span>
</td>
<td class="attributes">
</td>
<td class="description last"><p>called back with the full path to the bin file of the module or an error if it couldn't be resolved</p></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#L6">lineno 6</a>
</li>
</ul></dd>
</dl>
</dd>
</dl>
</article>
</section>
</div>
*generated with [docme](https://github.com/thlorenz/docme)*
</div>
<!-- END docme generated API please keep comment here to allow auto update -->
## License
MIT

@@ -8,3 +8,3 @@ 'use strict';

function relative (dir) {
function relative(dir) {
return path.relative(path.join(__dirname, '..'), dir)

@@ -19,3 +19,3 @@ }

});
})
})

@@ -28,4 +28,20 @@ test('\nmocha', function (t) {

});
})
})
test('\n_mocha', function (t) {
resolveBin('mocha', { executable: "_mocha" }, function (err, bin) {
if (err) throw err;
t.equal(relative(bin), 'node_modules/mocha/bin/_mocha')
t.end()
});
})
test('\nno `executable` in options', function (t) {
resolveBin('mocha', {}, function (err, bin) {
if (err) throw err;
t.equal(relative(bin), 'node_modules/mocha/bin/mocha')
t.end()
});
})
test('\nnon-existent', function (t) {

@@ -38,2 +54,2 @@ resolveBin('non-existent', 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