Skip to content

Commit

Permalink
Cross-compiling to Scala 3 and 2.13.6
Browse files Browse the repository at this point in the history
  • Loading branch information
dvreeze committed Jun 26, 2021
1 parent 6b96509 commit f64a08d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
23 changes: 14 additions & 9 deletions build.sbt
Expand Up @@ -8,8 +8,8 @@

import sbtcrossproject.CrossPlugin.autoImport.{crossProject, CrossType}

val scalaVer = "2.13.6"
val crossScalaVer = Seq(scalaVer)
val scalaVer = "3.0.0"
val crossScalaVer = Seq(scalaVer, "2.13.6")

ThisBuild / description := "XPath parser and XPath AST API"
ThisBuild / organization := "eu.cdevreeze.xpathparser"
Expand Down Expand Up @@ -42,11 +42,10 @@ ThisBuild / pomIncludeRepository := { _ => false }
val catsVersion = "2.6.1"

// This is what I wanted to do, but that caused ScalaJS linker errors. Hence the repeated dependencies below.
// ThisBuild / libraryDependencies += "com.lihaoyi" %%% "fastparse" % "2.2.4"
// ThisBuild / libraryDependencies += "org.typelevel" %%% "cats-core" % catsVersion
// ThisBuild / libraryDependencies += "org.typelevel" %%% "cats-parse" % "0.3.4"

ThisBuild / libraryDependencies += "org.scalatest" %%% "scalatest" % "3.1.1" % Test
ThisBuild / libraryDependencies += "org.scalatest" %%% "scalatest" % "3.2.9" % Test

lazy val root = project.in(file("."))
.aggregate(xpathparserJVM, xpathparserJS)
Expand All @@ -63,8 +62,6 @@ lazy val xpathparser = crossProject(JSPlatform, JVMPlatform)
.crossType(CrossType.Full)
.in(file("."))
.jvmSettings(
libraryDependencies += "com.lihaoyi" %%% "fastparse" % "2.2.4",

libraryDependencies += "org.typelevel" %%% "cats-core" % catsVersion,

libraryDependencies += "org.typelevel" %%% "cats-parse" % "0.3.4"
Expand All @@ -77,14 +74,22 @@ lazy val xpathparser = crossProject(JSPlatform, JVMPlatform)

scalaJSUseMainModuleInitializer := false,

libraryDependencies += "com.lihaoyi" %%% "fastparse" % "2.2.4",
libraryDependencies ++= (CrossVersion.partialVersion(scalaVersion.value) match {
case (Some((3, _))) =>
Seq(
// Hopefully for3Use2_13 soon not needed anymore
"org.scala-js" % "scalajs-dom_sjs1_2.13" % "1.1.0",
)
case _ =>
Seq(
"org.scala-js" % "scalajs-dom_sjs1_2.13" % "1.1.0",
)
}),

libraryDependencies += "org.typelevel" %%% "cats-core" % catsVersion,

libraryDependencies += "org.typelevel" %%% "cats-parse" % "0.3.4",

libraryDependencies += "org.scala-js" %%% "scalajs-dom" % "1.1.0",

libraryDependencies += "com.lihaoyi" %%% "pprint" % "0.6.6"

// mimaPreviousArtifacts := Set("eu.cdevreeze.xpathparser" %%% "xpathparser" % "0.6.0")
Expand Down
Expand Up @@ -17,6 +17,7 @@
package eu.cdevreeze.xpathparser.parse

import scala.collection.mutable
import scala.jdk.CollectionConverters._

import cats.parse.{Parser => P}
import eu.cdevreeze.xpathparser.ast.XPathExpr
Expand All @@ -37,8 +38,8 @@ class ParseW3cXPathExpressionsTest extends AnyFunSuite {

// Circumventing propertiesAsScalaMapConverter and its Scala version issues (CollectionConverters moved)
val propMap: mutable.Map[String, String] = mutable.Map.empty
props.forEach { (propName, propValue) =>
propMap.update(propName.toString, propValue.toString)
props.asScala.foreach { case (propName: String, propValue: String) =>
propMap.update(propName, propValue)
}

propMap.toMap.filter(_._1.indexOf("Comment") < 0).toMap
Expand Down
Expand Up @@ -50,7 +50,11 @@ object QName {

/** Creates a `QName` from an optional prefix and a localPart */
def apply(prefixOption: Option[String], localPart: String): QName =
prefixOption map { pref => PrefixedName(pref, localPart) } getOrElse (UnprefixedName(localPart))
prefixOption
.map { pref =>
PrefixedName(pref, localPart)
}
.getOrElse(UnprefixedName(localPart))

/** Creates a `PrefixedName` from a prefix and a localPart */
def apply(prefix: String, localPart: String): QName = PrefixedName(prefix, localPart)
Expand Down Expand Up @@ -83,6 +87,6 @@ object QName {
def unapply(qname: QName): Option[(Option[String], String)] = qname match {
case UnprefixedName(localPart) => Some((None, localPart))
case PrefixedName(prefix, localPart) => Some((Some(prefix), localPart))
case _ => None
case null => None
}
}

0 comments on commit f64a08d

Please sign in to comment.