mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-18 01:36:08 +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 Schema from 'schemastery';
|
||||
import path from 'path';
|
||||
import child from 'child_process';
|
||||
// eslint-disable-next-line import/no-duplicates
|
||||
import './utils';
|
||||
import cac from 'cac';
|
||||
@@ -26,6 +27,21 @@ logger.debug('%o', argv);
|
||||
process.on('unhandledRejection', 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) {
|
||||
if (config === false) return;
|
||||
if (config === true) config = undefined;
|
||||
@@ -108,8 +124,12 @@ export class Loader {
|
||||
try {
|
||||
this.cache[name] ||= require.resolve(name);
|
||||
} catch (err) {
|
||||
logger.error(err.message);
|
||||
return;
|
||||
try {
|
||||
this.cache[name] ||= require.resolve(name, { paths: HYDROPATH });
|
||||
} catch (e) {
|
||||
logger.error(err.message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
return unwrapExports(require(this.cache[name]));
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ export interface EventMap extends LifecycleEvents, HandlerEvents {
|
||||
|
||||
'contest/before-add': (payload: Partial<Tdoc>) => 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/balloon': (domainId: string, tid: ObjectId, bdoc: ContestBalloonDoc) => VoidReturn
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ export function convertIniConfig(ini: string) {
|
||||
const count = parseInt(f[0], 10);
|
||||
const res = { subtasks: [] };
|
||||
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 cur = {
|
||||
cases: [{ input, output }],
|
||||
|
||||
Reference in new issue
Block a user