mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: allow load from nix store
This commit is contained in:
3 files changed
+24
-4
No files matched your search
@@ -7,6 +7,7 @@ import './init';
|
|||||||
import './interface';
|
import './interface';
|
||||||
import Schema from 'schemastery';
|
import Schema from 'schemastery';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
import child from 'child_process';
|
||||||
// eslint-disable-next-line import/no-duplicates
|
// eslint-disable-next-line import/no-duplicates
|
||||||
import './utils';
|
import './utils';
|
||||||
import cac from 'cac';
|
import cac from 'cac';
|
||||||
@@ -26,6 +27,21 @@ logger.debug('%o', argv);
|
|||||||
process.on('unhandledRejection', logger.error);
|
process.on('unhandledRejection', logger.error);
|
||||||
process.on('uncaughtException', logger.error);
|
process.on('uncaughtException', logger.error);
|
||||||
|
|
||||||
|
const HYDROPATH = [];
|
||||||
|
|
||||||
|
if (process.env.NIX_PROFILES) {
|
||||||
|
try {
|
||||||
|
const result = JSON.parse(child.execSync('nix-env -q --json --out-path --meta').toString()) as Record<string, any>;
|
||||||
|
for (const derivation of Object.values(result)) {
|
||||||
|
if (derivation.name.startsWith('hydro-plugin-') && derivation.outputs?.out) {
|
||||||
|
HYDROPATH.push(derivation.outputs.out);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
logger.error('Nix detected, but failed to list installed derivations.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function resolveConfig(plugin: any, config: any) {
|
export function resolveConfig(plugin: any, config: any) {
|
||||||
if (config === false) return;
|
if (config === false) return;
|
||||||
if (config === true) config = undefined;
|
if (config === true) config = undefined;
|
||||||
@@ -108,8 +124,12 @@ export class Loader {
|
|||||||
try {
|
try {
|
||||||
this.cache[name] ||= require.resolve(name);
|
this.cache[name] ||= require.resolve(name);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error(err.message);
|
try {
|
||||||
return;
|
this.cache[name] ||= require.resolve(name, { paths: HYDROPATH });
|
||||||
|
} catch (e) {
|
||||||
|
logger.error(err.message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return unwrapExports(require(this.cache[name]));
|
return unwrapExports(require(this.cache[name]));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ export interface EventMap extends LifecycleEvents, HandlerEvents {
|
|||||||
|
|
||||||
'contest/before-add': (payload: Partial<Tdoc>) => VoidReturn
|
'contest/before-add': (payload: Partial<Tdoc>) => VoidReturn
|
||||||
'contest/add': (payload: Partial<Tdoc>, id: ObjectId) => VoidReturn
|
'contest/add': (payload: Partial<Tdoc>, id: ObjectId) => VoidReturn
|
||||||
'contest/list': (query: Fileter<Tdoc>, handler: any) => VoidReturn
|
'contest/list': (query: Filter<Tdoc>, handler: any) => VoidReturn
|
||||||
'contest/scoreboard': (tdoc: Tdoc, rows: ScoreboardRow[], udict: BaseUserDict, pdict: ProblemDict) => VoidReturn
|
'contest/scoreboard': (tdoc: Tdoc, rows: ScoreboardRow[], udict: BaseUserDict, pdict: ProblemDict) => VoidReturn
|
||||||
'contest/balloon': (domainId: string, tid: ObjectId, bdoc: ContestBalloonDoc) => VoidReturn
|
'contest/balloon': (domainId: string, tid: ObjectId, bdoc: ContestBalloonDoc) => VoidReturn
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ export function convertIniConfig(ini: string) {
|
|||||||
const count = parseInt(f[0], 10);
|
const count = parseInt(f[0], 10);
|
||||||
const res = { subtasks: [] };
|
const res = { subtasks: [] };
|
||||||
for (let i = 1; i <= count; i++) {
|
for (let i = 1; i <= count; i++) {
|
||||||
if (!f[i] || !f[i].trim()) throw new Error('Testcada count incorrect.');
|
if (!f[i]?.trim()) throw new Error('Testdata count incorrect.');
|
||||||
const [input, output, time, score, memory] = f[i].split('|');
|
const [input, output, time, score, memory] = f[i].split('|');
|
||||||
const cur = {
|
const cur = {
|
||||||
cases: [{ input, output }],
|
cases: [{ input, output }],
|
||||||
|
|||||||
Reference in new issue
Block a user