*remove globby and just use fs/path

This commit is contained in:
Derrick Hammer 2022-08-28 00:26:24 -04:00
parent b9bb588a35
commit 7cfad02ae5
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 10 additions and 6 deletions

View File

@ -2,10 +2,10 @@ import config from "./config.js";
import { getRpcServer } from "./rpc/server.js"; import { getRpcServer } from "./rpc/server.js";
import { PluginAPI, RPCMethod, Plugin } from "./types.js"; import { PluginAPI, RPCMethod, Plugin } from "./types.js";
import slugify from "slugify"; import slugify from "slugify";
import { dynImport } from "./util"; import * as fs from "fs";
import path from "path";
let pluginApi: PluginApiManager; let pluginApi: PluginApiManager;
let globby: typeof import("globby").globby;
const sanitizeName = (name: string) => const sanitizeName = (name: string) =>
slugify(name, { lower: true, strict: true }); slugify(name, { lower: true, strict: true });
@ -20,9 +20,14 @@ export class PluginApiManager {
return this.registeredPlugins.get(moduleName) as Plugin; return this.registeredPlugins.get(moduleName) as Plugin;
} }
const paths = await globby([`${moduleName}.js`, "${moduleName}.mjs"], { const paths = [];
cwd: config.get("plugin-folder"), 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) { if (!paths.length) {
throw new Error(`Plugin ${moduleName} does not exist`); throw new Error(`Plugin ${moduleName} does not exist`);
@ -69,7 +74,6 @@ export function getPluginAPI(): PluginApiManager {
} }
export async function loadPlugins() { export async function loadPlugins() {
globby = ((await dynImport("globby")) as typeof import("globby")).globby;
for (const plugin of config.array("plugins")) { for (const plugin of config.array("plugins")) {
await getPluginAPI().loadPlugin(plugin); await getPluginAPI().loadPlugin(plugin);
} }