MCPcopy Create free account
hub / github.com/APIParkLab/APIPark / loadModule

Function loadModule

frontend/packages/common/src/hooks/pluginLoader.ts:382–409  ·  view source on GitHub ↗
(routerPrefix: string, pluginName: any, exposedModule: string, pluginPath: any)

Source from the content-addressed store, hash-verified

380 }
381
382 const loadModule = async (routerPrefix: string, pluginName: any, exposedModule: string, pluginPath: any) => {
383 if (!modules.get(routerPrefix)) {
384 try {
385 const loadedModule = await loadRemoteModule(generateRemoteModuleTemplate(pluginName, exposedModule, pluginPath))
386 const Module = loadedModule.default ?? loadedModule
387 let ModuleBootstrap
388 try {
389 ModuleBootstrap = await loadRemoteModule(generateRemoteModuleTemplate(pluginName, 'Bootstrap', pluginPath))
390 } catch (error) {
391 console.warn('Bootstrap module not found:', error)
392 }
393 setModules((prevModules) => new Map(prevModules).set(routerPrefix, Module[exposedModule]))
394 if (!validateExportLifecycle(Module)) {
395 console.error('需要导出插件生命周期函数')
396 return
397 }
398 await Module.bootstrap?.({
399 pluginProvider,
400 pluginEventHub,
401 pluginSlotHub
402 })
403 return Module
404 } catch (error) {
405 console.error('导入插件失败:', error)
406 }
407 }
408 return getModule(routerPrefix, true)
409 }
410
411 const loadExecutedPlugin = async () => {
412 setStartLoadExecutePlugin(true)

Callers

nothing calls this directly

Calls 6

loadRemoteModuleFunction · 0.90
validateExportLifecycleFunction · 0.90
getModuleFunction · 0.85
getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected