Kotlin/JS maintains a local Node installation, used by Yarn, etc.
Is there a way to execute commands via that installation, without using a Gradle plugin that downloads another one?
The task kotlinNodeJsSetup exposes the destination of the Node installation.
Using this task, it is possible to create a NodeJS task:
tasks.create<Exec>("yourTask") {
dependsOn(":kotlinNodeJsSetup")
val kotlinNodeJsSetup = rootProject.tasks["kotlinNodeJsSetup"] as org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsSetupTask
workingDir = File(kotlinNodeJsSetup.destination, "bin")
commandLine(
"node",
"yourScript.js",
"arg1",
"…",
)
}
bin subfolder on Windows for the executable (node.exe is directly there). You might need to define the work dir differently based on OS, unless there is a better wayval yourTask by registering(Exec::class) { for the declaration. Also, had to use "./node" instead of "node".