diff --git a/libs/plugins-runtime/src/index.ts b/libs/plugins-runtime/src/index.ts index cc69c54..1e0cb8e 100644 --- a/libs/plugins-runtime/src/index.ts +++ b/libs/plugins-runtime/src/index.ts @@ -5,6 +5,7 @@ import { ɵloadPlugin, setContextBuilder, ɵloadPluginByUrl, + ɵunloadPlugin, } from './lib/load-plugin.js'; import type { Context } from '@penpot/plugin-types'; @@ -30,6 +31,7 @@ globalThisAny$.initPluginsRuntime = ( globalThisAny$.ɵcontext = contextBuilder('TEST'); globalThis.ɵloadPlugin = ɵloadPlugin; globalThis.ɵloadPluginByUrl = ɵloadPluginByUrl; + globalThis.ɵunloadPlugin = ɵunloadPlugin; } catch (err) { console.error(err); } diff --git a/libs/plugins-runtime/src/lib/create-plugin.spec.ts b/libs/plugins-runtime/src/lib/create-plugin.spec.ts index f721e7c..215aa56 100644 --- a/libs/plugins-runtime/src/lib/create-plugin.spec.ts +++ b/libs/plugins-runtime/src/lib/create-plugin.spec.ts @@ -87,6 +87,7 @@ describe('createPlugin', () => { expect(result).toEqual({ plugin: mockPluginManager, compartment: mockSandbox, + manifest, }); }); diff --git a/libs/plugins-runtime/src/lib/create-plugin.ts b/libs/plugins-runtime/src/lib/create-plugin.ts index d126066..a41044c 100644 --- a/libs/plugins-runtime/src/lib/create-plugin.ts +++ b/libs/plugins-runtime/src/lib/create-plugin.ts @@ -36,6 +36,7 @@ export async function createPlugin( return { plugin, + manifest, compartment: sandbox, }; } diff --git a/libs/plugins-runtime/src/lib/global.d.ts b/libs/plugins-runtime/src/lib/global.d.ts index e63189c..4371d65 100644 --- a/libs/plugins-runtime/src/lib/global.d.ts +++ b/libs/plugins-runtime/src/lib/global.d.ts @@ -4,5 +4,6 @@ export declare global { declare namespace globalThis { function ɵloadPlugin(cofig: Manifest): Promise; function ɵloadPluginByUrl(url: string): Promise; + function ɵunloadPlugin(id: Manifest['pluginId']): void; } } diff --git a/libs/plugins-runtime/src/lib/load-plugin.ts b/libs/plugins-runtime/src/lib/load-plugin.ts index bbeabbb..bf76842 100644 --- a/libs/plugins-runtime/src/lib/load-plugin.ts +++ b/libs/plugins-runtime/src/lib/load-plugin.ts @@ -68,3 +68,11 @@ export const ɵloadPluginByUrl = async function (manifestUrl: string) { const manifest = await loadManifest(manifestUrl); ɵloadPlugin(manifest); }; + +export const ɵunloadPlugin = function (id: Manifest['pluginId']) { + const plugin = plugins.find((plugin) => plugin.manifest.pluginId === id); + + if (plugin) { + plugin.plugin.close(); + } +};