EvolveLabs / electron-plugins

Plugin loader for electron applications.
MIT License
58 stars 11 forks source link

loding plugins must be always at root level #3

Closed alvarolorentedev closed 8 years ago

alvarolorentedev commented 8 years ago

If the loading file (index.js) is not at the same level than the package.json, you get the next error:

{ [Error: ENOENT: no such file or directory, open '/home/knek/code/koteky/src/package.json']
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '/home/knek/code/koteky/src/package.json' }
justinmchase commented 8 years ago

Actually it looks like the package.json file is what is missing. Can you confirm that your package.json is actually inside of the pakcage that's uploaded to npm?

What is the name of the plugin?

alvarolorentedev commented 8 years ago

i am working on it in my developer enviroment so is not on npm yet, could this be an issue?. The behaviour is:

image

image

Please find the code taged here

If I add a second package.json containing only name and plugins, it will actually overcome the issue. but I dont know if this is the expected bahaviour,

justinmchase commented 8 years ago

I see what you're saying. Yeah this line: https://github.com/EvolveLabs/electron-plugins/blob/master/index.js#L69

It will use the dir of the root module of the current process, I would have thought that would always be the same level as the app root but I haven't really tried it.

I guess what I would recommend is putting index.html, index.js and main.js all in the root directory. I would also recommend renaming src to lib. By convention src is reserved for native code for nodejs modules.

Also, if you know of a fix for this issue I'd be happy to accept it. The trick is finding out where the root directory of the main app is.

I suppose it should be using this api instead really:

app.getAppPath()
alvarolorentedev commented 8 years ago

thanks for the answer, actually that is what i have end up doing. Probably it will be a nice to have till anyone can work on this, on the readme.md have a section similar to the one in the electron-updater to have a reference to this small threads that relates to behaviours.

My personal opinion is that it should be recursively go backwards from the current directory to the app directory. I will explain myself, imagine the next project structure:

+root
    package.json
    +lib
        +controls
               package.json      
        +themes
               package.json      
        +data
               package.json      

I can see the power of handling at a certain directory level. You could handle quite different type of plugins without actually have to test them. Does this make sense?. But again I will defend the recursive case because if you have only one type of plugins, most probably you want to consolidate having just a package.json.

I will definetly give a deeper look on the code soon, and if i find a good solution I will do a pull request.

PS. thanks the tips, i have been working in a few diferent languages and i still need to get used to the conventions for javascript.