Aller au contenu

Dependencies between plugins

A plugin can declare that it needs other plugins to be active first:

export default {
id: "notes-sync",
name: "Notes sync",
dependsOn: ["notes"],
setup(ctx) {
const notes = ctx.useApi("notes");
if (!notes) {
// The dependency is missing or disabled.
return;
}
notes.onDocumentSaved((doc) => {
// react to the dependency's API
});
},
};

Rules:

  • dependsOn is a list of plugin ids.

  • ctx.useApi(id) only works for ids listed in dependsOn. It returns undefined when the dependency is missing, disabled or exposes no API.

  • A plugin exposes an API with ctx.provideApi(api) during setup. Returning the API from setup() does the same thing.

  • Typing: ids listed in the PluginApis interface of plugin-api are typed without generics (ctx.useApi("documents") returns DocumentsApi). A plugin publishing its own API adds itself by module augmentation, in a type-only api.ts that consumers include:

    declare module "@app/kernel/plugin-api" {
    interface PluginApis { "my-plugin": MyApi }
    }

    ctx.useApi<T>("other-id") still works for untyped ids.

  • If a dependency is installed but disabled, the Plugins panel offers to enable it. If it is not installed, you must install it first.

  • Disabling or removing a plugin disables all active plugins that depend on it, directly or transitively.

Documentation sous licence CC BY 4.0 · © les contributeurs de SCFlow ·Retour à supplychainflow.org