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

Update to sjs-dom 2.0.0 #23

Closed
Closed
Show file tree
Hide file tree
Changes from 2 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
12 changes: 11 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.12.15, 2.13.6]
scala: [2.12.15, 3.0.2, 2.13.6]
java: [[email protected]]
runs-on: ${{ matrix.os }}
steps:
Expand Down Expand Up @@ -109,6 +109,16 @@ jobs:
tar xf targets.tar
rm targets.tar

- name: Download target directories (3.0.2)
uses: actions/download-artifact@v2
with:
name: target-${{ matrix.os }}-3.0.2-${{ matrix.java }}

- name: Inflate target directories (3.0.2)
run: |
tar xf targets.tar
rm targets.tar

- name: Download target directories (2.13.6)
uses: actions/download-artifact@v2
with:
Expand Down
12 changes: 7 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import JSEnv._

name := "http4s-dom"

ThisBuild / baseVersion := "0.1"
ThisBuild / baseVersion := "0.2"

ThisBuild / organization := "org.http4s"
ThisBuild / organizationName := "http4s.org"
Expand All @@ -39,7 +39,7 @@ ThisBuild / scmInfo := Some(
url("https://github.com/http4s/http4s-dom"),
"https://github.com/http4s/http4s-dom.git"))

ThisBuild / crossScalaVersions := Seq("2.12.15", "2.13.6")
ThisBuild / crossScalaVersions := Seq("2.12.15", "3.0.2", "2.13.6")

replaceCommandAlias("ci", CI.AllCIs.map(_.toString).mkString)
addCommandAlias("ciFirefox", CI.Firefox.toString)
Expand Down Expand Up @@ -108,7 +108,7 @@ ThisBuild / Test / jsEnv := {
val catsEffectVersion = "3.2.9"
val fs2Version = "3.1.5"
val http4sVersion = "0.23.6"
val scalaJSDomVersion = "1.2.0"
val scalaJSDomVersion = "2.0.0-RC1"
val munitVersion = "0.7.29"
val munitCEVersion = "1.0.6"

Expand All @@ -125,7 +125,8 @@ lazy val dom = project
"co.fs2" %%% "fs2-core" % fs2Version,
"org.http4s" %%% "http4s-client" % http4sVersion,
"org.scala-js" %%% "scalajs-dom" % scalaJSDomVersion
)
),
dependencyOverrides += "org.scala-js" %%% "scalajs-dom" % scalaJSDomVersion
Copy link
Member Author

Choose a reason for hiding this comment

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

Workaround pending typelevel/fs2#2681.

)
.enablePlugins(ScalaJSPlugin)

Expand All @@ -139,7 +140,8 @@ lazy val tests = project
libraryDependencies ++= Seq(
"org.scalameta" %%% "munit" % munitVersion % Test,
"org.typelevel" %%% "munit-cats-effect-3" % munitCEVersion % Test
)
),
dependencyOverrides += "org.scala-js" %%% "scalajs-dom" % scalaJSDomVersion
)
.dependsOn(dom)
.enablePlugins(ScalaJSPlugin, BuildInfoPlugin, NoPublishPlugin)
15 changes: 7 additions & 8 deletions dom/src/main/scala/org/http4s/dom/FetchClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@ import cats.effect.syntax.all._
import cats.syntax.all._
import org.http4s.client.Client
import org.http4s.headers.Referer
import org.scalajs.dom.crypto._
import org.scalajs.dom.experimental.AbortController
import org.scalajs.dom.experimental.Fetch
import org.scalajs.dom.experimental.Headers
import org.scalajs.dom.experimental.HttpMethod
import org.scalajs.dom.experimental.RequestInit
import org.scalajs.dom.experimental.{Response => FetchResponse}
import org.scalajs.dom.AbortController
import org.scalajs.dom.Fetch
import org.scalajs.dom.Headers
import org.scalajs.dom.HttpMethod
import org.scalajs.dom.RequestInit
import org.scalajs.dom.{Response => FetchResponse}

import java.util.concurrent.TimeoutException
import scala.concurrent.duration._
Expand All @@ -52,7 +51,7 @@ private[dom] object FetchClient {

init.method = req.method.name.asInstanceOf[HttpMethod]
init.headers = new Headers(toDomHeaders(req.headers))
body.foreach { body => init.body = arrayBuffer2BufferSource(body.toJSArrayBuffer) }
body.foreach { body => init.body = body.toJSArrayBuffer }
init.signal = abortController.signal
mergedOptions.cache.foreach(init.cache = _)
mergedOptions.credentials.foreach(init.credentials = _)
Expand Down
10 changes: 5 additions & 5 deletions dom/src/main/scala/org/http4s/dom/FetchClientBuilder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import cats.effect.Resource
import org.http4s.client.Client
import org.http4s.client.defaults
import org.http4s.internal.BackendBuilder
import org.scalajs.dom.experimental.ReferrerPolicy
import org.scalajs.dom.experimental.RequestCache
import org.scalajs.dom.experimental.RequestCredentials
import org.scalajs.dom.experimental.RequestMode
import org.scalajs.dom.experimental.RequestRedirect
import org.scalajs.dom.ReferrerPolicy
import org.scalajs.dom.RequestCache
import org.scalajs.dom.RequestCredentials
import org.scalajs.dom.RequestMode
import org.scalajs.dom.RequestRedirect

import scala.concurrent.duration._

Expand Down
2 changes: 1 addition & 1 deletion dom/src/main/scala/org/http4s/dom/FetchEventContext.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import cats.effect.SyncIO
import cats.effect.kernel.Async
import cats.effect.std.Supervisor
import cats.syntax.all._
import org.scalajs.dom.experimental.serviceworkers.FetchEvent
import org.scalajs.dom.FetchEvent
import org.typelevel.vault.Key

final class FetchEventContext[F[_]] private (
Expand Down
10 changes: 5 additions & 5 deletions dom/src/main/scala/org/http4s/dom/FetchOptions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
package org.http4s.dom

import cats.effect.SyncIO
import org.scalajs.dom.experimental.ReferrerPolicy
import org.scalajs.dom.experimental.RequestCache
import org.scalajs.dom.experimental.RequestCredentials
import org.scalajs.dom.experimental.RequestMode
import org.scalajs.dom.experimental.RequestRedirect
import org.scalajs.dom.ReferrerPolicy
import org.scalajs.dom.RequestCache
import org.scalajs.dom.RequestCredentials
import org.scalajs.dom.RequestMode
import org.scalajs.dom.RequestRedirect
import org.typelevel.vault

/**
Expand Down
25 changes: 12 additions & 13 deletions dom/src/main/scala/org/http4s/dom/ServiceWorker.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,12 @@ import cats.effect.unsafe.IORuntime
import cats.syntax.all._
import fs2.Chunk
import fs2.Stream
import org.scalajs.dom.crypto._
import org.scalajs.dom.experimental.Body
import org.scalajs.dom.experimental.Fetch
import org.scalajs.dom.experimental.ResponseInit
import org.scalajs.dom.experimental.serviceworkers.FetchEvent
import org.scalajs.dom.experimental.serviceworkers.ServiceWorkerGlobalScope
import org.scalajs.dom.experimental.{Response => DomResponse}
Copy link
Member

Choose a reason for hiding this comment

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

Why were they renamed upstream? Were they experimental on the scala.js side or were they experimental originally on the dom side?

Copy link
Member Author

Choose a reason for hiding this comment

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

They were experimental in DOM. But in general, in SJS-dom we decided to "de-namespace": almost everything is inside the dom.* package now. See this for details.

import org.scalajs.dom.Body
import org.scalajs.dom.Fetch
import org.scalajs.dom.ResponseInit
import org.scalajs.dom.FetchEvent
import org.scalajs.dom.ServiceWorkerGlobalScope
import org.scalajs.dom.{Response => DomResponse}
import org.typelevel.vault.Key

object ServiceWorker {
Expand Down Expand Up @@ -91,15 +90,15 @@ object ServiceWorker {
response <- routes(request)
body <- OptionT.liftF(
OptionT(response.body.chunkAll.filter(_.nonEmpty).compile.last).map { chunk =>
arrayBuffer2BufferSource(chunk.toJSArrayBuffer)
chunk.toJSArrayBuffer
}.value)
} yield new DomResponse(
body.getOrElse(null),
ResponseInit(
response.status.code,
response.status.reason,
toDomHeaders(response.headers)
)
new ResponseInit {
var status = response.status.code
var statusText = response.status.reason
var headers = toDomHeaders(response.headers)
}
)
}

Expand Down
4 changes: 2 additions & 2 deletions tests/src/main/scala/org/http4s/dom/TestServiceWorker.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ package org.http4s.dom

import cats.effect.IO
import cats.effect.unsafe.implicits._
import org.scalajs.dom.experimental.serviceworkers.ExtendableEvent
import org.scalajs.dom.experimental.serviceworkers.ServiceWorkerGlobalScope
import org.scalajs.dom.ExtendableEvent
import org.scalajs.dom.ServiceWorkerGlobalScope

object TestServiceWorker {

Expand Down
3 changes: 1 addition & 2 deletions tests/src/test/scala/org/http4s/dom/DomSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ import org.http4s.client.dsl.io._
import org.http4s.multipart.Multipart
import org.http4s.multipart.Part
import org.http4s.syntax.all._
import org.scalajs.dom.experimental.serviceworkers._
import org.scalajs.dom.raw.Event
import org.scalajs.dom.Event
import org.scalajs.dom.window

import scala.concurrent.duration._
Expand Down