@axium/server 0.7.1 → 0.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/plugins.js +7 -7
- package/package.json +1 -1
package/dist/plugins.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as fs from 'node:fs';
|
|
2
|
-
import { join } from 'node:path/posix';
|
|
2
|
+
import { join, resolve } from 'node:path/posix';
|
|
3
3
|
import { styleText } from 'node:util';
|
|
4
4
|
import * as z from 'zod';
|
|
5
5
|
import { fromZodError } from 'zod-validation-error';
|
|
@@ -40,10 +40,6 @@ export function pluginText(plugin) {
|
|
|
40
40
|
].join('\n');
|
|
41
41
|
}
|
|
42
42
|
export async function loadPlugin(specifier) {
|
|
43
|
-
specifier = fileURLToPath(import.meta.resolve(specifier));
|
|
44
|
-
const stats = fs.statSync(specifier);
|
|
45
|
-
if (stats.isDirectory() || !['.js', '.mjs'].some(ext => specifier.endsWith(ext)))
|
|
46
|
-
return;
|
|
47
43
|
try {
|
|
48
44
|
const plugin = await Plugin.parseAsync(await import(specifier)).catch(e => {
|
|
49
45
|
throw fromZodError(e);
|
|
@@ -52,14 +48,18 @@ export async function loadPlugin(specifier) {
|
|
|
52
48
|
output.debug(`Loaded plugin: "${plugin.name}" (${plugin.id}) ${plugin.version}`);
|
|
53
49
|
}
|
|
54
50
|
catch (e) {
|
|
55
|
-
output.debug(`Failed to load plugin from ${specifier}: ${e}`);
|
|
51
|
+
output.debug(`Failed to load plugin from ${specifier}: ${e.message || e}`);
|
|
56
52
|
}
|
|
57
53
|
}
|
|
58
54
|
export async function loadPlugins(dir) {
|
|
59
55
|
fs.mkdirSync(dir, { recursive: true });
|
|
60
56
|
const files = fs.readdirSync(dir);
|
|
61
57
|
for (const file of files) {
|
|
62
|
-
|
|
58
|
+
const path = resolve(dir, file);
|
|
59
|
+
const stats = fs.statSync(path);
|
|
60
|
+
if (stats.isDirectory() || !['.js', '.mjs'].some(ext => path.endsWith(ext)))
|
|
61
|
+
return;
|
|
62
|
+
await loadPlugin(path);
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
export async function loadDefaultPlugins() {
|