scala-js / scala-js-dom

Statically typed DOM API for Scala.js
Other
315 stars 160 forks source link

Migrate to mdoc.js #741

Closed zetashift closed 1 year ago

zetashift commented 1 year ago

Currently running against:

root> docs/mdoc
[info] Updating
[info] Resolved  dependencies
[warn]
[warn]  Note: Unresolved dependencies path:
[error] stack trace is suppressed; run last docs / update for the full output
[error] (docs / update) sbt.librarymanagement.ResolveException: Error downloading org.scala-js:scalajs-dom_sjs1_2.12:0.0.0+1310-714813e3+20221
102-2315-SNAPSHOT
[error]   Not found
[error]   Not found
[error]   not found: /home/rishi/.ivy2/local/org.scala-js/scalajs-dom_sjs1_2.12/0.0.0+1310-714813e3+20221102-2315-SNAPSHOT/ivys/ivy.xml
[error]   not found: https://repo1.maven.org/maven2/org/scala-js/scalajs-dom_sjs1_2.12/0.0.0+1310-714813e3+20221102-2315-SNAPSHOT/scalajs-dom_sjs1_2.12-0.0.0+1310-714813e3+20221102-2315-SNAPSHOT.pom
zetashift commented 1 year ago

Do we track the current scala-js-dom version in the build file? I want to inject it in the docs using mdoc, but I can't seem to find the value.

armanbilge commented 1 year ago

We use the sbt dynver plugin, you can use the previousStableVersion setting key to access it. https://github.com/sbt/sbt-dynver/blob/125101baaff68978727f58994ecb9fd781501796/sbtdynver/src/main/scala/sbtdynver/DynVerPlugin.scala#L25

Make sure that the git tags are up to date in your local clone :)

zetashift commented 1 year ago

Next error, I am trying to get interactive scala JS to work, I made a mdoc.properties in the root folder but I get the following error:

bad option: '--intransitive'
Exception in thread "main" java.util.NoSuchElementException
        at java.base/java.util.ServiceLoader$2.next(ServiceLoader.java:1318)
        at java.base/java.util.ServiceLoader$2.next(ServiceLoader.java:1306)
        at java.base/java.util.ServiceLoader$3.next(ServiceLoader.java:1403)
        at mdoc.modifiers.JsModifier.onLoad(JsModifier.scala:102)
        at mdoc.internal.cli.Settings.$anonfun$onLoad$1(Settings.scala:222)
        at mdoc.internal.cli.Settings.$anonfun$onLoad$1$adapted(Settings.scala:222)
        at scala.collection.immutable.List.foreach(List.scala:431)
        at mdoc.internal.cli.Settings.onLoad(Settings.scala:222)
        at mdoc.internal.cli.Context$.fromSettings(Context.scala:50)
        at mdoc.internal.cli.MainOps$.$anonfun$process$1(MainOps.scala:272)
        at metaconfig.Configured.andThen(Configured.scala:45)
        at mdoc.internal.cli.MainOps$.process(MainOps.scala:272)
        at mdoc.MainProcess.process(Main.scala:41)
        at mdoc.MainProcess.process$(Main.scala:38)
        at mdoc.Main$.process(Main.scala:13)
        at mdoc.MainProcess.process(Main.scala:36)
        at mdoc.MainProcess.process$(Main.scala:35)
        at mdoc.Main$.process(Main.scala:13)
        at mdoc.Main$.main(Main.scala:15)
        at mdoc.Main.main(Main.scala)
armanbilge commented 1 year ago

Hum, why did you add mdoc.properties? I haven't needed that in any of my projects using mdoc.js

zetashift commented 1 year ago

Oh oops, I read the instructions for mdoc:js modifiers wrong, thank you :P

zetashift commented 1 year ago

Alright I got console logging working from the docs/mdoc --watch command and then loading the readme.md.

I need to improve the examples I think. Btw how are we deploying the mdoc.js site? Docusaurus seems like overkill

armanbilge commented 1 year ago

🎉

I need to improve the examples I think.

Do you mean the ones in the existing documentation? Maybe, haven't looked at them recently 😂 even if we just start by porting them

Btw how are we deploying the mdoc.js site? Docusaurus seems like overkill

Agree about docusaurus. I have to think about this, open to ideas too. Maybe we can steal the html/theme from the scala-js.org website which uses jekyll.

https://github.com/scala-js/scala-js-website

zetashift commented 1 year ago

Do you mean the ones in the existing documentation? Maybe, haven't looked at them recently joy even if we just start by porting them

I'll try to port them over!

Agree about docusaurus. I have to think about this, open to ideas too. Maybe we can steal the html/theme from the scala-js.org website which uses jekyll.

https://github.com/scala-js/scala-js-website

Yea I think we can just create a stylesheet based off of the main website. At the very least to get us started.

zetashift commented 1 year ago

I am converting the examples and I see this piece of code:

def main(pre: html.Pre) = {
  import scala.concurrent
              .ExecutionContext
              .Implicits
              .global
  import js.Thenable.Implicits._
  val url =
    "https://www.boredapi.com/api/activity"
  val responseText = for {
    response <- dom.fetch(url)
    text <- response.text()
  } yield {
    text
  }
  for (text <- responseText)
    pre.textContent = text
}

Is an ExecutionContext really necessary for using fetch?

armanbilge commented 1 year ago

Strictly speaking, no. It's only necessary if you convert the Promises to Futures.

zetashift commented 1 year ago

Is it correct that Promise can't be flatmapped? Running into this error:

 value flatMap is not a member of scala.scalajs.js.Promise[org.scalaj
s.dom.Response]
    response <- fetch(url)
                ^^^^^^^^^^

The code:

def fetchBoredApi(element: html.Pre) = {
  val url =
    "https://www.boredapi.com/api/activity"

  val responseText = for {
    response <- fetch(url)
    text <- response.text()
  } yield {
    text
  }

  for (text <- responseText)
    pre.textContent = text
}
sjrd commented 1 year ago

Yes, you need a .toFuture

zetashift commented 1 year ago

Closing this to hide my shameful Git skills! New PR will be up soon(TM)