Plugin dependencies
This unit provides information about the Orion's implementation of the plugin dependencies. The main goal of the implementation of this pattern is to get rid of the priorities one and use a better and solid approach to manage dependencies between plugins.

Plugin Oscar consumes a method produced by plugin Mike.
spec.js
import { addPlugin, useKernels } from '@orion/core/test-utils';
import { methodsKernel } from '@orion/methods';
import Mike from './producerPlugin.js';
import Oscar from './consumerPlugin.js';
import producerPkg from './producer.json';
import consumerPkg from './consumer.json';
import { testMessage } from './testHelper.js';
test(testMessage, async () => {
useKernels(methodsKernel);
addPlugin(producerPkg, Mike);
const consumerPlugin = addPlugin(consumerPkg, Oscar);
expect(consumerPlugin.mult(4, 3)).toBe(12);
});
producerPlugin.js
export default class Mike {
constructor({ methodsHelper }) {
this._methodsHelper = methodsHelper;
this._methodsHelper.register('sum', this._sum);
this._methodsHelper.register('subs', this._subs);
this._methodsHelper.register('mult', this._mult);
}
onInit() {
console.log('I am Mike');
}
_sum = (a, b) => {
return a + b;
};
_subs = (a, b) => {
return a - b;
};
_mult = (a, b) => {
return a * b;
};
}
producerPlugin.js
export default class Oscar {
constructor({ methodsHelper }) {
this._methodsHelper = methodsHelper;
}
onInit() {
console.log('I am Oscar');
}
mult = (a, b) => this._methodsHelper.invoke('mult', a, b);
}
producer.json
{
"name": "plugin-mike",
"version": "1.0.0",
"isOn": false,
"orion": {
"methodsHelper": {
"methods": {
"produces": ["sum", "subs", "mult"]
}
}
}
}
consumer.json
{
"name": "plugin-oscar",
"version": "1.0.0",
"pluginDependencies": { "plugin-mike": "1.0.0" },
"orion": {
"methodsHelper": {
"methods": {
"consumes": { "plugin-mike": ["mult"] }
}
}
}
}
testHelper.js
export const testMessage = 'Plugin Oscar consumes a method produced by plugin Mike';
How it works
In order to have a clear picture about the plugins and the relation between them, we created a dependencies system in which you define explicitly if a plugin is dependant of another but also the functionalities you are consuming or producing by the plugin. In the other hand, we can decide if a plugin prefers to be started or even know if there is a circular dependency in their relation in order to manage a fix to avoid its related problems.
Last example scenario
Mike is using the methods package to register its functionalities. The metadata of the plugins should look like:
// Plugin 'mike'
{
name: 'plugin-mike',
version: '1.0.0',
isOn: false,
orion: {
methodsHelper: {
methods: {
produces: ['sum', 'subs', 'mult']
}
}
}
}
And Oscar is consuming one of those methods.
// Plugin 'oscar'
{
name: 'plugin-oscar',
version: '1.0.0',
pluginDependencies: { 'plugin-mike': '1.0.0' },
orion: {
methodsHelper: {
methods: {
consumes: { 'plugin-mike': ['mult'] }
}
}
}
}
So Mike is defining them on the class.
class Mike {
constructor({ methodsHelper }: PluginDIO) {
methodsHelper.register('sum', (a: number, b: number) => {
console.log(a + b);
});
methodsHelper.register('subs', (a: number, b: number) => {
console.log(a - b);
});
methodsHelper.register('mult', (a: number, b: number) => {
console.log(a * b);
});
}
}
And Oscar is invoking a Mike's functionality,
class Oscar {
private _methodsHelper: MethodsHelper;
constructor({ methodsHelper }: PluginDIO) {
this._methodsHelper = methodsHelper;
}
mult(a: number, b: number) {
return this._methodsHelper.invoke('mult', a, b);
}
}
Finally, you will be able to create a instance of plugin Oscar and use mult functionality.
const pluginOscar = new Oscar();
pluginOscar.mult(4, 4);
// logs 16