chore: fix shell exec node path
This commit is contained in:
@@ -75,21 +75,6 @@ func Execute(ctx context.Context, req Request, stdout, stderr io.Writer) (*Resul
|
|||||||
return ExecuteWithHooks(ctx, req, stdout, stderr, nil)
|
return ExecuteWithHooks(ctx, req, stdout, stderr, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// injectMiseEnvs 隐式且静默地解析包含特定环境(如 node)的全局路径,并将其注入为环境变量
|
|
||||||
func injectMiseEnvs(req *Request) {
|
|
||||||
if !req.UseMise {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
for _, lang := range req.Languages {
|
|
||||||
if lang["name"] == "node" {
|
|
||||||
if nodePath := utils.GetMiseNodePath(lang["version"]); nodePath != "" {
|
|
||||||
req.Envs = append(req.Envs, "NODE_PATH="+nodePath)
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ExecuteWithHooks 执行命令(带钩子支持)
|
// ExecuteWithHooks 执行命令(带钩子支持)
|
||||||
func ExecuteWithHooks(ctx context.Context, req Request, stdout, stderr io.Writer, hooks Hooks) (*Result, error) {
|
func ExecuteWithHooks(ctx context.Context, req Request, stdout, stderr io.Writer, hooks Hooks) (*Result, error) {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
@@ -128,11 +113,9 @@ func ExecuteWithHooks(ctx context.Context, req Request, stdout, stderr io.Writer
|
|||||||
execCtx, cancel := context.WithTimeout(ctx, time.Duration(timeout)*time.Minute)
|
execCtx, cancel := context.WithTimeout(ctx, time.Duration(timeout)*time.Minute)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
// 隐式且静默地获取包含 node 环境的全局路径,并注入环境变量 (带极速缓存)
|
|
||||||
injectMiseEnvs(&req)
|
|
||||||
|
|
||||||
// 如果指定使用 mise,则预先构建好带 mise 的命令,这样 PreExecute 记录的就是完整命令
|
// 如果指定使用 mise,则预先构建好带 mise 的命令,这样 PreExecute 记录的就是完整命令
|
||||||
if req.UseMise {
|
if req.UseMise {
|
||||||
|
utils.InjectNodePath(&req.Envs, req.Languages)
|
||||||
req.Command = utils.BuildMiseCommand(req.Command, req.Languages)
|
req.Command = utils.BuildMiseCommand(req.Command, req.Languages)
|
||||||
req.UseMise = false
|
req.UseMise = false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -366,6 +366,8 @@ func (s *Scheduler) executeTask(req *ExecutionRequest) (*ExecutionResult, error)
|
|||||||
|
|
||||||
// 如果指定使用 mise,则预先构建好带 mise 的命令,这样 OnTaskExecuting 记录的就是完整命令
|
// 如果指定使用 mise,则预先构建好带 mise 的命令,这样 OnTaskExecuting 记录的就是完整命令
|
||||||
if req.UseMise {
|
if req.UseMise {
|
||||||
|
// 先注入 NODE_PATH (由于调度器会把 UseMise 置为 false,所以必须在这里提前处理)
|
||||||
|
utils.InjectNodePath(&req.Envs, req.Languages)
|
||||||
req.Command = utils.BuildMiseCommand(req.Command, req.Languages)
|
req.Command = utils.BuildMiseCommand(req.Command, req.Languages)
|
||||||
req.UseMise = false
|
req.UseMise = false
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-1
@@ -19,7 +19,7 @@ func GetMiseNodePath(version string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cmd := exec.Command("mise", "where", "node@"+version)
|
cmd := exec.Command("mise", "where", "node@"+version)
|
||||||
out, err := cmd.Output()
|
out, err := cmd.CombinedOutput()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
nodeDir := strings.TrimSpace(string(out))
|
nodeDir := strings.TrimSpace(string(out))
|
||||||
if nodeDir != "" {
|
if nodeDir != "" {
|
||||||
@@ -32,6 +32,18 @@ func GetMiseNodePath(version string) string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// InjectNodePath 检查语言环境中是否有 node,如果有则自动获取并注入 NODE_PATH 到环境变量切片中
|
||||||
|
func InjectNodePath(envs *[]string, languages []map[string]string) {
|
||||||
|
for _, lang := range languages {
|
||||||
|
if lang["name"] == "node" {
|
||||||
|
if nodePath := GetMiseNodePath(lang["version"]); nodePath != "" {
|
||||||
|
*envs = append(*envs, "NODE_PATH="+nodePath)
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// BuildMiseCommand 构建多语言 mise 执行命令 (字符串形式)
|
// BuildMiseCommand 构建多语言 mise 执行命令 (字符串形式)
|
||||||
func BuildMiseCommand(command string, languages []map[string]string) string {
|
func BuildMiseCommand(command string, languages []map[string]string) string {
|
||||||
if len(languages) == 0 {
|
if len(languages) == 0 {
|
||||||
|
|||||||
Generated
+1480
-323
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user