GithubHelp home page GithubHelp logo

tunnckocore / get-installed-path Goto Github PK

View Code? Open in Web Editor NEW
42.0 4.0 11.0 1.03 MB

Get locally or globally installation path of given package name.

Home Page: https://tunnckocore.com

License: MIT License

JavaScript 100.00%
npm detect install is-installed path package modules

get-installed-path's Introduction

get-installed-path npm version github release mit License NPM Downloads Total

Get installation path where the given package is installed. Works for globally and locally installed packages

You might also be interested in detect-installed.

Quality Assurance 💯

Code Climate Code Style Standard Linux Build Code Coverage Dependencies Status Renovate App Status Node Version Required

If you have any how-to kind of questions, please read Code of Conduct and join the chat room or open an issue.
You may also read the Contributing Guide. There, beside "How to contribute?", we describe everything stated by the badges.

tunnckoCore support Code Format Prettier Node Security Status Conventional Commits Semantic Release First Timers Only

All Contributors Spec Make A Pull Request Newsletter Subscribe PayPal Author Support Share Love BitHound Code

Table of Contents

(TOC generated by verb using markdown-toc)

Install

This project requires Node.js v6 and above. Use yarn v1 / npm v5 or above to install it.

$ yarn add get-installed-path

API

Review carefully the provided examples and the working tests.

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

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.

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

const { getInstalledPathSync } = require('get-installed-path')

const npmPath = getInstalledPathSync('npm')
console.log(npmPath)
// => '/home/charlike/.nvm/path/to/lib/node_modules/npm'

const gmPath = getInstalledPathSync('global-modules', { local: true })
console.log(gmPath)
// => '~/code/get-installed-path/node_modules/global-modules'

back to top

Related

back to top

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Please read the Contributing Guide and Code of Conduct documents for advices.

Author

License

Copyright © 2016-2017, Charlike Mike Reagent. Released under the MIT License.


This file was generated by verb-generate-readme, v0.6.0, on October 12, 2017.
Project scaffolded and managed with hela.

get-installed-path's People

Contributors

perry-mitchell avatar renovate-bot avatar renovate[bot] avatar tunnckocore avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

get-installed-path's Issues

Support environment variables in .npmrc's "prefix" setting

I traced the strange behavior of resolve-package to a problem in this package:

My node code:

console.log(require.resolve("lodash"));
require("get-installed-path").getInstalledPath("lodash").then(null, console.log);

Output:

/mnt/…/nodejs/modules/lodash/lodash.js
Error: get-installed-path: module not found "lodash" in path /home/mk/${HOME}/lib/node_modules/lodash
    at fs.stat (/mnt/basecamp/app-res/nodejs/modules/get-installed-path/dist/index.js:98:23)
    at FSReqWrap.oncomplete (fs.js:152:21)

When I change the prefix setting in my .npmrc from ${HOME} to ${HOME}/foobar and copy my ~/.node_modules symlink there, the error message adapts to
Error: get-installed-path: module not found "lodash" in path /home/mk/${HOME}/foobar/lib/node_modules/lodash

I wonder though, where does the /home/mk come from if the ${HOME} wasn't replaced?

Fails to get the installed paths for dependencies in a yarn monorepo

Support plan

  • which support plan is this issue covered by? Community
  • is this issue currently blocking your project? yes
  • is this issue affecting a production system? no

Context

  • node version: v14.18.2
  • module version: v4.0.8
  • environment (e.g. node, browser, native): node
  • used with (i.e. popular names of modules): serverless
  • any other relevant information: This is being executed in a child module of a Yarn monorep

What are you trying to achieve or the steps to reproduce?

In a child module with a dependency on lodash installed

const lodashPath = getInstalledPathSync('lodash')
console.log(lodashPath)

What was the result you got?

Error: get-installed-path: module not found "lodash" in path <path to monorepo root>/<child module name>/node_modules/lodash

What result did you expect?

<path to monorepo root>/node_modules/lodash

Weekly Digest (3 March, 2019 - 10 March, 2019)

Here's the Weekly Digest for tunnckoCoreLabs/get-installed-path:


ISSUES

Last week, no issues were created.


PULL REQUESTS

Last week, no pull requests were created, updated or merged.


COMMITS

Last week there were no commits.


CONTRIBUTORS

Last week there were no contributors.


STARGAZERS

Last week there were no stargazers.


RELEASES

Last week there were no releases.


That's all for last week, please 👀 Watch and Star the repository tunnckoCoreLabs/get-installed-path to receive next weekly updates. 😃

You can also view all Weekly Digests by clicking here.

Your Weekly Digest bot. 📆

Weekly Digest (17 February, 2019 - 24 February, 2019)

Here's the Weekly Digest for tunnckoCoreLabs/get-installed-path:


ISSUES

Last week, no issues were created.


PULL REQUESTS

Last week, no pull requests were created, updated or merged.


COMMITS

Last week there were no commits.


CONTRIBUTORS

Last week there were no contributors.


STARGAZERS

Last week there was 1 stargazer.
shinauri
You are the star! 🌟


RELEASES

Last week there were no releases.


That's all for last week, please 👀 Watch and Star the repository tunnckoCoreLabs/get-installed-path to receive next weekly updates. 😃

You can also view all Weekly Digests by clicking here.

Your Weekly Digest bot. 📆

Weekly Digest (24 February, 2019 - 3 March, 2019)

Here's the Weekly Digest for tunnckoCoreLabs/get-installed-path:


ISSUES

Last week, no issues were created.


PULL REQUESTS

Last week, no pull requests were created, updated or merged.


COMMITS

Last week there were no commits.


CONTRIBUTORS

Last week there were no contributors.


STARGAZERS

Last week there were no stargazers.


RELEASES

Last week there were no releases.


That's all for last week, please 👀 Watch and Star the repository tunnckoCoreLabs/get-installed-path to receive next weekly updates. 😃

You can also view all Weekly Digests by clicking here.

Your Weekly Digest bot. 📆

Fail on windows

  • node: v8.9.0
  • npm: v5.5.1
  • os: windows 7
  • nvm: 1.1.7
const { getInstalledPathSync } = require('get-installed-path')
console.log(getInstalledPathSync('npm'))
C:\Users\keenwon\Desktop\yyyyy\node_modules\get-installed-path\dist\index.js:164
    throw new Error(msg);
    ^

Error: get-installed-path: module not found "npm" in path C:\Users\keenwon\AppData\Roaming\npm\node_modules\npm
    at getInstalledPathSync (C:\Users\keenwon\Desktop\yyyyy\node_modules\get-installed-path\dist\index.js:164:11)
    at Object.<anonymous> (C:\Users\keenwon\Desktop\yyyyy\index.js:2:13)
    at Module._compile (module.js:635:30)
    at Object.Module._extensions..js (module.js:646:10)
    at Module.load (module.js:554:32)
    at tryModuleLoad (module.js:497:12)
    at Function.Module._load (module.js:489:3)
    at Function.Module.runMain (module.js:676:10)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:608:3

more info:

$ which npm
/c/Program Files/nodejs/npm

$ npm config -g get prefix
C:\Program Files\nodejs

Weekly Digest (10 February, 2019 - 17 February, 2019)

Here's the Weekly Digest for tunnckoCoreLabs/get-installed-path:


ISSUES

Last week, no issues were created.


PULL REQUESTS

Last week, no pull requests were created, updated or merged.


COMMITS

Last week there were no commits.


CONTRIBUTORS

Last week there were no contributors.


STARGAZERS

Last week there were no stargazers.


RELEASES

Last week there were no releases.


That's all for last week, please 👀 Watch and Star the repository tunnckoCoreLabs/get-installed-path to receive next weekly updates. 😃

You can also view all Weekly Digests by clicking here.

Your Weekly Digest bot. 📆

does not recurse upwards in path hierarchy

i tried this out and it is working fine when I know exactly the path of the node_modules and can specify this in cwd, but it seems to be missing the option to search through the hierarchy of paths form the cwd to find the different node_modules directories that could be used for installation. e.g. in node: the process object has a mainModule.paths which has an array of the possible install paths to search).

If this is possible already can you point me to the way to do this ?

Consider deprecating this module

We had problems with it in styleguidist/react-styleguidist#59 and realized that it has problems when it is used from a dependency B of some other module A, because then it can't find the locally-installed package C (in A/node_modules/B/node_modules/C, when installed with npm 2.x), because process.pwd() is /path/to/A.

And it seems to me that the use case of finding an installed module is better served by require.resolve(...). Correct?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.