MCPcopy Create free account
hub / github.com/hydro-dev/Hydro / getLoader

Function getLoader

packages/hydrooj/src/entry/common.ts:23–43  ·  view source on GitHub ↗
(type: LoadTask, filename: string)

Source from the content-addressed store, hash-verified

21
22type LoadTask = 'model' | 'addon' | 'service';
23const getLoader = (type: LoadTask, filename: string) => async function loader(pending: Record<string, string>, fail: string[], ctx: Context) {
24 for (const [name, i] of Object.entries(pending)) {
25 const p = locateFile(i, [`${filename}.ts`, `${filename}.js`]);
26 if (p && !fail.includes(i)) {
27 const loadType = type.replace(/^(.)/, (t) => t.toUpperCase());
28 try {
29 const m = unwrapExports(require(p));
30 if (m.apply) ctx.loader.reloadPlugin(p, name);
31 else logger.info(`${loadType} init: %s`, i);
32 } catch (e) {
33 fail.push(i);
34 app.injectUI(
35 'Notification', `${loadType} load fail: {0}`,
36 { args: [i], type: 'warn' }, PRIV.PRIV_VIEW_SYSTEM_NOTIFICATION,
37 );
38 logger.info(`${loadType} load fail: %s`, i);
39 logger.error(e);
40 }
41 }
42 }
43};
44
45export const addon = getLoader('addon', 'index');
46export const model = getLoader('model', 'model');

Callers 2

loadLanguagesFunction · 0.85
common.tsFile · 0.85

Calls 6

unwrapExportsFunction · 0.90
reloadPluginMethod · 0.80
locateFileFunction · 0.70
infoMethod · 0.45
pushMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected