From 3dc377bed50396dd5566d5d3fce0da3816e3e057 Mon Sep 17 00:00:00 2001 From: Brian Holt Date: Tue, 6 Jun 2023 12:58:19 -0500 Subject: [PATCH] discover node executable with nvm, if possible --- .nvmrc | 1 + project/AsyncUtilsBuildPlugin.scala | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 .nvmrc diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 000000000..a77793ecc --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +lts/hydrogen diff --git a/project/AsyncUtilsBuildPlugin.scala b/project/AsyncUtilsBuildPlugin.scala index a159a38a9..8d9dc1e74 100644 --- a/project/AsyncUtilsBuildPlugin.scala +++ b/project/AsyncUtilsBuildPlugin.scala @@ -2,6 +2,9 @@ import _root_.scalafix.sbt.ScalafixTestkitPlugin.autoImport.* import _root_.scalafix.sbt.{ScalafixPlugin, ScalafixTestkitPlugin} import com.typesafe.tools.mima.plugin.MimaPlugin import com.typesafe.tools.mima.plugin.MimaPlugin.autoImport.* +import org.scalajs.jsenv.JSEnv +import org.scalajs.jsenv.nodejs.NodeJSEnv +import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport.* import org.typelevel.sbt.TypelevelMimaPlugin.autoImport.* import org.typelevel.sbt.gha.GenerativePlugin.autoImport.* import org.typelevel.sbt.mergify.MergifyPlugin @@ -109,6 +112,7 @@ object AsyncUtilsBuildPlugin extends AutoPlugin { "org.typelevel" %% "cats-tagless-core" % CatsTaglessV, ) ++ (if (scalaVersion.value.startsWith("2")) scala2CompilerPlugins else Nil) }, + jsEnv := nvmJsEnv.value, ) .jvmPlatform(Scala2Versions) .jsPlatform(Scala2Versions) @@ -123,6 +127,7 @@ object AsyncUtilsBuildPlugin extends AutoPlugin { "org.typelevel" %% "cats-effect" % CatsEffect3V, ) ++ (if (scalaVersion.value.startsWith("2")) scala2CompilerPlugins else Nil) }, + jsEnv := nvmJsEnv.value, ) .dependsOn(`async-utils-core`) @@ -328,6 +333,18 @@ object AsyncUtilsBuildPlugin extends AutoPlugin { */ githubWorkflowScalaVersions := Seq("2.13"), githubWorkflowBuildSbtStepPreamble := Nil, + + nodeExecutable := + scala.util.Try { + import scala.sys.process.* + + Process("bash" :: "-c" :: ". $HOME/.nvm/nvm.sh --no-use && nvm which" :: Nil) + .lineStream + .last + } + .toOption + .map(file), + nvmJsEnv := new NodeJSEnv(nodeExecutable.value.map(_.getAbsolutePath).foldLeft(NodeJSEnv.Config())(_ withExecutable _)) ) override def extraProjects: Seq[Project] = autoImport.allProjects @@ -336,4 +353,7 @@ object AsyncUtilsBuildPlugin extends AutoPlugin { def %(vav: Version): ModuleID = oan % vav.toString } + + private lazy val nvmJsEnv: TaskKey[JSEnv] = taskKey("use nvm to find node") + private lazy val nodeExecutable: TaskKey[Option[File]] = taskKey("path to Node executable for JS tasks") }