get-installed-path
Advanced tools
Comparing version 3.0.0 to 3.0.1
29
index.js
@@ -22,5 +22,3 @@ /*! | ||
* | ||
* **Example** | ||
* | ||
* ```js | ||
* @example | ||
* const getInstalledPath = require('get-installed-path') | ||
@@ -75,10 +73,9 @@ * | ||
* // entry script. | ||
* ``` | ||
* | ||
* @param {String} `name` package name | ||
* @param {Object} `opts` pass `opts.local` to check locally | ||
* @param {string} name package name | ||
* @param {Object} opts pass `opts.local` to check locally | ||
* @return {Promise} rejected promise if `name` not a string or is empty string | ||
* @api public | ||
* @name getInstalledPath | ||
* @public | ||
*/ | ||
module.exports = function getInstalledPath (name, opts) { | ||
@@ -117,6 +114,6 @@ return new Promise((resolve, reject) => { | ||
* > Get installed path of a `name` package synchronous. | ||
* Returns `boolean` when `paths` option is used and filepath is directory, | ||
* otherwise returns a full filepath OR throws error. | ||
* | ||
* **Example** | ||
* | ||
* ```js | ||
* @example | ||
* const getInstalledPath = require('get-installed-path') | ||
@@ -131,11 +128,9 @@ * | ||
* // => '~/code/get-installed-path/node_modules/global-modules' | ||
* ``` | ||
* | ||
* @param {string} name package name | ||
* @param {Object} opts pass `opts.local` to check locally | ||
* @return {string} The full filepath or throw `TypeError` if `name` not a string or is empty string | ||
* @name .sync | ||
* @param {String} `name` package name | ||
* @param {Object} `opts` pass `opts.local` to check locally | ||
* @return {Boolean} or throw `TypeError` if `name` not a string or is empty string | ||
* @api public | ||
* @public | ||
*/ | ||
module.exports.sync = function getInstalledPathSync (name, opts) { | ||
@@ -142,0 +137,0 @@ if (!isValidString(name)) { |
{ | ||
"name": "get-installed-path", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"description": "Get installation path where the given package is installed. Works for globally and locally installed packages", | ||
@@ -5,0 +5,0 @@ "repository": "tunnckoCore/get-installed-path", |
111
README.md
@@ -29,2 +29,4 @@ # get-installed-path [![npm version][npmv-img]][npmv-url] [![github release][github-release-img]][github-release-url] [![mit License][license-img]][license-url] [![NPM Downloads Weekly][downloads-weekly-img]][downloads-weekly-url] [![NPM Downloads Total][downloads-total-img]][downloads-total-url] | ||
- [API](#api) | ||
* [getInstalledPath](#getinstalledpath) | ||
* [.sync](#sync) | ||
- [Related](#related) | ||
@@ -48,2 +50,97 @@ - [Contributing](#contributing) | ||
### [getInstalledPath](index.js#L80) | ||
> Get installed path of globally or locally `name` package. | ||
By default it checks if `name` exists as directory in [global-modules][] | ||
directory of the system. Pass `opts.local` to get path of `name` | ||
package from local directory or from `opts.cwd`. Returns rejected | ||
promise if module not found in global/local `node_modules` folder or | ||
if it exist but is not a directory. | ||
**Params** | ||
* `name` **{string}**: package name | ||
* `opts` **{Object}**: pass `opts.local` to check locally | ||
* `returns` **{Promise}**: rejected promise if `name` not a string or is empty string | ||
**Example** | ||
```jsx | ||
const getInstalledPath = require('get-installed-path') | ||
getInstalledPath('npm').then((path) => { | ||
console.log(path) | ||
// => '/home/charlike/.nvm/path/to/lib/node_modules/npm' | ||
}) | ||
getInstalledPath('foo-bar-barwerwlekrjw').catch((err) => { | ||
console.log(err.message) | ||
// => 'module not found "foo-bar-barwerwlekrjw" in path ...' | ||
}) | ||
getInstalledPath('npm', { | ||
local: true | ||
}).catch((err) => { | ||
console.log(err.message) | ||
// => 'module not found "foo-bar-barwerwlekrjw" in path ...' | ||
}) | ||
getInstalledPath('global-modules', { | ||
local: true | ||
}).then((path) => { | ||
console.log(path) | ||
// => '~/code/get-installed-path/node_modules/global-modules' | ||
}) | ||
// If you are using it for some sub-directory | ||
// pass `opts.cwd` to be where the `node_modules` | ||
// folder is. | ||
process.chidr('foo-bar-baz') | ||
getInstalledPath('global-modules', { | ||
local: true, | ||
cwd: '../' | ||
}).then((path) => { | ||
console.log(path) | ||
// => '~/code/get-installed-path/node_modules/global-modules' | ||
}) | ||
// When searching for the path of a package that is required | ||
// by several other packages, its path may not be in the | ||
// closest node_modules. In this case, to search recursively, | ||
// you can use the following: | ||
getInstalledPath('npm', { | ||
paths: process.mainModule.paths | ||
}).then((path) => { | ||
// ... | ||
}) | ||
// `process.mainModule` refers to the location of the current | ||
// entry script. | ||
``` | ||
### [.sync](index.js#L133) | ||
> Get installed path of a `name` package synchronous. | ||
Returns `boolean` when `paths` option is used and filepath is directory, | ||
otherwise returns a full filepath OR throws error. | ||
**Params** | ||
* `name` **{string}**: package name | ||
* `opts` **{Object}**: pass `opts.local` to check locally | ||
* `returns` **{string}**: The full filepath or throw `TypeError` if `name` not a string or is empty string | ||
**Example** | ||
```jsx | ||
const getInstalledPath = require('get-installed-path') | ||
const npmPath = getInstalledPath.sync('npm') | ||
console.log(npmPath) | ||
// => '/home/charlike/.nvm/path/to/lib/node_modules/npm' | ||
const gmPath = getInstalledPath.sync('global-modules', { local: true }) | ||
console.log(gmPath) | ||
// => '~/code/get-installed-path/node_modules/global-modules' | ||
``` | ||
## Related | ||
@@ -76,2 +173,9 @@ - [always-done](https://www.npmjs.com/package/always-done): Handle completion and errors with elegance! Support for streams, callbacks, promises, child… [more](https://github.com/hybridables/always-done#readme) | [homepage](https://github.com/hybridables/always-done#readme "Handle completion and errors with elegance! Support for streams, callbacks, promises, child processes, async/await and sync functions. A drop-in replacement for [async-done][] - pass 100% of its tests plus more") | ||
[always-done]: https://github.com/hybridables/always-done | ||
[async-done]: https://github.com/gulpjs/async-done | ||
[base]: https://github.com/node-base/base | ||
[charlike-cli]: https://github.com/tunnckoCore/charlike-cli | ||
[dezalgo]: https://github.com/npm/dezalgo | ||
[once]: https://github.com/isaacs/once | ||
<!-- Heading badges --> | ||
@@ -135,7 +239,2 @@ [npmv-url]: https://www.npmjs.com/package/get-installed-path | ||
[always-done]: https://github.com/hybridables/always-done | ||
[async-done]: https://github.com/gulpjs/async-done | ||
[base]: https://github.com/node-base/base | ||
[charlike-cli]: https://github.com/tunnckoCore/charlike-cli | ||
[dezalgo]: https://github.com/npm/dezalgo | ||
[once]: https://github.com/isaacs/once | ||
[global-modules]: https://github.com/jonschlinkert/global-modules |
23259
236
163