Skip to content

[BUG FIX] Fix path resolution for executables#328

Open
rasharab wants to merge 2 commits into
node-gradle:mainfrom
unblocked:FixGradleNode
Open

[BUG FIX] Fix path resolution for executables#328
rasharab wants to merge 2 commits into
node-gradle:mainfrom
unblocked:FixGradleNode

Conversation

@rasharab

@rasharab rasharab commented Jan 16, 2025

Copy link
Copy Markdown

There’s an issue with mac silicion+intellij, whereby gradle process executor is not respecting path environment variables.

This gets around that by using a fix for the plugin whereby we attempt to resolve the path manually.

#152

https://youtrack.jetbrains.com/issue/IDEA-334183

We hit this constantly with our development team and this fix resolved it for us.

@deepy deepy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've got a hunch of what you're trying to solve, but if you can describe the problem I can give better pointers

* @return The best matching executable path as a String.
*/
fun findBestExecutableMatch(executableName: String): String {
val pathVariable = System.getenv("PATH") ?: return executableName

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iirc this won't work on windows where environment variables are case-insensitive (and default to Path)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Easy to fix, thanks.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

*/
class ExecRunner {
fun execute(projectHelper: ProjectApiHelper, extension: NodeExtension, execConfiguration: ExecConfiguration): ExecResult {
val executablePath = findBestExecutableMatch(execConfiguration.executable)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From a quick glance it looks like this will break the download functionality entirely by only using already installed applications

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will address these points. Thanks.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done with tests to validate behaviour (w/ download and without download)

Comment thread src/main/kotlin/com/github/gradle/node/NodeExtension.kt
1. Add abiility for tests to override environment behaviour
2. Fix tests.
@rasharab

rasharab commented Jan 16, 2025

Copy link
Copy Markdown
Author

I've got a hunch of what you're trying to solve, but if you can describe the problem I can give better pointers

Updated comments. I prematurely submitted this pr, apologies.

@psoares

psoares commented Mar 6, 2025

Copy link
Copy Markdown

Is this published yet? I have a similar issue when running under WSL2: I have nodejs installed both on windows and on WSL (Ubuntu). Despite having my PATH set to pick the WSL version, when I run gradle commands, it picks up the windows version of npm instead. The only thing that works is activating the npm install task, which I don't want since I already have a system-level nodejs installed. I'm using v7.1.0.

@MukjepScarlet

Copy link
Copy Markdown

I have this issue too. I'm using 7.1.0 and have Node.JS on my Mac (arm64), I'm sure that npm is usable, but the task always logs Cause: error=2, No such file or directory.

@MukjepScarlet

Copy link
Copy Markdown

I hope this can be merged and published, or at least provide a snapshot publication.

@MukjepScarlet

Copy link
Copy Markdown

I built it on jitpack.io
Now we can use this in build.gradle.kts:

buildscript {
    repositories {
        maven(url = "https://jitpack.io")
    }
    dependencies {
        classpath("com.github.NextChapterSoftware.gradle-node-plugin:com.github.node-gradle.node.gradle.plugin:FixGradleNode-SNAPSHOT")
    }
}
apply(plugin = "com.github.node-gradle.node")

It actually works to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants