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

Support exoego fork of JsDom JsEnv #2147

Merged
merged 1 commit into from
Nov 26, 2022
Merged
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
3 changes: 3 additions & 0 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ object Deps {

object Scalajs_1 {
val scalajsEnvJsdomNodejs = ivy"org.scala-js::scalajs-env-jsdom-nodejs:1.1.0"
val scalajsEnvExoegoJsdomNodejs = ivy"net.exoego::scalajs-env-jsdom-nodejs:2.1.0"
val scalajsEnvNodejs = ivy"org.scala-js::scalajs-env-nodejs:1.4.0"
val scalajsEnvPhantomjs = ivy"org.scala-js::scalajs-env-phantomjs:1.0.0"
val scalajsSbtTestAdapter = ivy"org.scala-js::scalajs-sbt-test-adapter:1.11.0"
Expand Down Expand Up @@ -672,6 +673,7 @@ object scalajslib extends MillModule {
| val javaxServlet = "org.eclipse.jetty.orbit:javax.servlet:3.0.0.v201112011016"
| val scalajsEnvNodejs = "${formatDep(Deps.Scalajs_1.scalajsEnvNodejs)}"
| val scalajsEnvJsdomNodejs = "${formatDep(Deps.Scalajs_1.scalajsEnvJsdomNodejs)}"
| val scalajsEnvExoegoJsdomNodejs = "${formatDep(Deps.Scalajs_1.scalajsEnvExoegoJsdomNodejs)}"
| val scalajsEnvPhantomJs = "${formatDep(Deps.Scalajs_1.scalajsEnvPhantomjs)}"
| }
|}
Expand Down Expand Up @@ -701,6 +703,7 @@ object scalajslib extends MillModule {
Deps.Scalajs_1.scalajsSbtTestAdapter,
Deps.Scalajs_1.scalajsEnvNodejs,
Deps.Scalajs_1.scalajsEnvJsdomNodejs,
Deps.Scalajs_1.scalajsEnvExoegoJsdomNodejs,
Deps.Scalajs_1.scalajsEnvPhantomjs
)
}
Expand Down
24 changes: 18 additions & 6 deletions scalajslib/src/mill/scalajslib/ScalaJSModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import ch.epfl.scala.bsp4j.{BuildTargetDataKind, ScalaBuildTarget, ScalaPlatform
import mill.api.{Loose, PathRef, Result, internal}
import mill.scalalib.api.ZincWorkerUtil
import mill.scalalib.Lib.resolveDependencies
import mill.scalalib.{DepSyntax, Lib, TestModule}
import mill.scalalib.{Dep, DepSyntax, Lib, TestModule}
import mill.testrunner.TestRunner
import mill.define.{Command, Target, Task}
import mill.scalajslib.{ScalaJSWorker => DeprecatedScalaJSWorker}
Expand Down Expand Up @@ -50,6 +50,21 @@ trait ScalaJSModule extends scalalib.ScalaModule { outer =>
)
}

def scalaJSJsEnvIvyDeps: Target[Agg[Dep]] = T {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm very happy with this change which will speed up downloading dependencies in Scala.js builds, since now Mill downloads only the dependency you need instead of downloading all of them :)

val dep = jsEnvConfig() match {
case _: JsEnvConfig.NodeJs =>
ivy"${ScalaJSBuildInfo.Deps.scalajsEnvNodejs}"
case _: JsEnvConfig.JsDom =>
ivy"${ScalaJSBuildInfo.Deps.scalajsEnvJsdomNodejs}"
case _: JsEnvConfig.ExoegoJsDomNodeJs =>
ivy"${ScalaJSBuildInfo.Deps.scalajsEnvExoegoJsdomNodejs}"
case _: JsEnvConfig.Phantom =>
ivy"${ScalaJSBuildInfo.Deps.scalajsEnvPhantomJs}"
}

Agg(dep)
}

def scalaJSLinkerClasspath: T[Loose.Agg[PathRef]] = T {
val commonDeps = Seq(
ivy"org.scala-js::scalajs-sbt-test-adapter:${scalaJSVersion()}"
Expand All @@ -62,11 +77,8 @@ trait ScalaJSModule extends scalalib.ScalaModule { outer =>
)
case "1" =>
Seq(
ivy"org.scala-js::scalajs-linker:${scalaJSVersion()}",
ivy"${ScalaJSBuildInfo.Deps.scalajsEnvNodejs}",
ivy"${ScalaJSBuildInfo.Deps.scalajsEnvJsdomNodejs}",
ivy"${ScalaJSBuildInfo.Deps.scalajsEnvPhantomJs}"
)
ivy"org.scala-js::scalajs-linker:${scalaJSVersion()}"
) ++ scalaJSJsEnvIvyDeps()
}
// we need to use the scala-library of the currently running mill
resolveDependencies(
Expand Down
7 changes: 7 additions & 0 deletions scalajslib/src/mill/scalajslib/api/ScalaJSApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ sealed trait JsEnvConfig
object JsEnvConfig {
implicit def rwNodeJs: RW[NodeJs] = macroRW
implicit def rwJsDom: RW[JsDom] = macroRW
implicit def rwExoegoJsDomNodeJs: RW[ExoegoJsDomNodeJs] = macroRW
implicit def rwPhantom: RW[Phantom] = macroRW
implicit def rw: RW[JsEnvConfig] = macroRW

Expand All @@ -99,6 +100,12 @@ object JsEnvConfig {
env: Map[String, String] = Map.empty
) extends JsEnvConfig

final case class ExoegoJsDomNodeJs(
executable: String = "node",
args: List[String] = Nil,
env: Map[String, String] = Map.empty
) extends JsEnvConfig

final case class Phantom(
executable: String,
args: List[String],
Expand Down
6 changes: 6 additions & 0 deletions scalajslib/src/mill/scalajslib/worker/ScalaJSWorker.scala
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ private[scalajslib] class ScalaJSWorker extends AutoCloseable {
args = config.args,
env = config.env
)
case config: api.JsEnvConfig.ExoegoJsDomNodeJs =>
workerApi.JsEnvConfig.ExoegoJsDomNodeJs(
executable = config.executable,
args = config.args,
env = config.env
)
case config: api.JsEnvConfig.Phantom =>
workerApi.JsEnvConfig.Phantom(
executable = config.executable,
Expand Down
6 changes: 6 additions & 0 deletions scalajslib/worker-api/src/ScalaJSWorkerApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ private[scalajslib] object JsEnvConfig {
env: Map[String, String]
) extends JsEnvConfig

final case class ExoegoJsDomNodeJs(
executable: String,
args: List[String],
env: Map[String, String]
) extends JsEnvConfig

final case class Phantom(
executable: String,
args: List[String],
Expand Down
3 changes: 3 additions & 0 deletions scalajslib/worker/0.6/src/ScalaJSWorkerImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -197,5 +197,8 @@ class ScalaJSWorkerImpl extends ScalaJSWorkerApi {
.withEnv(config.env)
.withAutoExit(config.autoExit)
)
case _: JsEnvConfig.ExoegoJsDomNodeJs => throw new Exception(
"Not supported on Scala.js 0.6"
)
}
}
7 changes: 7 additions & 0 deletions scalajslib/worker/1/src/ScalaJSWorkerImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,13 @@ class ScalaJSWorkerImpl extends ScalaJSWorkerApi {
.withArgs(config.args)
.withEnv(config.env)
)
case config: JsEnvConfig.ExoegoJsDomNodeJs =>
new net.exoego.jsenv.jsdomnodejs.JSDOMNodeJSEnv(
net.exoego.jsenv.jsdomnodejs.JSDOMNodeJSEnv.Config()
.withExecutable(config.executable)
.withArgs(config.args)
.withEnv(config.env)
)
case config: JsEnvConfig.Phantom =>
new org.scalajs.jsenv.phantomjs.PhantomJSEnv(
org.scalajs.jsenv.phantomjs.PhantomJSEnv.Config()
Expand Down