srs / gradle-node-plugin

Gradle plugin for integrating NodeJS in your build. :rocket:
Apache License 2.0
866 stars 211 forks source link

Downloaded node binaries are not available in the PATH #243

Open fbecart opened 7 years ago

fbecart commented 7 years ago

Hi,

I have an issue specific to the fact that I use Lerna. Here is an extract of my root build.gradle:

buildscript {
    repositories {
        jcenter()
    }
}

node {
    version = '8.1.3'
    download = true
}

task lernaBootstrap(type: NpmTask) {
    dependsOn npmInstall

    args = ['run', 'lerna', 'bootstrap']
}

When npm run lerna bootstrap is executed, multiple npm processes will be started to download the dependencies of each Node project. Lerna uses the binaries (npm) available in the PATH.

Currently, the directory where the binaries are downloaded is not available in the PATH. As a result, Lerna uses the system version of npm instead of the downloaded one.

My workaround has been the following to build.gradle:

afterEvaluate {
    Map environment = [:] << System.getenv()
    environment.PATH = "${node.variant.nodeBinDir}:${environment.PATH}"
    lernaBootstrap.environment = environment
}

I imagine a better fix could be to let the plugin add the download directory to the PATH.

VBourdine commented 6 years ago

It's strange to me, that nobody else has been looking for this solution