serverless-spy 0.0.41 → 0.0.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.jsii +2 -3
- package/cli/cli.ts +53 -12
- package/cli/package.json +1 -4
- package/dist/releasetag.txt +1 -1
- package/lib/cli/cli.js +37 -13
- package/lib/cli/cli.mjs +37 -13
- package/lib/cli/cli.ts +53 -12
- package/lib/cli/package.json +1 -4
- package/lib/src/ServerlessSpy.js +1 -1
- package/package.json +1 -3
- package/node_modules/expand-tilde/LICENSE +0 -21
- package/node_modules/expand-tilde/README.md +0 -80
- package/node_modules/expand-tilde/index.js +0 -22
- package/node_modules/expand-tilde/package.json +0 -67
- package/node_modules/get-installed-path/CHANGELOG.md +0 -99
- package/node_modules/get-installed-path/LICENSE +0 -21
- package/node_modules/get-installed-path/README.md +0 -282
- package/node_modules/get-installed-path/dist/index.es.js +0 -181
- package/node_modules/get-installed-path/dist/index.js +0 -188
- package/node_modules/get-installed-path/package.json +0 -101
- package/node_modules/global-modules/LICENSE +0 -21
- package/node_modules/global-modules/README.md +0 -75
- package/node_modules/global-modules/index.js +0 -31
- package/node_modules/global-modules/package.json +0 -72
- package/node_modules/global-prefix/LICENSE +0 -21
- package/node_modules/global-prefix/README.md +0 -78
- package/node_modules/global-prefix/index.js +0 -96
- package/node_modules/global-prefix/node_modules/which/CHANGELOG.md +0 -152
- package/node_modules/global-prefix/node_modules/which/LICENSE +0 -15
- package/node_modules/global-prefix/node_modules/which/README.md +0 -51
- package/node_modules/global-prefix/node_modules/which/bin/which +0 -52
- package/node_modules/global-prefix/node_modules/which/package.json +0 -30
- package/node_modules/global-prefix/node_modules/which/which.js +0 -135
- package/node_modules/global-prefix/package.json +0 -75
- package/node_modules/homedir-polyfill/LICENSE +0 -21
- package/node_modules/homedir-polyfill/README.md +0 -96
- package/node_modules/homedir-polyfill/index.js +0 -9
- package/node_modules/homedir-polyfill/package.json +0 -62
- package/node_modules/homedir-polyfill/polyfill.js +0 -81
- package/node_modules/ini/LICENSE +0 -15
- package/node_modules/ini/README.md +0 -102
- package/node_modules/ini/ini.js +0 -206
- package/node_modules/ini/package.json +0 -33
- package/node_modules/is-windows/LICENSE +0 -21
- package/node_modules/is-windows/README.md +0 -95
- package/node_modules/is-windows/index.js +0 -27
- package/node_modules/is-windows/package.json +0 -71
- package/node_modules/isexe/.npmignore +0 -2
- package/node_modules/isexe/LICENSE +0 -15
- package/node_modules/isexe/README.md +0 -51
- package/node_modules/isexe/index.js +0 -57
- package/node_modules/isexe/mode.js +0 -41
- package/node_modules/isexe/package.json +0 -31
- package/node_modules/isexe/test/basic.js +0 -221
- package/node_modules/isexe/windows.js +0 -42
- package/node_modules/parse-passwd/LICENSE +0 -21
- package/node_modules/parse-passwd/README.md +0 -86
- package/node_modules/parse-passwd/index.js +0 -56
- package/node_modules/parse-passwd/package.json +0 -55
- package/node_modules/resolve-dir/LICENSE +0 -21
- package/node_modules/resolve-dir/README.md +0 -88
- package/node_modules/resolve-dir/index.js +0 -22
- package/node_modules/resolve-dir/package.json +0 -73
|
@@ -1,282 +0,0 @@
|
|
|
1
|
-
# 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 Total][downloads-total-img]][npmv-url]
|
|
2
|
-
|
|
3
|
-
<!--
|
|
4
|
-
[![NPM Downloads Weekly][downloads-weekly-img]][npmv-url]
|
|
5
|
-
[![NPM Downloads Total][downloads-total-img]][npmv-url] -->
|
|
6
|
-
|
|
7
|
-
> Get installation path where the given package is installed. Works for globally and locally installed packages
|
|
8
|
-
|
|
9
|
-
<div id="thetop"></div>
|
|
10
|
-
|
|
11
|
-
You might also be interested in [detect-installed](https://github.com/tunnckocore/detect-installed#readme).
|
|
12
|
-
|
|
13
|
-
## Quality Assurance :100:
|
|
14
|
-
|
|
15
|
-
[![Code Climate][codeclimate-img]][codeclimate-url]
|
|
16
|
-
[![Code Style Standard][standard-img]][standard-url]
|
|
17
|
-
[![Linux Build][travis-img]][travis-url]
|
|
18
|
-
[![Code Coverage][codecov-img]][codecov-url]
|
|
19
|
-
[![Dependencies Status][dependencies-img]][dependencies-url]
|
|
20
|
-
[![Renovate App Status][renovate-img]][renovate-url]
|
|
21
|
-
[![Node Version Required][nodeversion-img]][nodeversion-url]
|
|
22
|
-
|
|
23
|
-
If you have any _how-to_ kind of questions, please read [Code of Conduct](./CODE_OF_CONDUCT.md) and **join the chat** room or [open an issue][open-issue-url].
|
|
24
|
-
You may also read the [Contributing Guide](./CONTRIBUTING.md). There, beside _"How to contribute?"_, we describe everything **_stated_** by the badges.
|
|
25
|
-
|
|
26
|
-
[![tunnckoCore support][chat-img]][chat-url]
|
|
27
|
-
[![Code Format Prettier][prettier-img]][prettier-url]
|
|
28
|
-
[![Node Security Status][nodesecurity-img]][nodesecurity-url]
|
|
29
|
-
[![Conventional Commits][ccommits-img]][ccommits-url]
|
|
30
|
-
[![Semantic Release][semantic-release-img]][semantic-release-url]
|
|
31
|
-
[![First Timers Only][first-timers-only-img]][first-timers-only-url]
|
|
32
|
-
|
|
33
|
-
<a target="_blank" rel="nofollow" href="https://app.codesponsor.io/link/K7yYzzA5nb2ZDR4GTKmgUdfe/tunnckoCore/get-installed-path">
|
|
34
|
-
<img alt="Sponsor" width="888" height="68" src="https://app.codesponsor.io/embed/K7yYzzA5nb2ZDR4GTKmgUdfe/tunnckoCore/get-installed-path.svg" />
|
|
35
|
-
</a>
|
|
36
|
-
<br>
|
|
37
|
-
<br>
|
|
38
|
-
|
|
39
|
-
[![All Contributors Spec][all-contributors-img]](#contributors)
|
|
40
|
-
[![Make A Pull Request][prs-welcome-img]][prs-welcome-url]
|
|
41
|
-
[![Newsletter Subscribe][tinyletter-img]][tinyletter-url]
|
|
42
|
-
[![PayPal Author Support][paypal-donate-img]][paypal-donate-url]
|
|
43
|
-
[![Share Love][share-love-img]][share-love-url]
|
|
44
|
-
[![BitHound Code][bithound-code-img]][bithound-code-url]
|
|
45
|
-
|
|
46
|
-
## Table of Contents
|
|
47
|
-
- [Install](#install)
|
|
48
|
-
- [API](#api)
|
|
49
|
-
* [getInstalledPath](#getinstalledpath)
|
|
50
|
-
* [getInstalledPathSync](#getinstalledpathsync)
|
|
51
|
-
- [Related](#related)
|
|
52
|
-
- [Contributing](#contributing)
|
|
53
|
-
- [Author](#author)
|
|
54
|
-
- [License](#license)
|
|
55
|
-
|
|
56
|
-
_(TOC generated by [verb](https://github.com/verbose/verb) using [markdown-toc](https://github.com/jonschlinkert/markdown-toc))_
|
|
57
|
-
|
|
58
|
-
## Install
|
|
59
|
-
|
|
60
|
-
This project requires [**Node.js**][nodeversion-url] **v6** and above. Use [**yarn**](https://yarnpkg.com) **v1** / [**npm**](https://www.npmjs.com) **v5** or above to install it.
|
|
61
|
-
|
|
62
|
-
```
|
|
63
|
-
$ yarn add get-installed-path
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
## API
|
|
67
|
-
Review carefully the provided examples and the working [tests](./test/index.js).
|
|
68
|
-
|
|
69
|
-
### [getInstalledPath](src/index.js#L71)
|
|
70
|
-
|
|
71
|
-
> Get installed path of globally or locally `name` package.
|
|
72
|
-
By default it checks if `name` exists as directory in [global-modules][]
|
|
73
|
-
directory of the system. Pass `opts.local` to get path of `name`
|
|
74
|
-
package from local directory or from `opts.cwd`. Returns rejected
|
|
75
|
-
promise if module not found in global/local `node_modules` folder or
|
|
76
|
-
if it exist but is not a directory.
|
|
77
|
-
|
|
78
|
-
**Params**
|
|
79
|
-
|
|
80
|
-
* `name` **{string}**: package name
|
|
81
|
-
* `opts` **{Object}**: pass `opts.local` to check locally
|
|
82
|
-
* `returns` **{Promise}**: rejected promise if `name` not a string or is empty string
|
|
83
|
-
|
|
84
|
-
**Example**
|
|
85
|
-
|
|
86
|
-
```jsx
|
|
87
|
-
const { getInstalledPath } = require('get-installed-path')
|
|
88
|
-
|
|
89
|
-
getInstalledPath('npm').then((path) => {
|
|
90
|
-
console.log(path)
|
|
91
|
-
// => '/home/charlike/.nvm/path/to/lib/node_modules/npm'
|
|
92
|
-
})
|
|
93
|
-
|
|
94
|
-
getInstalledPath('foo-bar-barwerwlekrjw').catch((err) => {
|
|
95
|
-
console.log(err.message)
|
|
96
|
-
// => 'module not found "foo-bar-barwerwlekrjw" in path ...'
|
|
97
|
-
})
|
|
98
|
-
|
|
99
|
-
getInstalledPath('npm', {
|
|
100
|
-
local: true
|
|
101
|
-
}).catch((err) => {
|
|
102
|
-
console.log(err.message)
|
|
103
|
-
// => 'module not found "foo-bar-barwerwlekrjw" in path ...'
|
|
104
|
-
})
|
|
105
|
-
|
|
106
|
-
getInstalledPath('global-modules', {
|
|
107
|
-
local: true
|
|
108
|
-
}).then((path) => {
|
|
109
|
-
console.log(path)
|
|
110
|
-
// => '~/code/get-installed-path/node_modules/global-modules'
|
|
111
|
-
})
|
|
112
|
-
|
|
113
|
-
// If you are using it for some sub-directory
|
|
114
|
-
// pass `opts.cwd` to be where the `node_modules`
|
|
115
|
-
// folder is.
|
|
116
|
-
process.chidr('foo-bar-baz')
|
|
117
|
-
getInstalledPath('global-modules', {
|
|
118
|
-
local: true,
|
|
119
|
-
cwd: '../'
|
|
120
|
-
}).then((path) => {
|
|
121
|
-
console.log(path)
|
|
122
|
-
// => '~/code/get-installed-path/node_modules/global-modules'
|
|
123
|
-
})
|
|
124
|
-
|
|
125
|
-
// When searching for the path of a package that is required
|
|
126
|
-
// by several other packages, its path may not be in the
|
|
127
|
-
// closest node_modules. In this case, to search recursively,
|
|
128
|
-
// you can use the following:
|
|
129
|
-
getInstalledPath('npm', {
|
|
130
|
-
paths: process.mainModule.paths
|
|
131
|
-
}).then((path) => {
|
|
132
|
-
// ...
|
|
133
|
-
})
|
|
134
|
-
// `process.mainModule` refers to the location of the current
|
|
135
|
-
// entry script.
|
|
136
|
-
```
|
|
137
|
-
|
|
138
|
-
### [getInstalledPathSync](src/index.js#L124)
|
|
139
|
-
|
|
140
|
-
> Get installed path of a `name` package synchronous.
|
|
141
|
-
Returns `boolean` when `paths` option is used and filepath is directory,
|
|
142
|
-
otherwise returns a full filepath OR throws error.
|
|
143
|
-
|
|
144
|
-
**Params**
|
|
145
|
-
|
|
146
|
-
* `name` **{string}**: package name
|
|
147
|
-
* `opts` **{Object}**: pass `opts.local` to check locally
|
|
148
|
-
* `returns` **{string}**: The full filepath or throw `TypeError` if `name` not a string or is empty string
|
|
149
|
-
|
|
150
|
-
**Example**
|
|
151
|
-
|
|
152
|
-
```jsx
|
|
153
|
-
const { getInstalledPathSync } = require('get-installed-path')
|
|
154
|
-
|
|
155
|
-
const npmPath = getInstalledPathSync('npm')
|
|
156
|
-
console.log(npmPath)
|
|
157
|
-
// => '/home/charlike/.nvm/path/to/lib/node_modules/npm'
|
|
158
|
-
|
|
159
|
-
const gmPath = getInstalledPathSync('global-modules', { local: true })
|
|
160
|
-
console.log(gmPath)
|
|
161
|
-
// => '~/code/get-installed-path/node_modules/global-modules'
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
**[back to top](#thetop)**
|
|
165
|
-
|
|
166
|
-
## Related
|
|
167
|
-
- [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")
|
|
168
|
-
- [detect-installed](https://www.npmjs.com/package/detect-installed): Checks that given package is installed globally or locally. | [homepage](https://github.com/tunnckocore/detect-installed#readme "Checks that given package is installed globally or locally.")
|
|
169
|
-
- [global-modules](https://www.npmjs.com/package/global-modules): The directory used by npm for globally installed npm modules. | [homepage](https://github.com/jonschlinkert/global-modules "The directory used by npm for globally installed npm modules.")
|
|
170
|
-
- [global-paths](https://www.npmjs.com/package/global-paths): Returns an array of unique "global" directories based on the user's platform… [more](https://github.com/jonschlinkert/global-paths) | [homepage](https://github.com/jonschlinkert/global-paths "Returns an array of unique "global" directories based on the user's platform and environment. The resulting paths can be used for doing lookups for generators or other globally installed npm packages. Node.js / JavaScript.")
|
|
171
|
-
- [global-prefix](https://www.npmjs.com/package/global-prefix): Get the npm global path prefix. | [homepage](https://github.com/jonschlinkert/global-prefix "Get the npm global path prefix.")
|
|
172
|
-
- [is-installed](https://www.npmjs.com/package/is-installed): Checks that given package is installed locally or globally. Useful for robust… [more](https://github.com/tunnckocore/is-installed#readme) | [homepage](https://github.com/tunnckocore/is-installed#readme "Checks that given package is installed locally or globally. Useful for robust resolving when you want some package - it will check first if it exists locally, then if it exists globally")
|
|
173
|
-
- [minibase](https://www.npmjs.com/package/minibase): Minimalist alternative for Base. Build complex APIs with small units called plugins… [more](https://github.com/node-minibase/minibase#readme) | [homepage](https://github.com/node-minibase/minibase#readme "Minimalist alternative for Base. Build complex APIs with small units called plugins. Works well with most of the already existing [base][] plugins.")
|
|
174
|
-
- [try-catch-core](https://www.npmjs.com/package/try-catch-core): Low-level package to handle completion and errors of sync or asynchronous functions… [more](https://github.com/hybridables/try-catch-core#readme) | [homepage](https://github.com/hybridables/try-catch-core#readme "Low-level package to handle completion and errors of sync or asynchronous functions, using [once][] and [dezalgo][] libs. Useful for and used in higher-level libs such as [always-done][] to handle completion of anything.")
|
|
175
|
-
|
|
176
|
-
**[back to top](#thetop)**
|
|
177
|
-
|
|
178
|
-
## Contributing
|
|
179
|
-
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue][open-issue-url].
|
|
180
|
-
Please read the [Contributing Guide](./CONTRIBUTING.md) and [Code of Conduct](./CODE_OF_CONDUCT.md) documents for advices.
|
|
181
|
-
|
|
182
|
-
## Author
|
|
183
|
-
- [github/tunnckoCore](https://github.com/tunnckoCore)
|
|
184
|
-
- [twitter/tunnckoCore](https://twitter.com/tunnckoCore)
|
|
185
|
-
- [codementor/tunnckoCore](https://codementor.io/tunnckoCore)
|
|
186
|
-
|
|
187
|
-
## License
|
|
188
|
-
Copyright © 2016-2017, [Charlike Mike Reagent](https://i.am.charlike.online). Released under the [MIT License](LICENSE).
|
|
189
|
-
|
|
190
|
-
***
|
|
191
|
-
|
|
192
|
-
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on October 12, 2017._
|
|
193
|
-
Project scaffolded and managed with [hela][].
|
|
194
|
-
|
|
195
|
-
[always-done]: https://github.com/hybridables/always-done
|
|
196
|
-
[async-done]: https://github.com/gulpjs/async-done
|
|
197
|
-
[base]: https://github.com/node-base/base
|
|
198
|
-
[charlike-cli]: https://github.com/tunnckoCore/charlike-cli
|
|
199
|
-
[dezalgo]: https://github.com/npm/dezalgo
|
|
200
|
-
[global-modules]: https://github.com/jonschlinkert/global-modules
|
|
201
|
-
[hela]: https://github.com/tunnckoCore/hela
|
|
202
|
-
[once]: https://github.com/isaacs/once
|
|
203
|
-
|
|
204
|
-
<!-- Heading badges -->
|
|
205
|
-
[npmv-url]: https://www.npmjs.com/package/get-installed-path
|
|
206
|
-
[npmv-img]: https://img.shields.io/npm/v/get-installed-path.svg?label=npm%20version
|
|
207
|
-
|
|
208
|
-
[open-issue-url]: https://github.com/tunnckoCore/get-installed-path/issues/new
|
|
209
|
-
[github-release-url]: https://github.com/tunnckoCore/get-installed-path/releases/latest
|
|
210
|
-
[github-release-img]: https://img.shields.io/github/release/tunnckoCore/get-installed-path.svg?label=github%20release
|
|
211
|
-
|
|
212
|
-
[license-url]: https://github.com/tunnckoCore/get-installed-path/blob/master/LICENSE
|
|
213
|
-
[license-img]: https://img.shields.io/npm/l/get-installed-path.svg
|
|
214
|
-
|
|
215
|
-
[downloads-weekly-img]: https://img.shields.io/npm/dw/get-installed-path.svg
|
|
216
|
-
[downloads-monthly-img]: https://img.shields.io/npm/dm/get-installed-path.svg
|
|
217
|
-
[downloads-total-img]: https://img.shields.io/npm/dt/get-installed-path.svg
|
|
218
|
-
|
|
219
|
-
<!-- Front line badges -->
|
|
220
|
-
[codeclimate-url]: https://codeclimate.com/github/tunnckoCore/get-installed-path
|
|
221
|
-
[codeclimate-img]: https://img.shields.io/codeclimate/github/tunnckoCore/get-installed-path.svg
|
|
222
|
-
|
|
223
|
-
[standard-url]: https://github.com/standard/standard
|
|
224
|
-
[standard-img]: https://img.shields.io/badge/code_style-standard-brightgreen.svg
|
|
225
|
-
|
|
226
|
-
[travis-url]: https://travis-ci.org/tunnckoCore/get-installed-path
|
|
227
|
-
[travis-img]: https://img.shields.io/travis/tunnckoCore/get-installed-path/master.svg?label=linux
|
|
228
|
-
|
|
229
|
-
[codecov-url]: https://codecov.io/gh/tunnckoCore/get-installed-path
|
|
230
|
-
[codecov-img]: https://img.shields.io/codecov/c/github/tunnckoCore/get-installed-path/master.svg
|
|
231
|
-
|
|
232
|
-
[dependencies-url]: https://david-dm.org/tunnckoCore/get-installed-path
|
|
233
|
-
[dependencies-img]: https://img.shields.io/david/tunnckoCore/get-installed-path.svg
|
|
234
|
-
|
|
235
|
-
[renovate-url]: https://renovateapp.com
|
|
236
|
-
[renovate-img]: https://img.shields.io/badge/renovate-enabled-brightgreen.svg
|
|
237
|
-
|
|
238
|
-
<!-- Second front of badges -->
|
|
239
|
-
|
|
240
|
-
[chat-url]: https://tunnckocore.flock.com/?i=cx2xoeofjtj6eo6c
|
|
241
|
-
[chat-img]: https://img.shields.io/badge/chat-on_flock-brightgreen.svg
|
|
242
|
-
|
|
243
|
-
[prettier-url]: https://github.com/prettier/prettier
|
|
244
|
-
[prettier-img]: https://img.shields.io/badge/styled_with-prettier-f952a5.svg
|
|
245
|
-
|
|
246
|
-
[nodesecurity-url]: https://nodesecurity.io/orgs/tunnckocore-dev/projects/fd91a3c7-498b-4ff8-8f29-5d93a9d97626
|
|
247
|
-
[nodesecurity-img]: https://nodesecurity.io/orgs/tunnckocore-dev/projects/fd91a3c7-498b-4ff8-8f29-5d93a9d97626/badge
|
|
248
|
-
<!-- the original color of nsp:
|
|
249
|
-
[nodesec-img]: https://img.shields.io/badge/nsp-no_known_vulns-35a9e0.svg -->
|
|
250
|
-
|
|
251
|
-
[semantic-release-url]: https://github.com/semantic-release/semantic-release
|
|
252
|
-
[semantic-release-img]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg
|
|
253
|
-
|
|
254
|
-
[ccommits-url]: https://conventionalcommits.org/
|
|
255
|
-
[ccommits-img]: https://img.shields.io/badge/conventional_commits-1.0.0-yellow.svg
|
|
256
|
-
|
|
257
|
-
[nodeversion-url]: https://nodejs.org/en/download
|
|
258
|
-
[nodeversion-img]: https://img.shields.io/node/v/get-installed-path.svg
|
|
259
|
-
|
|
260
|
-
[first-timers-only-img]: https://img.shields.io/badge/first--timers--only-friendly-blue.svg
|
|
261
|
-
[first-timers-only-url]: http://www.firsttimersonly.com
|
|
262
|
-
|
|
263
|
-
[prs-welcome-img]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg
|
|
264
|
-
[prs-welcome-url]: http://makeapullrequest.com
|
|
265
|
-
|
|
266
|
-
[all-contributors-img]: https://img.shields.io/github/contributors/tunnckoCore/get-installed-path.svg?label=all%20contributors&colorB=ffa500
|
|
267
|
-
|
|
268
|
-
[bithound-deps-url]: https://www.bithound.io/github/tunnckoCore/get-installed-path/master/dependencies/npm
|
|
269
|
-
[bithound-deps-img]: https://www.bithound.io/github/tunnckoCore/get-installed-path/badges/dependencies.svg
|
|
270
|
-
|
|
271
|
-
[bithound-code-url]: https://www.bithound.io/github/tunnckoCore/get-installed-path/master
|
|
272
|
-
[bithound-code-img]: https://www.bithound.io/github/tunnckoCore/get-installed-path/badges/code.svg
|
|
273
|
-
|
|
274
|
-
[paypal-donate-url]: https://paypal.me/tunnckoCore/10
|
|
275
|
-
[paypal-donate-img]: https://img.shields.io/badge/paypal-donate-009cde.svg
|
|
276
|
-
|
|
277
|
-
[tinyletter-url]: https://tinyletter.com/tunnckoCore
|
|
278
|
-
[tinyletter-img]: https://img.shields.io/badge/newsletter-subscribe-9caaf8.svg
|
|
279
|
-
|
|
280
|
-
[share-love-url]: https://twitter.com/intent/tweet?text=https://github.com/tunnckoCore/get-installed-path&via=tunnckoCore
|
|
281
|
-
[share-love-img]: https://img.shields.io/badge/share-♥-ed1c24.svg
|
|
282
|
-
|
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @author Charlike Mike Reagent <open.source.charlike@gmail.com>
|
|
3
|
-
* @copyright 2016-present @tunnckoCore/team and contributors
|
|
4
|
-
* @license MIT
|
|
5
|
-
*/
|
|
6
|
-
import fs from 'fs';
|
|
7
|
-
import path from 'path';
|
|
8
|
-
import modules from 'global-modules';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* > Get installed path of globally or locally `name` package.
|
|
12
|
-
* By default it checks if `name` exists as directory in [global-modules][]
|
|
13
|
-
* directory of the system. Pass `opts.local` to get path of `name`
|
|
14
|
-
* package from local directory or from `opts.cwd`. Returns rejected
|
|
15
|
-
* promise if module not found in global/local `node_modules` folder or
|
|
16
|
-
* if it exist but is not a directory.
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* const { getInstalledPath } = require('get-installed-path')
|
|
20
|
-
*
|
|
21
|
-
* getInstalledPath('npm').then((path) => {
|
|
22
|
-
* console.log(path)
|
|
23
|
-
* // => '/home/charlike/.nvm/path/to/lib/node_modules/npm'
|
|
24
|
-
* })
|
|
25
|
-
*
|
|
26
|
-
* getInstalledPath('foo-bar-barwerwlekrjw').catch((err) => {
|
|
27
|
-
* console.log(err.message)
|
|
28
|
-
* // => 'module not found "foo-bar-barwerwlekrjw" in path ...'
|
|
29
|
-
* })
|
|
30
|
-
*
|
|
31
|
-
* getInstalledPath('npm', {
|
|
32
|
-
* local: true
|
|
33
|
-
* }).catch((err) => {
|
|
34
|
-
* console.log(err.message)
|
|
35
|
-
* // => 'module not found "foo-bar-barwerwlekrjw" in path ...'
|
|
36
|
-
* })
|
|
37
|
-
*
|
|
38
|
-
* getInstalledPath('global-modules', {
|
|
39
|
-
* local: true
|
|
40
|
-
* }).then((path) => {
|
|
41
|
-
* console.log(path)
|
|
42
|
-
* // => '~/code/get-installed-path/node_modules/global-modules'
|
|
43
|
-
* })
|
|
44
|
-
*
|
|
45
|
-
* // If you are using it for some sub-directory
|
|
46
|
-
* // pass `opts.cwd` to be where the `node_modules`
|
|
47
|
-
* // folder is.
|
|
48
|
-
* process.chidr('foo-bar-baz')
|
|
49
|
-
* getInstalledPath('global-modules', {
|
|
50
|
-
* local: true,
|
|
51
|
-
* cwd: '../'
|
|
52
|
-
* }).then((path) => {
|
|
53
|
-
* console.log(path)
|
|
54
|
-
* // => '~/code/get-installed-path/node_modules/global-modules'
|
|
55
|
-
* })
|
|
56
|
-
*
|
|
57
|
-
* // When searching for the path of a package that is required
|
|
58
|
-
* // by several other packages, its path may not be in the
|
|
59
|
-
* // closest node_modules. In this case, to search recursively,
|
|
60
|
-
* // you can use the following:
|
|
61
|
-
* getInstalledPath('npm', {
|
|
62
|
-
* paths: process.mainModule.paths
|
|
63
|
-
* }).then((path) => {
|
|
64
|
-
* // ...
|
|
65
|
-
* })
|
|
66
|
-
* // `process.mainModule` refers to the location of the current
|
|
67
|
-
* // entry script.
|
|
68
|
-
*
|
|
69
|
-
* @param {string} name package name
|
|
70
|
-
* @param {Object} opts pass `opts.local` to check locally
|
|
71
|
-
* @return {Promise} rejected promise if `name` not a string or is empty string
|
|
72
|
-
* @name getInstalledPath
|
|
73
|
-
* @public
|
|
74
|
-
*/
|
|
75
|
-
|
|
76
|
-
function getInstalledPath(name, opts) {
|
|
77
|
-
return new Promise((resolve, reject) => {
|
|
78
|
-
if (!isValidString(name)) {
|
|
79
|
-
const message = 'get-installed-path: expect `name` to be string';
|
|
80
|
-
return reject(new TypeError(message));
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const targetPaths = defaults(name, opts);
|
|
84
|
-
|
|
85
|
-
const statPath = filepath => fs.stat(filepath, (e, stats) => {
|
|
86
|
-
if (e && targetPaths.length > 0) {
|
|
87
|
-
statPath(targetPaths.shift());
|
|
88
|
-
return;
|
|
89
|
-
} else if (e) {
|
|
90
|
-
const label = 'get-installed-path:';
|
|
91
|
-
const msg = `${label} module not found "${name}" in path ${filepath}`;
|
|
92
|
-
return reject(new Error(msg));
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
if (stats.isDirectory()) {
|
|
96
|
-
return resolve(filepath);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const msg = `Possibly "${name}" is not a directory: ${filepath}`;
|
|
100
|
-
let err = new Error('get-installed-path: some error occured! ' + msg);
|
|
101
|
-
reject(err);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
statPath(targetPaths.shift());
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* > Get installed path of a `name` package synchronous.
|
|
109
|
-
* Returns `boolean` when `paths` option is used and filepath is directory,
|
|
110
|
-
* otherwise returns a full filepath OR throws error.
|
|
111
|
-
*
|
|
112
|
-
* @example
|
|
113
|
-
* const { getInstalledPathSync } = require('get-installed-path')
|
|
114
|
-
*
|
|
115
|
-
* const npmPath = getInstalledPathSync('npm')
|
|
116
|
-
* console.log(npmPath)
|
|
117
|
-
* // => '/home/charlike/.nvm/path/to/lib/node_modules/npm'
|
|
118
|
-
*
|
|
119
|
-
* const gmPath = getInstalledPathSync('global-modules', { local: true })
|
|
120
|
-
* console.log(gmPath)
|
|
121
|
-
* // => '~/code/get-installed-path/node_modules/global-modules'
|
|
122
|
-
*
|
|
123
|
-
* @param {string} name package name
|
|
124
|
-
* @param {Object} opts pass `opts.local` to check locally
|
|
125
|
-
* @return {string} The full filepath or throw `TypeError` if `name` not a string or is empty string
|
|
126
|
-
* @name getInstalledPathSync
|
|
127
|
-
* @public
|
|
128
|
-
*/
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
function getInstalledPathSync(name, opts) {
|
|
132
|
-
if (!isValidString(name)) {
|
|
133
|
-
throw new TypeError('get-installed-path: expect `name` to be string');
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
const filePaths = defaults(name, opts);
|
|
137
|
-
const firstPath = filePaths[0];
|
|
138
|
-
const modulePath = filePaths.find(filePath => {
|
|
139
|
-
let stat = null;
|
|
140
|
-
|
|
141
|
-
try {
|
|
142
|
-
stat = fs.statSync(filePath);
|
|
143
|
-
} catch (e) {
|
|
144
|
-
return false;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
if (stat.isDirectory()) {
|
|
148
|
-
return true;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
const msg = `Possibly "${name}" is not a directory: ${filePath}`;
|
|
152
|
-
throw new Error('get-installed-path: some error occured! ' + msg);
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
if (!modulePath) {
|
|
156
|
-
const label = 'get-installed-path:';
|
|
157
|
-
const msg = `${label} module not found "${name}" in path ${firstPath}`;
|
|
158
|
-
throw new Error(msg);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
return modulePath;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
function isValidString(val) {
|
|
165
|
-
return typeof val === 'string' ? val.length > 0 : false;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
function defaults(name, opts) {
|
|
169
|
-
opts = opts && typeof opts === 'object' ? opts : {};
|
|
170
|
-
opts.cwd = typeof opts.cwd === 'string' ? opts.cwd : process.cwd();
|
|
171
|
-
|
|
172
|
-
if (opts.paths) {
|
|
173
|
-
return opts.paths.map(modulePath => path.join(modulePath, name));
|
|
174
|
-
} else if (opts.local) {
|
|
175
|
-
return [path.join(opts.cwd, 'node_modules', name)];
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
return [path.join(modules, name)];
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
export { getInstalledPath, getInstalledPathSync };
|
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @author Charlike Mike Reagent <open.source.charlike@gmail.com>
|
|
3
|
-
* @copyright 2016-present @tunnckoCore/team and contributors
|
|
4
|
-
* @license MIT
|
|
5
|
-
*/
|
|
6
|
-
'use strict';
|
|
7
|
-
|
|
8
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
9
|
-
|
|
10
|
-
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
|
11
|
-
|
|
12
|
-
var fs = _interopDefault(require('fs'));
|
|
13
|
-
var path = _interopDefault(require('path'));
|
|
14
|
-
var modules = _interopDefault(require('global-modules'));
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* > Get installed path of globally or locally `name` package.
|
|
18
|
-
* By default it checks if `name` exists as directory in [global-modules][]
|
|
19
|
-
* directory of the system. Pass `opts.local` to get path of `name`
|
|
20
|
-
* package from local directory or from `opts.cwd`. Returns rejected
|
|
21
|
-
* promise if module not found in global/local `node_modules` folder or
|
|
22
|
-
* if it exist but is not a directory.
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* const { getInstalledPath } = require('get-installed-path')
|
|
26
|
-
*
|
|
27
|
-
* getInstalledPath('npm').then((path) => {
|
|
28
|
-
* console.log(path)
|
|
29
|
-
* // => '/home/charlike/.nvm/path/to/lib/node_modules/npm'
|
|
30
|
-
* })
|
|
31
|
-
*
|
|
32
|
-
* getInstalledPath('foo-bar-barwerwlekrjw').catch((err) => {
|
|
33
|
-
* console.log(err.message)
|
|
34
|
-
* // => 'module not found "foo-bar-barwerwlekrjw" in path ...'
|
|
35
|
-
* })
|
|
36
|
-
*
|
|
37
|
-
* getInstalledPath('npm', {
|
|
38
|
-
* local: true
|
|
39
|
-
* }).catch((err) => {
|
|
40
|
-
* console.log(err.message)
|
|
41
|
-
* // => 'module not found "foo-bar-barwerwlekrjw" in path ...'
|
|
42
|
-
* })
|
|
43
|
-
*
|
|
44
|
-
* getInstalledPath('global-modules', {
|
|
45
|
-
* local: true
|
|
46
|
-
* }).then((path) => {
|
|
47
|
-
* console.log(path)
|
|
48
|
-
* // => '~/code/get-installed-path/node_modules/global-modules'
|
|
49
|
-
* })
|
|
50
|
-
*
|
|
51
|
-
* // If you are using it for some sub-directory
|
|
52
|
-
* // pass `opts.cwd` to be where the `node_modules`
|
|
53
|
-
* // folder is.
|
|
54
|
-
* process.chidr('foo-bar-baz')
|
|
55
|
-
* getInstalledPath('global-modules', {
|
|
56
|
-
* local: true,
|
|
57
|
-
* cwd: '../'
|
|
58
|
-
* }).then((path) => {
|
|
59
|
-
* console.log(path)
|
|
60
|
-
* // => '~/code/get-installed-path/node_modules/global-modules'
|
|
61
|
-
* })
|
|
62
|
-
*
|
|
63
|
-
* // When searching for the path of a package that is required
|
|
64
|
-
* // by several other packages, its path may not be in the
|
|
65
|
-
* // closest node_modules. In this case, to search recursively,
|
|
66
|
-
* // you can use the following:
|
|
67
|
-
* getInstalledPath('npm', {
|
|
68
|
-
* paths: process.mainModule.paths
|
|
69
|
-
* }).then((path) => {
|
|
70
|
-
* // ...
|
|
71
|
-
* })
|
|
72
|
-
* // `process.mainModule` refers to the location of the current
|
|
73
|
-
* // entry script.
|
|
74
|
-
*
|
|
75
|
-
* @param {string} name package name
|
|
76
|
-
* @param {Object} opts pass `opts.local` to check locally
|
|
77
|
-
* @return {Promise} rejected promise if `name` not a string or is empty string
|
|
78
|
-
* @name getInstalledPath
|
|
79
|
-
* @public
|
|
80
|
-
*/
|
|
81
|
-
|
|
82
|
-
function getInstalledPath(name, opts) {
|
|
83
|
-
return new Promise((resolve, reject) => {
|
|
84
|
-
if (!isValidString(name)) {
|
|
85
|
-
const message = 'get-installed-path: expect `name` to be string';
|
|
86
|
-
return reject(new TypeError(message));
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const targetPaths = defaults(name, opts);
|
|
90
|
-
|
|
91
|
-
const statPath = filepath => fs.stat(filepath, (e, stats) => {
|
|
92
|
-
if (e && targetPaths.length > 0) {
|
|
93
|
-
statPath(targetPaths.shift());
|
|
94
|
-
return;
|
|
95
|
-
} else if (e) {
|
|
96
|
-
const label = 'get-installed-path:';
|
|
97
|
-
const msg = `${label} module not found "${name}" in path ${filepath}`;
|
|
98
|
-
return reject(new Error(msg));
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if (stats.isDirectory()) {
|
|
102
|
-
return resolve(filepath);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const msg = `Possibly "${name}" is not a directory: ${filepath}`;
|
|
106
|
-
let err = new Error('get-installed-path: some error occured! ' + msg);
|
|
107
|
-
reject(err);
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
statPath(targetPaths.shift());
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* > Get installed path of a `name` package synchronous.
|
|
115
|
-
* Returns `boolean` when `paths` option is used and filepath is directory,
|
|
116
|
-
* otherwise returns a full filepath OR throws error.
|
|
117
|
-
*
|
|
118
|
-
* @example
|
|
119
|
-
* const { getInstalledPathSync } = require('get-installed-path')
|
|
120
|
-
*
|
|
121
|
-
* const npmPath = getInstalledPathSync('npm')
|
|
122
|
-
* console.log(npmPath)
|
|
123
|
-
* // => '/home/charlike/.nvm/path/to/lib/node_modules/npm'
|
|
124
|
-
*
|
|
125
|
-
* const gmPath = getInstalledPathSync('global-modules', { local: true })
|
|
126
|
-
* console.log(gmPath)
|
|
127
|
-
* // => '~/code/get-installed-path/node_modules/global-modules'
|
|
128
|
-
*
|
|
129
|
-
* @param {string} name package name
|
|
130
|
-
* @param {Object} opts pass `opts.local` to check locally
|
|
131
|
-
* @return {string} The full filepath or throw `TypeError` if `name` not a string or is empty string
|
|
132
|
-
* @name getInstalledPathSync
|
|
133
|
-
* @public
|
|
134
|
-
*/
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
function getInstalledPathSync(name, opts) {
|
|
138
|
-
if (!isValidString(name)) {
|
|
139
|
-
throw new TypeError('get-installed-path: expect `name` to be string');
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
const filePaths = defaults(name, opts);
|
|
143
|
-
const firstPath = filePaths[0];
|
|
144
|
-
const modulePath = filePaths.find(filePath => {
|
|
145
|
-
let stat = null;
|
|
146
|
-
|
|
147
|
-
try {
|
|
148
|
-
stat = fs.statSync(filePath);
|
|
149
|
-
} catch (e) {
|
|
150
|
-
return false;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
if (stat.isDirectory()) {
|
|
154
|
-
return true;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
const msg = `Possibly "${name}" is not a directory: ${filePath}`;
|
|
158
|
-
throw new Error('get-installed-path: some error occured! ' + msg);
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
if (!modulePath) {
|
|
162
|
-
const label = 'get-installed-path:';
|
|
163
|
-
const msg = `${label} module not found "${name}" in path ${firstPath}`;
|
|
164
|
-
throw new Error(msg);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
return modulePath;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
function isValidString(val) {
|
|
171
|
-
return typeof val === 'string' ? val.length > 0 : false;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
function defaults(name, opts) {
|
|
175
|
-
opts = opts && typeof opts === 'object' ? opts : {};
|
|
176
|
-
opts.cwd = typeof opts.cwd === 'string' ? opts.cwd : process.cwd();
|
|
177
|
-
|
|
178
|
-
if (opts.paths) {
|
|
179
|
-
return opts.paths.map(modulePath => path.join(modulePath, name));
|
|
180
|
-
} else if (opts.local) {
|
|
181
|
-
return [path.join(opts.cwd, 'node_modules', name)];
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
return [path.join(modules, name)];
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
exports.getInstalledPath = getInstalledPath;
|
|
188
|
-
exports.getInstalledPathSync = getInstalledPathSync;
|