CLI and Lib package, where to put module loading code
https://softwareengineering.stackexchange.com/questions/412612
Question
My Software contains a lib
package, a cli
package and an arbitrary number of plugin packages.
The plugin packages do the algorithmic work.
The lib package basically just executes the plugins and passes the result of each plugin to the next plugin and exposes the lib
s functionality to the cli
package. The cli
package reads the configuration file and passes the configuration(which plugins to execute in which order) to the lib
package. The lib
is basically a single line of typescript code that uses the compose/pipe/flow
function from functional programming and looks like this:
export const bumpup: (plugins: Plugin[])=> BumpupData = (plugins) => flow(...plugins)();
The reason for making an extra package for a single line is
- Eventually the
lib
should be usable without thecli
by other packages - The
lib
provides the interfaces for plugins and I don't want plugin authors to depend on thecli
package to write their plugins, especially for the case where thelib
is used without thecli
The plugins are read from the configuration and are loaded dynamically at runtime from the node_modules
folder with the dynamic import from ES6.
That module loading code takes the name of the package that should be loaded and returns a function complying to the plugin interface that can be passed to the lib function.
In which package does the code for loading the modules belong and why?
What are reason for and against putting that code in one of the packages.
I have the feeling that the pattern of separating software in cli
and lib
package is very common, is there a name for that pattern so I can read more on that pattern?
La solution
Suppose you are also creating a REST API and/or a GUI for your system. Would the logic for loading plugins be different than for your current CLI?
If not, then the plugin loading logic belongs in the lib
package on the grounds of DRY (Don't Repeat Yourself). You should avoid having the same logic in multiple places in the same project.