MCPcopy Create free account
hub / github.com/esengine/esengine / _loadOne

Method _loadOne

packages/runtime-core/src/PluginLoader.ts:233–275  ·  view source on GitHub ↗
(config: PluginLoadConfig)

Source from the content-addressed store, hash-verified

231 // ========== 私有方法 ==========
232
233 private async _loadOne(config: PluginLoadConfig): Promise<void> {
234 const info: PluginLoadInfo = {
235 packageId: config.packageId,
236 state: 'loading'
237 };
238 this._loaded.set(config.packageId, info);
239 const start = Date.now();
240
241 try {
242 let plugin: IRuntimePlugin | null = null;
243
244 switch (config.sourceType) {
245 case 'npm':
246 plugin = await this._loadNpm(config);
247 break;
248 case 'local':
249 plugin = await this._loadLocal(config);
250 break;
251 case 'static':
252 logger.warn(`Static plugin ${config.packageId} should be pre-registered`);
253 break;
254 }
255
256 if (plugin) {
257 info.plugin = plugin;
258 info.state = 'loaded';
259 info.loadTime = Date.now() - start;
260 runtimePluginManager.register(plugin);
261 logger.debug(`Loaded: ${config.packageId} (${info.loadTime}ms)`);
262 } else {
263 throw new Error('Plugin export not found');
264 }
265 } catch (error) {
266 info.state = 'failed';
267 info.error = error instanceof Error ? error.message : String(error);
268 info.loadTime = Date.now() - start;
269 logger.error(`Failed: ${config.packageId} - ${info.error}`);
270
271 if (!this._config.continueOnFailure) {
272 throw error;
273 }
274 }
275 }
276
277 private async _loadNpm(config: PluginLoadConfig): Promise<IRuntimePlugin | null> {
278 const module = await import(/* @vite-ignore */ config.packageId);

Callers 1

loadAllMethod · 0.95

Calls 8

_loadNpmMethod · 0.95
_loadLocalMethod · 0.95
nowMethod · 0.80
setMethod · 0.65
registerMethod · 0.65
warnMethod · 0.45
debugMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected