0
Fork 0
mirror of https://github.com/penpot/penpot-plugins.git synced 2025-01-04 13:50:13 -05:00

feat(runtime): unload plugin

This commit is contained in:
Juanfran 2024-10-09 09:14:06 +02:00
parent 13ea206eab
commit b4d0463548
5 changed files with 13 additions and 0 deletions

View file

@ -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);
}

View file

@ -87,6 +87,7 @@ describe('createPlugin', () => {
expect(result).toEqual({
plugin: mockPluginManager,
compartment: mockSandbox,
manifest,
});
});

View file

@ -36,6 +36,7 @@ export async function createPlugin(
return {
plugin,
manifest,
compartment: sandbox,
};
}

View file

@ -4,5 +4,6 @@ export declare global {
declare namespace globalThis {
function ɵloadPlugin(cofig: Manifest): Promise<void>;
function ɵloadPluginByUrl(url: string): Promise<void>;
function ɵunloadPlugin(id: Manifest['pluginId']): void;
}
}

View file

@ -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();
}
};