Skip to content

Commit

Permalink
Upgrade to Scala 3 and publish for Scala.js (zio#5101)
Browse files Browse the repository at this point in the history
  • Loading branch information
ghostdogpr committed May 16, 2021
1 parent 406cb0c commit 4fc7efd
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 19 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
fail-fast: false
matrix:
java: ['adopt@1.8', 'adopt@1.11']
scala: ['2.11.12', '2.12.13', '2.13.5', '3.0.0-RC3']
scala: ['2.11.12', '2.12.13', '2.13.5', '3.0.0']
platform: ['JVM', 'JS', 'Native']
steps:
- name: Checkout current branch
Expand All @@ -66,9 +66,9 @@ jobs:
- name: Test 2.12.x and 2.13.x
if: ${{ !startsWith(matrix.scala, '2.11.') && !startsWith(matrix.scala, '3.0.') && matrix.platform != 'Native' }}
run: sbt ++${{ matrix.scala }}! test${{ matrix.platform }}
- name: Test 3.x (JVM only)
if: ${{ startsWith(matrix.scala, '3.0.') && contains(matrix.java, '1.8') && matrix.platform == 'JVM' }}
run: sbt ++${{ matrix.scala }}! testJVMDotty
- name: Test 3.x
if: ${{ startsWith(matrix.scala, '3.0.') && contains(matrix.java, '1.8') && matrix.platform != 'Native' }}
run: sbt ++${{ matrix.scala }}! test${{ matrix.platform }}Dotty
- name: Test native
if: ${{ !startsWith(matrix.scala, '3.0.') && matrix.platform == 'Native' }}
run: sbt ++${{ matrix.scala }}! testNative
Expand Down
22 changes: 19 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ addCommandAlias(
"testJVMDotty",
";coreTestsJVM/test;stacktracerJVM/test:compile;streamsTestsJVM/test;testTestsJVM/test;testMagnoliaTestsJVM/test;testRefinedJVM/test;testRunnerJVM/test:run;examplesJVM/test:compile"
)
addCommandAlias(
"testJSDotty",
";coreTestsJS/test;stacktracerJS/test;streamsTestsJS/test;testTestsJS/test;testRefinedJS/test;examplesJS/test:compile"
)
addCommandAlias(
"testJVM211",
";coreTestsJVM/test;stacktracerJVM/test;streamsTestsJVM/test;testTestsJVM/test;testRunnerJVM/test:run;examplesJVM/test:compile;macrosTestsJVM/test"
Expand Down Expand Up @@ -126,7 +130,7 @@ lazy val core = crossProject(JSPlatform, JVMPlatform, NativePlatform)
.settings(stdSettings("zio"))
.settings(crossProjectSettings)
.settings(buildInfoSettings("zio"))
.settings(libraryDependencies += "dev.zio" %%% "izumi-reflect" % "1.1.1")
.settings(libraryDependencies += "dev.zio" %%% "izumi-reflect" % "1.1.2")
.enablePlugins(BuildInfoPlugin)

lazy val coreJVM = core.jvm
Expand All @@ -135,6 +139,7 @@ lazy val coreJVM = core.jvm
.settings(mimaSettings(failOnProblem = true))

lazy val coreJS = core.js
.settings(dottySettings)

lazy val coreNative = core.native
.settings(nativeSettings)
Expand Down Expand Up @@ -165,6 +170,7 @@ lazy val coreTestsJVM = coreTests.jvm
.settings(replSettings)

lazy val coreTestsJS = coreTests.js
.settings(dottySettings)

lazy val macros = crossProject(JSPlatform, JVMPlatform)
.in(file("macros"))
Expand Down Expand Up @@ -208,6 +214,7 @@ lazy val streamsJVM = streams.jvm
.settings(mimaSettings(failOnProblem = false))

lazy val streamsJS = streams.js
.settings(dottySettings)

lazy val streamsNative = streams.native
.settings(nativeSettings)
Expand All @@ -232,6 +239,7 @@ lazy val streamsTestsJVM = streamsTests.jvm
.settings(dottySettings)

lazy val streamsTestsJS = streamsTests.js
.settings(dottySettings)

lazy val test = crossProject(JSPlatform, JVMPlatform, NativePlatform)
.in(file("test"))
Expand All @@ -252,6 +260,7 @@ lazy val testJVM = test.jvm
// No bincompat on zio-test yet
.settings(mimaSettings(failOnProblem = false))
lazy val testJS = test.js
.settings(dottySettings)
.settings(
libraryDependencies ++= List(
"io.github.cquiroz" %%% "scala-java-time" % "2.3.0",
Expand All @@ -275,7 +284,7 @@ lazy val testTests = crossProject(JSPlatform, JVMPlatform)
.enablePlugins(BuildInfoPlugin)

lazy val testTestsJVM = testTests.jvm.settings(dottySettings)
lazy val testTestsJS = testTests.js
lazy val testTestsJS = testTests.js.settings(dottySettings)

lazy val testMagnolia = crossProject(JVMPlatform, JSPlatform)
.in(file("test-magnolia"))
Expand Down Expand Up @@ -341,6 +350,7 @@ lazy val testRefined = crossProject(JVMPlatform, JSPlatform)
lazy val testRefinedJVM = testRefined.jvm
.settings(dottySettings)
lazy val testRefinedJS = testRefined.js
.settings(dottySettings)

lazy val stacktracer = crossProject(JSPlatform, JVMPlatform, NativePlatform)
.in(file("stacktracer"))
Expand All @@ -350,6 +360,7 @@ lazy val stacktracer = crossProject(JSPlatform, JVMPlatform, NativePlatform)
.enablePlugins(BuildInfoPlugin)

lazy val stacktracerJS = stacktracer.js
.settings(dottySettings)
lazy val stacktracerJVM = stacktracer.jvm
.settings(dottySettings)
.settings(replSettings)
Expand All @@ -370,7 +381,11 @@ lazy val testRunnerJVM = testRunner.jvm
.settings(dottySettings)
.settings(libraryDependencies ++= Seq("org.scala-sbt" % "test-interface" % "1.0"))
lazy val testRunnerJS = testRunner.js
.settings(libraryDependencies ++= Seq("org.scala-js" %% "scalajs-test-interface" % scalaJSVersion))
.settings(
libraryDependencies ++= Seq(
("org.scala-js" %% "scalajs-test-interface" % scalaJSVersion).cross(CrossVersion.for3Use2_13)
)
)
lazy val testRunnerNative = testRunner.native
.settings(nativeSettings)
.settings(libraryDependencies ++= Seq("org.scala-native" %%% "test-interface" % nativeVersion))
Expand Down Expand Up @@ -444,6 +459,7 @@ lazy val examples = crossProject(JVMPlatform, JSPlatform)
.dependsOn(macros, testRunner)

lazy val examplesJS = examples.js
.settings(dottySettings)
lazy val examplesJVM = examples.jvm
.settings(dottySettings)
.dependsOn(testJunitRunnerJVM)
Expand Down
14 changes: 8 additions & 6 deletions core/js/src/main/scala/zio/TaskPlatformSpecific.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package zio

import scala.scalajs.js
import scala.scalajs.js.{Promise => JSPromise}
import scala.scalajs.js.{Function1, Promise => JSPromise, Thenable, |}

private[zio] trait TaskPlatformSpecific { self: Task.type =>

Expand All @@ -26,14 +26,16 @@ private[zio] trait TaskPlatformSpecific { self: Task.type =>
*/
def fromPromiseJS[A](promise: => JSPromise[A]): Task[A] =
self.effectAsync { callback =>
promise.`then`[Unit](
a => callback(UIO.succeedNow(a)),
js.defined { (e: Any) =>
val onFulfilled: Function1[A, Unit | Thenable[Unit]] = new scala.Function1[A, Unit | Thenable[Unit]] {
def apply(a: A): Unit | Thenable[Unit] = callback(UIO.succeedNow(a))
}
val onRejected: Function1[Any, Unit | Thenable[Unit]] = new scala.Function1[Any, Unit | Thenable[Unit]] {
def apply(e: Any): Unit | Thenable[Unit] =
callback(IO.fail(e match {
case t: Throwable => t
case _ => js.JavaScriptException(e)
}))
}
)
}
promise.`then`[Unit](onFulfilled, js.defined(onRejected))
}
}
14 changes: 8 additions & 6 deletions core/js/src/main/scala/zio/ZIOPlatformSpecific.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package zio

import scala.scalajs.js
import scala.scalajs.js.{Promise => JSPromise}
import scala.scalajs.js.{Function1, Promise => JSPromise, Thenable, |}

private[zio] trait ZIOPlatformSpecific[-R, +E, +A] { self: ZIO[R, E, A] =>

Expand All @@ -42,14 +42,16 @@ private[zio] trait ZIOCompanionPlatformSpecific { self: ZIO.type =>
*/
def fromPromiseJS[A](promise: => JSPromise[A]): Task[A] =
self.effectAsync { callback =>
promise.`then`[Unit](
a => callback(UIO.succeedNow(a)),
js.defined { (e: Any) =>
val onFulfilled: Function1[A, Unit | Thenable[Unit]] = new scala.Function1[A, Unit | Thenable[Unit]] {
def apply(a: A): Unit | Thenable[Unit] = callback(UIO.succeedNow(a))
}
val onRejected: Function1[Any, Unit | Thenable[Unit]] = new scala.Function1[Any, Unit | Thenable[Unit]] {
def apply(e: Any): Unit | Thenable[Unit] =
callback(IO.fail(e match {
case t: Throwable => t
case _ => js.JavaScriptException(e)
}))
}
)
}
promise.`then`[Unit](onFulfilled, js.defined(onRejected))
}
}

0 comments on commit 4fc7efd

Please sign in to comment.