From ce23f0a7b8686428581435321425ad92e003ac0b Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Sat, 7 Jan 2023 23:02:13 -0500 Subject: [PATCH] *Refactor how core plugins are loaded --- src/modules/plugin.ts | 10 ++++------ src/plugins/index.ts | 7 +++++++ 2 files changed, 11 insertions(+), 6 deletions(-) create mode 100644 src/plugins/index.ts diff --git a/src/modules/plugin.ts b/src/modules/plugin.ts index 26edcd1..1177589 100644 --- a/src/modules/plugin.ts +++ b/src/modules/plugin.ts @@ -8,9 +8,6 @@ import path from "path"; import type { Logger } from "pino"; import { getHDKey, getSeed } from "../lib/seed.js"; -import pluginRpc from "../plugins/rpc"; -import pluginCore from "../plugins/core"; -import pluginDht from "../plugins/dht"; import type Config from "@lumeweb/cfg"; import EventEmitter2 from "eventemitter2"; import log from "../log.js"; @@ -21,6 +18,7 @@ import { } from "./swarm.js"; import { get as getSSl, SSLManager } from "./ssl.js"; import type { HDKey } from "micro-ed25519-hdkey"; +import corePlugins from "../plugins"; let pluginAPIManager: PluginAPIManager; let pluginAPI: PluginAPI; @@ -228,9 +226,9 @@ export function getPluginAPIManager(): PluginAPIManager { export async function loadPlugins() { const apiManager = getPluginAPIManager(); - apiManager.loadPluginInstance(pluginCore); - apiManager.loadPluginInstance(pluginRpc); - apiManager.loadPluginInstance(pluginDht); + for (const plugin of corePlugins) { + await apiManager.loadPluginInstance(plugin); + } for (const plugin of [...new Set(config.array("plugins", []))] as []) { await apiManager.loadPlugin(plugin); diff --git a/src/plugins/index.ts b/src/plugins/index.ts new file mode 100644 index 0000000..b1a1c0a --- /dev/null +++ b/src/plugins/index.ts @@ -0,0 +1,7 @@ +import core from "./core"; +import rpc from "./rpc"; +import dht from "./dht"; + +const corePlugins = [core, dht, rpc]; + +export default corePlugins;