Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: recognise jdsom #1491

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,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]] =
Expand Down Expand Up @@ -226,6 +230,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"),
Expand Down Expand Up @@ -277,6 +282,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
Expand Down Expand Up @@ -321,6 +328,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
Expand Down Expand Up @@ -795,7 +818,8 @@ object BloopDefaults {

val scalaJsEmitSourceMaps =
ScalaJsKeys.scalaJSEmitSourceMaps.?.value.getOrElse(emptyScalaJs.emitSourceMaps)
val jsdom = Some(false)

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)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"""))
}
)
Original file line number Diff line number Diff line change
@@ -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"