inxilpro / node-app-root-path

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

Fix for usage with Electron renderer processes #10

Closed davej closed 8 years ago

davej commented 8 years ago

I'm not sure if this would be considered in-scope of the project but I added a conditional so that it works consistently with Electron.

Before this fix, if run in the Electron 'renderer' process then it would return the path for the dir containing the HTML file it is require'd on. This is not what normally what you would want, this fix will use the app-root-path for the main process instead.

Probably not the most efficient way to implement this but it works for me.

inxilpro commented 8 years ago

Sorry for such a late reply. Can you explain the use case for needing the root path inside the renderer process?

davej commented 8 years ago

The same use cases that this module has when used in Node… referencing files/paths relative to the application root with consistent results.

inxilpro commented 8 years ago

Implemented it slightly different in 9eb0173dd138280e027fd2b5afb687bd8ed94b43 — how's that look?

inxilpro commented 8 years ago

Just published with the beta tag—can you test it with npm i -S app-root-path@beta and make sure it works (I don't do Electron, so I don't have a test in place yet).

davej commented 8 years ago

No, it doesn't work. require('app-root-path').path should be '/Users/Dave/MyApp', but instead it is:

'/Users/Dave/MyApp/Users/Dave/MyApp/node_modules/app-root-path'
inxilpro commented 8 years ago

OK, I just applied your logic, but placed it slightly differently in the resolve() function.