yao/script/script.go
Max 26189fd61f feat: Clear modules before loading shared library
Clear the modules before loading the shared library to ensure a clean state. This is necessary to avoid any conflicts or issues with previously loaded modules.
2024-06-06 15:44:28 +08:00

36 lines
749 B
Go

package script
import (
"fmt"
"github.com/yaoapp/gou/application"
v8 "github.com/yaoapp/gou/runtime/v8"
"github.com/yaoapp/yao/config"
"github.com/yaoapp/yao/share"
)
// Load 加载共享库
func Load(cfg config.Config) error {
v8.CLearModules()
exts := []string{"*.js", "*.ts"}
err := application.App.Walk("scripts", func(root, file string, isdir bool) error {
if isdir {
return nil
}
_, err := v8.Load(file, share.ID(root, file))
return err
}, exts...)
if err != nil {
return err
}
return application.App.Walk("services", func(root, file string, isdir bool) error {
if isdir {
return nil
}
id := fmt.Sprintf("__yao_service.%s", share.ID(root, file))
_, err := v8.Load(file, id)
return err
}, exts...)
}