Skip to content

Commit 3dc377b

Browse files
committed
discover node executable with nvm, if possible
1 parent ab0f845 commit 3dc377b

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lts/hydrogen

project/AsyncUtilsBuildPlugin.scala

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import _root_.scalafix.sbt.ScalafixTestkitPlugin.autoImport.*
22
import _root_.scalafix.sbt.{ScalafixPlugin, ScalafixTestkitPlugin}
33
import com.typesafe.tools.mima.plugin.MimaPlugin
44
import com.typesafe.tools.mima.plugin.MimaPlugin.autoImport.*
5+
import org.scalajs.jsenv.JSEnv
6+
import org.scalajs.jsenv.nodejs.NodeJSEnv
7+
import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport.*
58
import org.typelevel.sbt.TypelevelMimaPlugin.autoImport.*
69
import org.typelevel.sbt.gha.GenerativePlugin.autoImport.*
710
import org.typelevel.sbt.mergify.MergifyPlugin
@@ -109,6 +112,7 @@ object AsyncUtilsBuildPlugin extends AutoPlugin {
109112
"org.typelevel" %% "cats-tagless-core" % CatsTaglessV,
110113
) ++ (if (scalaVersion.value.startsWith("2")) scala2CompilerPlugins else Nil)
111114
},
115+
jsEnv := nvmJsEnv.value,
112116
)
113117
.jvmPlatform(Scala2Versions)
114118
.jsPlatform(Scala2Versions)
@@ -123,6 +127,7 @@ object AsyncUtilsBuildPlugin extends AutoPlugin {
123127
"org.typelevel" %% "cats-effect" % CatsEffect3V,
124128
) ++ (if (scalaVersion.value.startsWith("2")) scala2CompilerPlugins else Nil)
125129
},
130+
jsEnv := nvmJsEnv.value,
126131
)
127132
.dependsOn(`async-utils-core`)
128133

@@ -328,6 +333,18 @@ object AsyncUtilsBuildPlugin extends AutoPlugin {
328333
*/
329334
githubWorkflowScalaVersions := Seq("2.13"),
330335
githubWorkflowBuildSbtStepPreamble := Nil,
336+
337+
nodeExecutable :=
338+
scala.util.Try {
339+
import scala.sys.process.*
340+
341+
Process("bash" :: "-c" :: ". $HOME/.nvm/nvm.sh --no-use && nvm which" :: Nil)
342+
.lineStream
343+
.last
344+
}
345+
.toOption
346+
.map(file),
347+
nvmJsEnv := new NodeJSEnv(nodeExecutable.value.map(_.getAbsolutePath).foldLeft(NodeJSEnv.Config())(_ withExecutable _))
331348
)
332349

333350
override def extraProjects: Seq[Project] = autoImport.allProjects
@@ -336,4 +353,7 @@ object AsyncUtilsBuildPlugin extends AutoPlugin {
336353
def %(vav: Version): ModuleID =
337354
oan % vav.toString
338355
}
356+
357+
private lazy val nvmJsEnv: TaskKey[JSEnv] = taskKey("use nvm to find node")
358+
private lazy val nodeExecutable: TaskKey[Option[File]] = taskKey("path to Node executable for JS tasks")
339359
}

0 commit comments

Comments
 (0)