Hi.
I'm not sure, this solution can be used to build a real plugin base system.
If a plugin doesn't have dependencies or have dependencies, which doesn't require any extra installation actions it will work. But, if the plugin has "complicated" dependency, which requires some extra installation actions, it will not.
You can try to create a plugin, which has as a dependency for example "node-pty". The thing is - node-pty does some extra installation actions. And npm can do it within some environment.
If you run electron application via terminal (something like "electron myapp.js" it could work, because in this case electron will use your environment.
But, if you will build an electron application and run it as a desktop application, the installation will be failed. Because your application will not use your environment anymore. For example, the variable PATH will not have your regular PATHs. As a result, during installation of node-pty will be an error, because npm/node cannot find python, which is needed to install node-pty.
So, to resolve this problem you should add PATH before call npm installation. But does it make sense? What if user of your application doesn't have on a board python? But to use and install plugin he has to install python?
Also not clear how you resolve an issue with necessary to rebuild some modules (https://electronjs.org/docs/tutorial/using-native-node-modules). Not sure, will be enough just install it plugin.
Also, this is not good idea to use programmatically npm. It doesn't looks like developers care about this way of usage. There are tons of documentation about CLI, but nothing about API.
So, definitely would be nice if you will provide more information about the usage of your solution.