mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +08:00
core: add resolve check before addon add
This commit is contained in:
1 parent
6a4aa14016
commit
3e918346ff
3 files changed
+21
-4
No files matched your search
@@ -111,7 +111,15 @@ if (!argv.args[0] || argv.args[0] === 'cli') {
|
||||
}
|
||||
}
|
||||
|
||||
if (operation === 'add' && name) addons.push(name);
|
||||
if (operation === 'add' && name) {
|
||||
try {
|
||||
require.resolve(`${name}/package.json`);
|
||||
} catch (e) {
|
||||
console.error(`Addon not found or not available: ${name}`);
|
||||
return;
|
||||
}
|
||||
addons.push(name);
|
||||
}
|
||||
addons = Array.from(new Set(addons));
|
||||
console.log('Current Addons: ', addons);
|
||||
fs.writeFileSync(addonPath, JSON.stringify(addons, null, 2));
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hydrooj",
|
||||
"version": "4.2.11",
|
||||
"version": "4.2.12",
|
||||
"bin": "bin/hydrooj.js",
|
||||
"main": "src/plugin-api",
|
||||
"module": "src/plugin-api",
|
||||
|
||||
@@ -8,6 +8,7 @@ import yaml from 'js-yaml';
|
||||
import { Context } from '../context';
|
||||
import i18n from '../lib/i18n';
|
||||
import { Logger } from '../logger';
|
||||
import { PRIV } from '../model/builtin';
|
||||
import * as bus from '../service/bus';
|
||||
import { unwrapExports } from '../utils';
|
||||
|
||||
@@ -37,13 +38,18 @@ const getLoader = (type: LoadTask, filename: string) => async function loader(pe
|
||||
for (const i of pending) {
|
||||
const p = locateFile(i, [`${filename}.ts`, `${filename}.js`]);
|
||||
if (p && !fail.includes(i)) {
|
||||
const name = type.replace(/^(.)/, (t) => t.toUpperCase());
|
||||
try {
|
||||
const m = unwrapExports(require(p));
|
||||
if (m.apply) ctx.loader.reloadPlugin(ctx, p, {});
|
||||
else logger.info(`${type.replace(/^(.)/, (t) => t.toUpperCase())} init: %s`, i);
|
||||
else logger.info(`${name} init: %s`, i);
|
||||
} catch (e) {
|
||||
fail.push(i);
|
||||
logger.info(`${type.replace(/^(.)/, (t) => t.toUpperCase())} load fail: %s`, i);
|
||||
app.inject(
|
||||
'Notification', `${name} load fail: {0}`,
|
||||
{ args: [i] }, PRIV.PRIV_VIEW_SYSTEM_NOTIFICATION,
|
||||
);
|
||||
logger.info(`${name} load fail: %s`, i);
|
||||
logger.error(e);
|
||||
}
|
||||
}
|
||||
@@ -82,6 +88,7 @@ export async function locale(pending: string[], fail: string[]) {
|
||||
logger.info('Locale init: %s', i);
|
||||
} catch (e) {
|
||||
fail.push(i);
|
||||
app.inject('Notification', 'Locale load fail: {0}', { args: [i] }, PRIV.PRIV_VIEW_SYSTEM_NOTIFICATION);
|
||||
logger.error('Locale Load Fail: %s', i);
|
||||
logger.error(e);
|
||||
}
|
||||
@@ -123,6 +130,7 @@ export async function setting(pending: string[], fail: string[], modelSetting: t
|
||||
}
|
||||
logger.info('Config load: %s', i);
|
||||
} catch (e) {
|
||||
app.inject('Notification', 'Config load fail: {0}', { args: [i] }, PRIV.PRIV_VIEW_SYSTEM_NOTIFICATION);
|
||||
logger.error('Config Load Fail: %s', i);
|
||||
logger.error(e);
|
||||
}
|
||||
@@ -144,6 +152,7 @@ export async function template(pending: string[], fail: string[]) {
|
||||
logger.info('Template init: %s', i);
|
||||
} catch (e) {
|
||||
fail.push(i);
|
||||
app.inject('Notification', 'Template load fail: {0}', { args: [i] }, PRIV.PRIV_VIEW_SYSTEM_NOTIFICATION);
|
||||
logger.error('Template Load Fail: %s', i);
|
||||
logger.error(e);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user