From 7cfad02ae537995b0018698648877e1d402b41ba Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Sun, 28 Aug 2022 00:26:24 -0400 Subject: [PATCH] *remove globby and just use fs/path --- src/plugin.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/plugin.ts b/src/plugin.ts index 62fceab..a19418b 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -2,10 +2,10 @@ import config from "./config.js"; import { getRpcServer } from "./rpc/server.js"; import { PluginAPI, RPCMethod, Plugin } from "./types.js"; import slugify from "slugify"; -import { dynImport } from "./util"; +import * as fs from "fs"; +import path from "path"; let pluginApi: PluginApiManager; -let globby: typeof import("globby").globby; const sanitizeName = (name: string) => slugify(name, { lower: true, strict: true }); @@ -20,9 +20,14 @@ export class PluginApiManager { return this.registeredPlugins.get(moduleName) as Plugin; } - const paths = await globby([`${moduleName}.js`, "${moduleName}.mjs"], { - cwd: config.get("plugin-folder"), - }); + const paths = []; + for (const modulePath of [`${moduleName}.js`, `${moduleName}.mjs`]) { + const fullPath = path.join(config.get("plugin-folder"), modulePath); + if (fs.existsSync(fullPath)) { + paths.push(fullPath); + break; + } + } if (!paths.length) { throw new Error(`Plugin ${moduleName} does not exist`); @@ -69,7 +74,6 @@ export function getPluginAPI(): PluginApiManager { } export async function loadPlugins() { - globby = ((await dynImport("globby")) as typeof import("globby")).globby; for (const plugin of config.array("plugins")) { await getPluginAPI().loadPlugin(plugin); }