From e534a12a11bc587f17775ecd270df31cc1bba538 Mon Sep 17 00:00:00 2001 From: Marvin Zhang Date: Tue, 15 Apr 2025 21:00:53 +0800 Subject: [PATCH] feat: enhance Node.js environment configuration in task runner - Added a new utility function GetNodeBinPath to retrieve the global node_bin path from configuration, with a default fallback. - Updated configureNodePath method to set the PATH environment variable to include the node_bin path if it's not already present, improving the task runner's environment setup for Node.js development. --- core/task/handler/runner.go | 6 ++++++ core/utils/config.go | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/core/task/handler/runner.go b/core/task/handler/runner.go index ef61a2e0..9baf7574 100644 --- a/core/task/handler/runner.go +++ b/core/task/handler/runner.go @@ -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() { diff --git a/core/utils/config.go b/core/utils/config.go index c0455681..2ad35b83 100644 --- a/core/utils/config.go +++ b/core/utils/config.go @@ -33,6 +33,7 @@ const ( MetadataConfigName = "config.json" DefaultPyenvPath = "/root/.pyenv" DefaultNodeModulesPath = "/usr/lib/node_modules" + DefaultNodeBinPath = "/usr/lib/bin" DefaultGoPath = "/root/go" ) @@ -271,6 +272,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