@@ -35,6 +35,24 @@ fun computeWorkingDir(nodeProjectDir: DirectoryProperty, execConfiguration: Exec
35
35
return workingDir
36
36
}
37
37
38
+ /* *
39
+ * Helper function to find the best matching executable in the system PATH.
40
+ *
41
+ * @param executableName The name of the executable to search for.
42
+ * @return The best matching executable path as a String.
43
+ */
44
+ fun findBestExecutableMatch (executableName : String ): String {
45
+ val pathVariable = System .getenv(" PATH" ) ? : return executableName
46
+ val paths = pathVariable.split(File .pathSeparator)
47
+ for (path in paths) {
48
+ val executableFile = File (path, executableName)
49
+ if (executableFile.exists() && executableFile.canExecute()) {
50
+ return executableFile.absolutePath
51
+ }
52
+ }
53
+ return executableName // Return the original executable if no match is found
54
+ }
55
+
38
56
/* *
39
57
* Basic execution runner that runs a given ExecConfiguration.
40
58
*
@@ -43,8 +61,9 @@ fun computeWorkingDir(nodeProjectDir: DirectoryProperty, execConfiguration: Exec
43
61
*/
44
62
class ExecRunner {
45
63
fun execute (projectHelper : ProjectApiHelper , extension : NodeExtension , execConfiguration : ExecConfiguration ): ExecResult {
64
+ val executablePath = findBestExecutableMatch(execConfiguration.executable)
46
65
return projectHelper.exec {
47
- executable = execConfiguration.executable
66
+ executable = executablePath
48
67
args = execConfiguration.args
49
68
environment = computeEnvironment(execConfiguration)
50
69
isIgnoreExitValue = execConfiguration.ignoreExitValue
0 commit comments