Dependencies between plugins
Dependencies between plugins
Section intitulée « 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:
-
dependsOnis a list of plugin ids. -
ctx.useApi(id)only works for ids listed independsOn. It returnsundefinedwhen the dependency is missing, disabled or exposes no API. -
A plugin exposes an API with
ctx.provideApi(api)duringsetup. Returning the API fromsetup()does the same thing. -
Typing: ids listed in the
PluginApisinterface ofplugin-apiare typed without generics (ctx.useApi("documents")returnsDocumentsApi). A plugin publishing its own API adds itself by module augmentation, in a type-onlyapi.tsthat 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