ui-next: refactor addon ui patch resolving

This commit is contained in:
Baoshuo committed 2026-05-10 01:12:46 +08:00
1 parent 562ff3acbe
commit 8f366a04c0
2 files changed
+10 -6

No files matched your search

+1 -1
View File
@@ -622,7 +622,7 @@ export interface ProblemSearchOptions {
export type ProblemSearch = (domainId: string, q: string, options?: ProblemSearchOptions) => Promise<ProblemSearchResponse>;
export type UIInjectableFields = 'ProblemAdd' | 'Notification' | 'Nav' | 'UserDropdown' | 'DomainManage' | 'ControlPanel' | 'Route';
export type UIInjectableFields = 'ProblemAdd' | 'Notification' | 'Nav' | 'UserDropdown' | 'DomainManage' | 'ControlPanel';
export interface UI {
nodes: Record<UIInjectableFields, any[]>;
getNodes: typeof import('./lib/ui').getNodes;
+9 -5
View File
@@ -5,7 +5,7 @@ import react from '@vitejs/plugin-react';
import c2k from 'koa2-connect/ts';
import { createServer, type Plugin } from 'vite';
import { serializer } from '@hydrooj/framework';
import { Context, getNodes } from 'hydrooj';
import { Context } from 'hydrooj';
const INJECT_MARKER = '<!-- __HYDRO_INJECTION__DO_NOT_REMOVE_THIS__ -->';
const buildInject = (str: string) => `<script id="__HYDRO_INJECTION__" type="application/json">${str}</script>`;
@@ -23,10 +23,14 @@ function hydroPlugins(): Plugin {
},
load(id) {
if (id === resolvedVirtualModuleId) {
const plugins = getNodes('Route');
if (!plugins) return 'export default [];';
const imports = plugins.map((p, i) => `import plugin${i} from '${p.args.entry}';`).join('\n');
const exports = `export default [${plugins.map((p, i) => `plugin${i}`).join(', ')}];`;
const entries: string[] = [];
for (const addon of Object.values(global.addons)) {
const uiEntry = path.resolve(addon, 'ui', 'index.ts');
if (fs.existsSync(uiEntry)) entries.push(uiEntry);
}
if (!entries.length) return 'export default [];';
const imports = entries.map((e, i) => `import plugin${i} from '${e}';`).join('\n');
const exports = `export default [${entries.map((_, i) => `plugin${i}`).join(', ')}];`;
return `${imports}\n${exports}`;
}
},