From 0c735c3a7bc7da2c410bc4bf245335a2e3331acf Mon Sep 17 00:00:00 2001 From: Anton Sviridov Date: Fri, 16 Apr 2021 08:49:13 +0100 Subject: [PATCH 1/2] WIP: recognise jdsom --- .../bloop/integrations/sbt/SbtBloop.scala | 27 ++++++++++++++++++- .../src/sbt-test/sbt-bloop/scala-js/build.sbt | 4 +++ .../sbt-bloop/scala-js/project/plugins.sbt | 1 + 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/integrations/sbt-bloop/src/main/scala/bloop/integrations/sbt/SbtBloop.scala b/integrations/sbt-bloop/src/main/scala/bloop/integrations/sbt/SbtBloop.scala index 2cc9d4cc01..88c4cb8d5e 100644 --- a/integrations/sbt-bloop/src/main/scala/bloop/integrations/sbt/SbtBloop.scala +++ b/integrations/sbt-bloop/src/main/scala/bloop/integrations/sbt/SbtBloop.scala @@ -80,10 +80,14 @@ object BloopKeys { taskKey[CompileResult]("Offload compilation to Bloop via BSP.") val bloopAnalysisOut: TaskKey[Option[File]] = taskKey[Option[File]]("User-defined location for the incremental analysis file") + val bloopScalaJSStage: SettingKey[Option[String]] = settingKey[Option[String]]("Scala.js-independent definition of `scalaJSStage`") val bloopScalaJSModuleKind: SettingKey[Option[String]] = settingKey[Option[String]]("Scala.js-independent definition of `scalaJSModuleKind`") + val bloopScalaJSEnv: SettingKey[Option[String]] = + settingKey[Option[String]]("Scala.js-independent definition of `jsEnv`") + val bloopMainClass: SettingKey[Option[String]] = settingKey[Option[String]]("The main class to run a bloop target") val bloopSupportedConfigurations: SettingKey[Seq[Configuration]] = @@ -219,6 +223,7 @@ object BloopDefaults { List( BloopKeys.bloopScalaJSStage := findOutScalaJsStage.value, BloopKeys.bloopScalaJSModuleKind := findOutScalaJsModuleKind.value, + BloopKeys.bloopScalaJSEnv := checkScalaJsDomEnv.value, // Override checksums so that `updates` don't check md5 for all jars Keys.checksums in Keys.update := Vector("sha1"), Keys.checksums in Keys.updateClassifiers := Vector("sha1"), @@ -269,6 +274,8 @@ object BloopDefaults { private final val CommonJSModule = "CommonJSModule" private final val ESModule = "ESModule" + private final val JsDomEnv = "JsDom" + /** * Create a "proxy" for a setting that will allow us to inspect its value even though * its not accessed from the same classloader. This is required to access Scala.js @@ -313,6 +320,22 @@ object BloopDefaults { } } + def checkScalaJsDomEnv: Def.Initialize[Option[String]] = Def.settingDyn { + try { + val stageClass = Class.forName("org.scalajs.jsenv.JSEnv") + val stageSetting = proxyForSetting("jsEnv", stageClass) + + Def.setting { + val name = stageSetting.value.toString + + if (name.contains("JSDOMNodeJSEnv")) Some(JsDomEnv) + else None + } + } catch { + case _: ClassNotFoundException => Def.setting(None) + } + } + def bloopTargetDir: Def.Initialize[File] = Def.setting { val project = Keys.thisProject.value val bloopConfigDir = BloopKeys.bloopConfigDir.value @@ -776,7 +799,9 @@ object BloopDefaults { val scalaJsEmitSourceMaps = ScalaJsKeys.scalaJSEmitSourceMaps.?.value.getOrElse(emptyScalaJs.emitSourceMaps) - val jsdom = Some(false) + + // val jsEnv = ScalaJsKeys + val jsdom = BloopKeys.bloopScalaJSEnv.value.map(_ == JsDomEnv) val jsConfig = Config.JsConfig(scalaJsVersion, scalaJsStage, scalaJsModule, scalaJsEmitSourceMaps, jsdom, None, None, emptyScalaJs.toolchain) Config.Platform.Js(jsConfig, mainClass) } diff --git a/integrations/sbt-bloop/src/sbt-test/sbt-bloop/scala-js/build.sbt b/integrations/sbt-bloop/src/sbt-test/sbt-bloop/scala-js/build.sbt index 29b513bbd2..35a69ef7f6 100644 --- a/integrations/sbt-bloop/src/sbt-test/sbt-bloop/scala-js/build.sbt +++ b/integrations/sbt-bloop/src/sbt-test/sbt-bloop/scala-js/build.sbt @@ -1,5 +1,8 @@ val jsProject = project .enablePlugins(ScalaJSPlugin) + .settings( + jsEnv := new org.scalajs.jsenv.jsdomnodejs.JSDOMNodeJSEnv() + ) .settings( InputKey[Unit]("check") := { val expected = complete.DefaultParsers.spaceDelimited("").parsed.head @@ -8,5 +11,6 @@ val jsProject = project assert(lines.contains(s""""platform":{"name":"$expected"""")) assert(lines.contains(s""""mode":"debug"""")) assert(lines.contains(s""""version":"0.6.28"""")) + assert(lines.contains(s""""jsdom": true""")) } ) diff --git a/integrations/sbt-bloop/src/sbt-test/sbt-bloop/scala-js/project/plugins.sbt b/integrations/sbt-bloop/src/sbt-test/sbt-bloop/scala-js/project/plugins.sbt index fca381ca0d..b2b27f1bc6 100644 --- a/integrations/sbt-bloop/src/sbt-test/sbt-bloop/scala-js/project/plugins.sbt +++ b/integrations/sbt-bloop/src/sbt-test/sbt-bloop/scala-js/project/plugins.sbt @@ -1,2 +1,3 @@ addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % sys.props.apply("plugin.version")) addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.28") +libraryDependencies += "org.scala-js" %% "scalajs-env-jsdom-nodejs" % "1.1.0" From 9fa4162b82907adfa510a4c2d905be3886c2e3c7 Mon Sep 17 00:00:00 2001 From: Anton Sviridov Date: Fri, 16 Apr 2021 09:11:11 +0100 Subject: [PATCH 2/2] formatting, my old nemesis --- .../src/main/scala/bloop/integrations/sbt/SbtBloop.scala | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/integrations/sbt-bloop/src/main/scala/bloop/integrations/sbt/SbtBloop.scala b/integrations/sbt-bloop/src/main/scala/bloop/integrations/sbt/SbtBloop.scala index 88c4cb8d5e..c8df8af9c8 100644 --- a/integrations/sbt-bloop/src/main/scala/bloop/integrations/sbt/SbtBloop.scala +++ b/integrations/sbt-bloop/src/main/scala/bloop/integrations/sbt/SbtBloop.scala @@ -80,14 +80,14 @@ object BloopKeys { taskKey[CompileResult]("Offload compilation to Bloop via BSP.") val bloopAnalysisOut: TaskKey[Option[File]] = taskKey[Option[File]]("User-defined location for the incremental analysis file") - + val bloopScalaJSStage: SettingKey[Option[String]] = settingKey[Option[String]]("Scala.js-independent definition of `scalaJSStage`") val bloopScalaJSModuleKind: SettingKey[Option[String]] = settingKey[Option[String]]("Scala.js-independent definition of `scalaJSModuleKind`") - val bloopScalaJSEnv: SettingKey[Option[String]] = + val bloopScalaJSEnv: SettingKey[Option[String]] = settingKey[Option[String]]("Scala.js-independent definition of `jsEnv`") - + val bloopMainClass: SettingKey[Option[String]] = settingKey[Option[String]]("The main class to run a bloop target") val bloopSupportedConfigurations: SettingKey[Seq[Configuration]] = @@ -800,7 +800,6 @@ object BloopDefaults { val scalaJsEmitSourceMaps = ScalaJsKeys.scalaJSEmitSourceMaps.?.value.getOrElse(emptyScalaJs.emitSourceMaps) - // val jsEnv = ScalaJsKeys val jsdom = BloopKeys.bloopScalaJSEnv.value.map(_ == JsDomEnv) val jsConfig = Config.JsConfig(scalaJsVersion, scalaJsStage, scalaJsModule, scalaJsEmitSourceMaps, jsdom, None, None, emptyScalaJs.toolchain) Config.Platform.Js(jsConfig, mainClass)