davideicardi / live-plugin-manager

Plugin manager and installer for Node.JS
MIT License
225 stars 43 forks source link

Are there any reasons for PluginManager not installing plugin dependencies #37

Closed g5becks closed 3 years ago

g5becks commented 3 years ago

Hi, thanks for the great lib.

I am having a problem that I cant seem to find an answer to. I am using this library in a cli program that I am building. So I wrapped the PluginManager class and made a library in my monorepo. Here is the npm package.

The strange thing is that I can use the library in one script, and it will download the plugin's npm package and all of it's dependencies to pluginsPath, and I when I use the same library from my cli program it only downloads the plugin and none of the dependencies.

This is some pretty weird behavior that I have spent the past 2 days debugging with no luck at all. I was hoping that maybe you could shed some light on why this issue may be occurring.

Thanks.

davideicardi commented 3 years ago

Which is the package that cause problems? Or this happened for all packages when using your library?

davideicardi commented 3 years ago

Maybe you can send ne the logs by calling your app wih DEBUG=* environment variable.

g5becks commented 3 years ago

It only has issues when being run from my cli program. I import it in another test program and it works fine.

I figured out what the issue is though. PluginManager is saying the dependencies for plugins are already available on the host. The way I am using live-plugin-manager is by reading a config file that lists plugins to install. A plugin will be a lib from my monorepo, which in turn depends on the same dependencies as my cli does. So it's always going to say the plugin is already available.

It looks like staticDependencies will solve this issue if I am not mistaken.

I will give that a try and report back.

davideicardi commented 3 years ago

If the dependency is already available on the host I think you should not do nothing. I mean they are not installed but they are available automatically. staticDependencies are dependencies that you want to "hack" so that the host can pass something special to the plugin.

If you don't do nothing it works at runtime? Or you have some missing dependency error?

Also consider to use hostRequire=undefined as an option to disable any transitive dependency from host to plugin.

g5becks commented 3 years ago

The thing is, I don't know where the cli will be installed. It could be local to a project that is running it, and the project that needs the dependency in another project. I may be mistaken, but I don't think the node module resolver would be able to find it that way.

g5becks commented 3 years ago

I never knew about hostRequire=undefined option. If you have a sec. Can you link me to some docs on that?

Thanks a lot for your help btw.

davideicardi commented 3 years ago

No doc for now, sorry ... but here the relevant code:

g5becks commented 3 years ago

great. I'll check it out.

Thanks again for the assistance.