Skip to content

Commit f951da8

Browse files
committed
[BUG FIX] Fix path resolution for executables
1 parent cf42426 commit f951da8

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

build.gradle.kts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ plugins {
1919
id("com.cinnober.gradle.semver-git") version "3.0.0"
2020
id("org.jetbrains.dokka") version "1.7.10"
2121
id("org.gradle.test-retry") version "1.5.0"
22+
`maven-publish`
2223
}
2324

2425
group = "com.github.node-gradle"
@@ -59,6 +60,35 @@ dependencies {
5960
testImplementation("org.mock-server:mockserver-netty:5.15.0")
6061
}
6162

63+
publishing {
64+
publications {
65+
create<MavenPublication>("mavenJava") {
66+
from(components["java"])
67+
groupId = "com.github.node-gradle"
68+
artifactId = "gradle-node-plugin"
69+
version = project.version.toString()
70+
pom {
71+
name.set("Gradle Node.js Plugin")
72+
description.set("Gradle plugin for executing Node.js scripts. Supports npm, pnpm, Yarn, and Bun.")
73+
url.set("https://github.com/node-gradle/gradle-node-plugin")
74+
licenses {
75+
license {
76+
name.set("Apache License, Version 2.0")
77+
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
78+
}
79+
}
80+
}
81+
}
82+
}
83+
repositories {
84+
maven {
85+
name = "localMaven"
86+
url = uri("${buildDir}/maven-repo")
87+
}
88+
}
89+
}
90+
91+
6292
tasks.compileTestGroovy {
6393
// Should be
6494
// classpath += files(sourceSets.test.get().kotlin.classesDirectory)

src/main/kotlin/com/github/gradle/node/exec/ExecRunner.kt

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,24 @@ fun computeWorkingDir(nodeProjectDir: DirectoryProperty, execConfiguration: Exec
3535
return workingDir
3636
}
3737

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+
3856
/**
3957
* Basic execution runner that runs a given ExecConfiguration.
4058
*
@@ -43,8 +61,9 @@ fun computeWorkingDir(nodeProjectDir: DirectoryProperty, execConfiguration: Exec
4361
*/
4462
class ExecRunner {
4563
fun execute(projectHelper: ProjectApiHelper, extension: NodeExtension, execConfiguration: ExecConfiguration): ExecResult {
64+
val executablePath = findBestExecutableMatch(execConfiguration.executable)
4665
return projectHelper.exec {
47-
executable = execConfiguration.executable
66+
executable = executablePath
4867
args = execConfiguration.args
4968
environment = computeEnvironment(execConfiguration)
5069
isIgnoreExitValue = execConfiguration.ignoreExitValue

0 commit comments

Comments
 (0)