*remove globby and just use fs/path
This commit is contained in:
parent
b9bb588a35
commit
7cfad02ae5
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue