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:
parent
13ea206eab
commit
b4d0463548
5 changed files with 13 additions and 0 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -87,6 +87,7 @@ describe('createPlugin', () => {
|
|||
expect(result).toEqual({
|
||||
plugin: mockPluginManager,
|
||||
compartment: mockSandbox,
|
||||
manifest,
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@ export async function createPlugin(
|
|||
|
||||
return {
|
||||
plugin,
|
||||
manifest,
|
||||
compartment: sandbox,
|
||||
};
|
||||
}
|
||||
|
|
1
libs/plugins-runtime/src/lib/global.d.ts
vendored
1
libs/plugins-runtime/src/lib/global.d.ts
vendored
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue