From a7abd8d09fdf6d8946f5367098b71c2960965bf4 Mon Sep 17 00:00:00 2001 From: Zijun Yang <37757768+zpatronus@users.noreply.github.com> Date: Mon, 1 Dec 2025 22:49:40 -0500 Subject: [PATCH] fix(shell-utils): resolve command detection on Ubuntu by using shell for builtins (#1123) --- packages/core/src/utils/shell-utils.ts | 43 +++++++++++++++++--------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/packages/core/src/utils/shell-utils.ts b/packages/core/src/utils/shell-utils.ts index 6afab89d..320f8ff0 100644 --- a/packages/core/src/utils/shell-utils.ts +++ b/packages/core/src/utils/shell-utils.ts @@ -517,24 +517,39 @@ export function resolveCommandPath(command: string): { try { const isWin = process.platform === 'win32'; - const checkCommand = isWin ? 'where' : 'command'; - const checkArgs = isWin ? [command] : ['-v', command]; + if (isWin) { + const checkCommand = 'where.exe'; + const checkArgs = [command]; - let result: string | null = null; - try { - result = execFileSync(checkCommand, checkArgs, { - encoding: 'utf8', - shell: isWin, - }).trim(); - } catch { - console.warn(`Command ${checkCommand} not found`); - } + let result: string | null = null; + try { + result = execFileSync(checkCommand, checkArgs, { + encoding: 'utf8', + shell: false, + }).trim(); + } catch { + return { path: null, error: undefined }; + } - if (!result) return { path: null, error: undefined }; - if (!isWin) { + return result ? { path: result } : { path: null }; + } else { + const shell = '/bin/sh'; + const checkArgs = ['-c', `command -v ${escapeShellArg(command, 'bash')}`]; + + let result: string | null = null; + try { + result = execFileSync(shell, checkArgs, { + encoding: 'utf8', + shell: false, + }).trim(); + } catch { + return { path: null, error: undefined }; + } + + if (!result) return { path: null, error: undefined }; accessSync(result, fsConstants.X_OK); + return { path: result, error: undefined }; } - return { path: result, error: undefined }; } catch (error) { return { path: null,