inxilpro / node-app-root-path

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

fix: #28 #36

Open seognil opened 5 years ago

seognil commented 5 years ago

I meet the bug for my tool la-starter-cli

It seems the same as #28

the bug

In my case,
app-root-path parse my tool's appRoot as /usr/local/lib/ on Mac

So I got /usr/local/lib/package.json not found in my code

It should be /usr/local/lib/node_modules/@seognil-lab/la-starter-cli/ instead

(install and run my tool lcli -v) (the bug should appear after reopen my code line 7 & 8 and comment line 10)

the fix

I trace the code, it happens while there are multi node_modules in the path string

e.g. /usr/local/lib/node_modules/@seognil-lab/la-starter-cli/node_modules/app-root-path/lib

I update the code, and test manually passed for both mac and window

It may fix #28 (Maybe #20 as well, not checked that too much)

remaining

But I'm not sure the origin logic,
And I know app-root-path is used by tons of libs So I also keep it as comment code,

Please check it Thanks ~

(UPDATE) I notice that CI failed, so maybe we could seperate the use-case somehow?

inxilpro commented 4 years ago

Is this still an issue with 3.0.0?

seognil commented 4 years ago

@inxilpro hi there~
I just tested the v3.0.0, yes it seems still an issue…

notice the case /usr/local/lib/node_modules/@seognil-lab/la-starter-cli/node_modules/app-root-path/lib
there are two node_modules, and the second one is target

seems to need a better way to decide, maybe could use some node.js runtime flag such as __dirname 🤔?