inxilpro / node-app-root-path

Determine the root path to your project
MIT License
605 stars 29 forks source link

Incorrect root path when using with cli libraries #8

Closed olsonpm closed 8 years ago

olsonpm commented 9 years ago

Example repository which exhibits the behavior

https://github.com/olsonpm/exampleCLI

$ npm install --save -g "olsonpm/exampleCLI"
... # let it install
$ exampleCLI
# outputs
root
{ resolve: [Function],
  require: [Function],
  toString: [Function],
  setPath: [Function],
  path: '/home/<username>/.nvm/v0.10.36/lib/node_modules/exampleCLI/bin' }

root.toString()
/home/<username>/.nvm/v0.10.36/lib/node_modules/exampleCLI/bin

Now based on the readme (and without digging into your code), I couldn't tell if it should be reporting /home//.nvm/v0.10.36/lib or /home//.nvm/v0.10.36/lib/node_modules/exampleCLI

however I didn't expect it to report the bin directory

inxilpro commented 9 years ago

Hmm, this is an interesting issue. Arguably, it should return /home/<username>/.nvm/v0.10.36/lib/node_modules/exampleCLI/ without the bin/ component. The reason you're not getting /home/<username>/.nvm/v0.10.36/lib/ is because you're dealing with a node global path.

Interesting. Let me give it a bit of thought. This is another example of how many freaking edge cases there are where it's hard to say what the "root path" actually is :)

zero5100 commented 9 years ago

I am currently experiencing this issue as well. I created and installed a global npm module that has a cli command, and app-root-path reports the /bin directory as the path.

inxilpro commented 9 years ago

Hrm, seems like maybe there needs to be custom logic for bin/ (and /.bin perhaps). It seems like unless your module is called "bin" it should be fine, and this is common npm functionality…

zero5100 commented 9 years ago

Yeah...if you are naming your project "bin" you are just asking for things to break.

inxilpro commented 9 years ago

@zero5100 are you using nvm as well?

zero5100 commented 9 years ago

@inxilpro Yes, I am.

inxilpro commented 8 years ago

The latest commits should fix this. Sorry it took so long. You can try it with:

npm i -S app-root-path@beta

I'll publish as 1.1.0 shortly after a little more testing.

olsonpm commented 8 years ago

Not a problem - and thanks much!

inxilpro commented 8 years ago

Would you mind confirming that the fix works as expected?

olsonpm commented 8 years ago

I'm busy tonight but will get to it tomorrow.

inxilpro commented 8 years ago

Of course! Whenever you have time…

olsonpm commented 8 years ago

Got around to it just now - works as expected.

woot

rockymadden commented 7 years ago

Experiencing this same issue but with src where the project is a CLI whose index lives at ./src/index.js.