diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 02e0f5ea8990..f3a7296032d2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 @@ -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 diff --git a/build.sbt b/build.sbt index 602d30e38135..cde65c116972 100644 --- a/build.sbt +++ b/build.sbt @@ -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" @@ -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 @@ -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) @@ -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")) @@ -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) @@ -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")) @@ -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", @@ -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")) @@ -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")) @@ -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) @@ -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)) @@ -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) diff --git a/core/js/src/main/scala/zio/TaskPlatformSpecific.scala b/core/js/src/main/scala/zio/TaskPlatformSpecific.scala index c3255b0b2ade..96ffd363f18d 100644 --- a/core/js/src/main/scala/zio/TaskPlatformSpecific.scala +++ b/core/js/src/main/scala/zio/TaskPlatformSpecific.scala @@ -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 => @@ -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)) } } diff --git a/core/js/src/main/scala/zio/ZIOPlatformSpecific.scala b/core/js/src/main/scala/zio/ZIOPlatformSpecific.scala index 74d512664f35..aea716b7855b 100644 --- a/core/js/src/main/scala/zio/ZIOPlatformSpecific.scala +++ b/core/js/src/main/scala/zio/ZIOPlatformSpecific.scala @@ -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] => @@ -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)) } }