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

Method reloadPlugin

packages/hydrooj/src/loader.ts:116–148  ·  view source on GitHub ↗
(key: string, configScope: string)

Source from the content-addressed store, hash-verified

114 }
115
116 async reloadPlugin(key: string, configScope: string) {
117 const plugin = this.resolvePlugin(key);
118 if (!plugin) return;
119 // currently cordis validates config and converts proxy to plain object
120 // must do a full reload once config changed
121 const config = await this.resolveConfig(plugin, configScope, false);
122 let fork = this.state[key];
123 const displayPath = key.includes('node_modules')
124 ? key.split('node_modules').pop()
125 : path.relative(process.cwd(), key);
126 logger.info(
127 `%s plugin %c${configScope ? ' with scope %c' : ''}`,
128 fork ? 'update' : 'apply', displayPath, configScope,
129 );
130 if (fork) {
131 fork.update(config, true);
132 } else {
133 fork = this.ctx.plugin(plugin, config);
134 if (!fork) return;
135 const inner = Object.getPrototypeOf(fork) !== Fiber.prototype
136 ? Object.getPrototypeOf(fork) : fork;
137 this.state[key] = inner;
138 }
139 if (!Object.isFrozen(config)) {
140 fork.ctx.on('system/setting', async () => {
141 if (!fork.uid || !this.state[key]) return;
142 const resolved = await this.resolveConfig(plugin, configScope, false);
143 if (isEqual(this.state[key].config, resolved)) return;
144 this.reloadPlugin(key, configScope);
145 });
146 }
147 return fork;
148 }
149
150 resolvePlugin(name: string) {
151 try {

Callers 5

getLoaderFunction · 0.80
builtinModelFunction · 0.80
applyFunction · 0.80
loadDirFunction · 0.80
loadFunction · 0.80

Calls 6

resolvePluginMethod · 0.95
resolveConfigMethod · 0.95
popMethod · 0.80
infoMethod · 0.45
updateMethod · 0.45
onMethod · 0.45

Tested by

no test coverage detected