MCPcopy
hub / github.com/electron/forge / PluginInterface

Class PluginInterface

packages/api/core/src/util/plugin-interface.ts:28–211  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26}
27
28export default class PluginInterface implements IForgePluginInterface {
29 private plugins: IForgePlugin[] = [];
30 private _pluginPromise: Promise<void> = Promise.resolve();
31
32 private config: ResolvedForgeConfig;
33
34 static async create(
35 dir: string,
36 forgeConfig: ResolvedForgeConfig,
37 ): Promise<PluginInterface> {
38 const int = new PluginInterface(dir, forgeConfig);
39 await int._pluginPromise;
40 return int;
41 }
42
43 private constructor(dir: string, forgeConfig: ResolvedForgeConfig) {
44 this._pluginPromise = Promise.all(
45 forgeConfig.plugins.map(async (plugin): Promise<IForgePlugin> => {
46 if (isForgePlugin(plugin)) {
47 return plugin;
48 }
49
50 if (
51 typeof plugin === 'object' &&
52 'name' in plugin &&
53 'config' in plugin
54 ) {
55 const { name: pluginName, config: opts } = plugin;
56 if (typeof pluginName !== 'string') {
57 throw new Error(
58 `Expected plugin[0] to be a string but found ${pluginName}`,
59 );
60 }
61 // eslint-disable-next-line @typescript-eslint/no-explicit-any
62 const Plugin = await importSearch<any>(dir, [pluginName]);
63 if (!Plugin) {
64 throw new Error(
65 `Could not find module with name: ${pluginName}. Make sure it's listed in the devDependencies of your package.json`,
66 );
67 }
68 return new Plugin(opts);
69 }
70
71 throw new Error(
72 `Expected plugin to either be a plugin instance or a { name, config } object but found ${JSON.stringify(plugin)}`,
73 );
74 }),
75 ).then((plugins) => {
76 this.plugins = plugins;
77 for (const plugin of this.plugins) {
78 plugin.init(dir, forgeConfig);
79 }
80 return;
81 });
82 // TODO: fix hack
83 // eslint-disable-next-line @typescript-eslint/no-explicit-any
84 this.config = null as any;
85 Object.defineProperty(this, 'config', {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected