We've been using <gradle-node-plugin> in our proje...
# javascript
a
We've been using gradle-node-plugin in our project to write Gradle Tasks that call node/npm because it • lets us explicitly specify an npm version • lets us share tasks across projects that don't use Kotlin/JS • has convenient helpers for
NpmTask
and
NpxTask
• seems to be better-documented than the almost-secret tasks bundled with Kotlin/JS At the same time, the Kotlin/JS compiler also downloads node/yarn as needed too. Does anyone have a setup where they have them configured to play well together? Maybe just • turning off downloads for one of the two plugins • setting them both to run yarn from the same directory • making sure that the setup task for the plugin with the disabled download dependsOn the setup task for the other plugin ?
m
Not 100% sure this is what you're looking for but there is new stuff in 1.6 about using pre-installed node: https://kotlinlang.org/docs/whatsnew16.html#option-to-use-pre-installed-node-js-and-yarn
a
That's what inspired this question 😄 We still want Gradle to download node to ensure we're using a consistent version. We just want to download it once instead of multiple times when more than one plugin uses it 🙃
😁 1
👍 1
e
do you need gradle-node-plugin? for simple scripts, you can do something like
Copy code
val myScript by tasks.registering(Exec::class) {
    doFirst {
        val kotlinNodeJs = rootProject.the<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension>()
        executable(kotlinNodeJs.requireConfigured().nodeExecutable)
    }
    args(file("myScript.js"), "arg1", "arg2")
}
and for fetching NPM dependencies, just add them to some Kotlin/JS project
a
@ephemient we mostly use the NpxTask and NpmTask helpers from the plugin, but maybe I could use your snippet to reimplement them…
e
that should hopefully not be too hard 🤞 alternately, it might be possible to tell gradle-node-plugin to use Kotlin's installation, but I'm not sure if the order of configuration will work or not