From c7b9a8b5b89187490e7c076d8e0dcf442895e7e5 Mon Sep 17 00:00:00 2001 From: Alexander Kucera Date: Wed, 5 Nov 2025 08:50:15 +0100 Subject: [PATCH] Fixes executable path resolution on Windows Updates the executable path resolution logic to correctly identify executables on Windows systems by using the 'where' command instead of 'which', which is not available on Windows. This change ensures that the application can locate and execute dependencies properly, regardless of the operating system. It also uses `path.isAbsolute` to accurately determine if a user-provided path is absolute, improving the reliability of path resolution. --- src/core/ExecutableChecker.ts | 26 +++++++++++++++++--------- src/plugin/PathResolver.ts | 8 ++++++-- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/core/ExecutableChecker.ts b/src/core/ExecutableChecker.ts index b115e66..1dfe40c 100644 --- a/src/core/ExecutableChecker.ts +++ b/src/core/ExecutableChecker.ts @@ -10,6 +10,7 @@ */ import { DEPENDENCY_CONSTANTS } from './constants'; +import * as path from 'path'; /** * Information about a checked dependency executable. @@ -140,12 +141,15 @@ export class ExecutableChecker { */ private static async findExecutableWithWhich(executableName: string, additionalPaths: string[] = []): Promise { const { spawn } = require('child_process'); - + try { const stdout = await new Promise((resolve, reject) => { const env = this.getAugmentedEnv(additionalPaths); - - const whichProcess = spawn('which', [executableName], { + + // Use platform-specific command: 'where' on Windows, 'which' on Unix + const whichCommand = process.platform === 'win32' ? 'where' : 'which'; + + const whichProcess = spawn(whichCommand, [executableName], { stdio: ['pipe', 'pipe', 'pipe'], env: env }); @@ -213,8 +217,8 @@ export class ExecutableChecker { * ``` */ public static async resolveExecutablePath(userPath: string | undefined, defaultName: string, additionalPaths: string[] = []): Promise { - // If user provided a full path (contains /), use it as-is - if (userPath && userPath.trim() !== '' && userPath.includes('/')) { + // If user provided an absolute path, use it as-is + if (userPath && userPath.trim() !== '' && path.isAbsolute(userPath)) { return userPath; } @@ -246,18 +250,22 @@ export class ExecutableChecker { * @see {@link resolveExecutablePath} for detailed resolution logic and examples */ public static resolveExecutablePathSync(userPath: string | undefined, defaultName: string, additionalPaths: string[] = []): string { - // If user provided a full path (contains /), use it as-is - if (userPath && userPath.trim() !== '' && userPath.includes('/')) { + // If user provided an absolute path, use it as-is + if (userPath && userPath.trim() !== '' && path.isAbsolute(userPath)) { return userPath; } // If user provided just an executable name or empty path, resolve it const searchName = (userPath && userPath.trim() !== '') ? userPath.trim() : defaultName; - + // Try to find the executable using which command synchronously const { spawnSync } = require('child_process'); + + // Use platform-specific command: 'where' on Windows, 'which' on Unix + const whichCommand = process.platform === 'win32' ? 'where' : 'which'; + try { - const result = spawnSync('which', [searchName], { + const result = spawnSync(whichCommand, [searchName], { encoding: 'utf8', env: this.getAugmentedEnv(additionalPaths) }); diff --git a/src/plugin/PathResolver.ts b/src/plugin/PathResolver.ts index a677424..828b418 100644 --- a/src/plugin/PathResolver.ts +++ b/src/plugin/PathResolver.ts @@ -27,13 +27,17 @@ export class PathResolver { // Try to find the executable using which command const { spawnSync } = require('child_process'); + + // Use platform-specific command: 'where' on Windows, 'which' on Unix + const whichCommand = process.platform === 'win32' ? 'where' : 'which'; + try { const augmentedEnv = { ...process.env, PATH: `/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:${process.env.PATH || ''}` }; - - const result = spawnSync('which', [defaultName], { + + const result = spawnSync(whichCommand, [defaultName], { encoding: 'utf8', env: augmentedEnv });