mirror of
https://github.com/penpot/penpot-plugins.git
synced 2025-01-21 06:02:34 -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,
|
ɵloadPlugin,
|
||||||
setContextBuilder,
|
setContextBuilder,
|
||||||
ɵloadPluginByUrl,
|
ɵloadPluginByUrl,
|
||||||
|
ɵunloadPlugin,
|
||||||
} from './lib/load-plugin.js';
|
} from './lib/load-plugin.js';
|
||||||
|
|
||||||
import type { Context } from '@penpot/plugin-types';
|
import type { Context } from '@penpot/plugin-types';
|
||||||
|
@ -30,6 +31,7 @@ globalThisAny$.initPluginsRuntime = (
|
||||||
globalThisAny$.ɵcontext = contextBuilder('TEST');
|
globalThisAny$.ɵcontext = contextBuilder('TEST');
|
||||||
globalThis.ɵloadPlugin = ɵloadPlugin;
|
globalThis.ɵloadPlugin = ɵloadPlugin;
|
||||||
globalThis.ɵloadPluginByUrl = ɵloadPluginByUrl;
|
globalThis.ɵloadPluginByUrl = ɵloadPluginByUrl;
|
||||||
|
globalThis.ɵunloadPlugin = ɵunloadPlugin;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,6 +87,7 @@ describe('createPlugin', () => {
|
||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
plugin: mockPluginManager,
|
plugin: mockPluginManager,
|
||||||
compartment: mockSandbox,
|
compartment: mockSandbox,
|
||||||
|
manifest,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,7 @@ export async function createPlugin(
|
||||||
|
|
||||||
return {
|
return {
|
||||||
plugin,
|
plugin,
|
||||||
|
manifest,
|
||||||
compartment: sandbox,
|
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 {
|
declare namespace globalThis {
|
||||||
function ɵloadPlugin(cofig: Manifest): Promise<void>;
|
function ɵloadPlugin(cofig: Manifest): Promise<void>;
|
||||||
function ɵloadPluginByUrl(url: string): 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);
|
const manifest = await loadManifest(manifestUrl);
|
||||||
ɵloadPlugin(manifest);
|
ɵloadPlugin(manifest);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const ɵunloadPlugin = function (id: Manifest['pluginId']) {
|
||||||
|
const plugin = plugins.find((plugin) => plugin.manifest.pluginId === id);
|
||||||
|
|
||||||
|
if (plugin) {
|
||||||
|
plugin.plugin.close();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue