feat: add global node_bin path configuration in Runner

- Introduced a new method to configure the global node_bin path in the Runner, ensuring it is included in the system PATH if not already present.
- Added GetNodeBinPath function in utils to retrieve the node_bin path from configuration, with a default fallback.
- Enhanced environment variable management for better integration of Node.js binaries.
This commit is contained in:
Marvin Zhang
2025-04-15 20:55:47 +08:00
parent f167ff7600
commit 1ce6f87ad5
2 changed files with 18 additions and 3 deletions

View File

@@ -364,6 +364,12 @@ func (r *Runner) configureNodePath() {
_ = os.Setenv("PATH", nodePath+":"+envPath)
}
_ = os.Setenv("NODE_PATH", nodePath)
// Configure global node_bin path
nodeBinPath := utils.GetNodeBinPath()
if !strings.Contains(envPath, nodeBinPath) {
_ = os.Setenv("PATH", nodeBinPath+":"+envPath)
}
}
func (r *Runner) configureGoPath() {

View File

@@ -2,12 +2,13 @@ package utils
import (
"fmt"
"github.com/gin-gonic/gin"
"github.com/mitchellh/go-homedir"
"github.com/spf13/viper"
"os"
"path/filepath"
"strings"
"github.com/gin-gonic/gin"
"github.com/mitchellh/go-homedir"
"github.com/spf13/viper"
)
const (
@@ -34,6 +35,7 @@ const (
MetadataConfigName = "config.json"
DefaultPyenvPath = "/root/.pyenv"
DefaultNodeModulesPath = "/usr/lib/node_modules"
DefaultNodeBinPath = "/usr/lib/node_bin"
DefaultGoPath = "/root/go"
DefaultMCPServerHost = "0.0.0.0"
DefaultMCPServerPort = 9777
@@ -283,6 +285,13 @@ func GetNodeModulesPath() string {
return DefaultNodeModulesPath
}
func GetNodeBinPath() string {
if res := viper.GetString("install.node.bin"); res != "" {
return res
}
return DefaultNodeBinPath
}
func GetGoPath() string {
if res := viper.GetString("install.go.path"); res != "" {
return res