Extendable packages


I want to make a package which you can add other packages to. Say you install the base package and then two sub packages, what is the best method to implement this?

Maybe I want to run a function with every sub package that is installed or something. Is there a good way of doing this?

I’m thinking the base package would declare Base = {}; Base.plugins = {}; and then the sub package could just latch on to that with Base.plugins.plugin = {}; or something but I’m not sure it’s the best way to do it

That’s basically what I’ve done with tunguska:gauge and an optional theme pack.

The theme pack has a requirement on the base package. In the package.js:

api.use('tunguska:gauge@1.0.0', 'client');

So, if the theme pack is added on its own, it also loads the base package. However, adding the base package on its own does not force the theme pack to load.

The base code contains an initial TunguskaGauge.themes, which is extended by the theme pack if installed.