Skip to content

Commit

Permalink
feat(runtime): unload plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
juanfran committed Oct 9, 2024
1 parent 13ea206 commit b4d0463
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions libs/plugins-runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
ɵloadPlugin,
setContextBuilder,
ɵloadPluginByUrl,
ɵunloadPlugin,
} from './lib/load-plugin.js';

import type { Context } from '@penpot/plugin-types';
Expand All @@ -30,6 +31,7 @@ globalThisAny$.initPluginsRuntime = (
globalThisAny$.ɵcontext = contextBuilder('TEST');
globalThis.ɵloadPlugin = ɵloadPlugin;
globalThis.ɵloadPluginByUrl = ɵloadPluginByUrl;
globalThis.ɵunloadPlugin = ɵunloadPlugin;
} catch (err) {
console.error(err);
}
Expand Down
1 change: 1 addition & 0 deletions libs/plugins-runtime/src/lib/create-plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ describe('createPlugin', () => {
expect(result).toEqual({
plugin: mockPluginManager,
compartment: mockSandbox,
manifest,
});
});

Expand Down
1 change: 1 addition & 0 deletions libs/plugins-runtime/src/lib/create-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export async function createPlugin(

return {
plugin,
manifest,
compartment: sandbox,
};
}
1 change: 1 addition & 0 deletions libs/plugins-runtime/src/lib/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
8 changes: 8 additions & 0 deletions libs/plugins-runtime/src/lib/load-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
};

0 comments on commit b4d0463

Please sign in to comment.