From da5416602ed34f0df0efa05b39ec61d9f2ea2b5b Mon Sep 17 00:00:00 2001 From: plokhotnyuk Date: Sat, 2 Jul 2022 14:15:23 +0200 Subject: [PATCH] Add Scala.js support + update dependencies --- build.sbt | 146 ++++++++++---------- project/plugins.sbt | 3 + src/test/scala/PlayJsonExtensionsTest.scala | 9 +- 3 files changed, 77 insertions(+), 81 deletions(-) diff --git a/build.sbt b/build.sbt index 8e585f1..806222e 100644 --- a/build.sbt +++ b/build.sbt @@ -2,83 +2,79 @@ import scalariform.formatter.preferences._ import com.typesafe.sbt.SbtScalariform.{ScalariformKeys, autoImport} val projectName = "play-json-extensions" -lazy val root = Project(id = projectName, base = file(".")) - -version := "0.42.0" -organization := "ai.x" -name := projectName -scalaVersion := "2.12.10" -crossScalaVersions := Seq("2.12.10", "2.13.1") -useGpg := true -credentials += Credentials(Path.userHome / ".sbt" / "sonatype_credential") -description := "Additional type classes for the play-json serialization library" -organizationName := "x.ai - Magically schedule meetings" - val ghProject = "xdotai/"+projectName -val ghUrl = url( "https://github.com/" + ghProject ) - -homepage := Some( ghUrl ) -startYear := Some(2015) -licenses += ( - "Two-clause BSD-style license", - url( ghUrl + "/blob/master/LICENSE.txt" ) -) -scmInfo := Some( - ScmInfo( ghUrl, "git@github.com:" + ghProject + ".git" ) -) -developers := List( - Developer("cvogt", "Jan Christopher Vogt", "@cvogt", url("https://github.com/cvogt")) -) - -libraryDependencies ++= Seq( - "com.typesafe.play" %% "play-json" % "2.8.1", - "org.scala-lang" % "scala-compiler" % scalaVersion.value % "provided", - "org.scalatest" %% "scalatest" % "3.0.8" % "test" -) +val ghUrl = url("https://github.com/" + ghProject) -resolvers ++= Seq( - Resolver.sonatypeRepo("releases"), - Resolver.sonatypeRepo("snapshots") +val sharedSettings = Seq( + version := "0.43.0-SNAPSHOT", + organization := "ai.x", + name := projectName, + scalaVersion := "2.12.10", + crossScalaVersions := Seq("2.12.10", "2.13.1"), + useGpg := true, + credentials += Credentials(Path.userHome / ".sbt" / "sonatype_credential"), + description := "Additional type classes for the play-json serialization library", + organizationName := "x.ai - Magically schedule meetings", + homepage := Some(ghUrl), + startYear := Some(2015), + licenses += ("Two-clause BSD-style license", url(ghUrl + "/blob/master/LICENSE.txt")), + scmInfo := Some(ScmInfo(ghUrl, "git@github.com:" + ghProject + ".git" )), + developers := List( + Developer("cvogt", "Jan Christopher Vogt", "@cvogt", url("https://github.com/cvogt")) + ), + libraryDependencies ++= Seq( + "com.typesafe.play" %%% "play-json" % "2.9.2", + "org.scala-lang" % "scala-compiler" % scalaVersion.value % "provided", + "org.scalatest" %%% "scalatest" % "3.2.12" % "test" + ), + resolvers ++= Seq( + Resolver.sonatypeRepo("releases"), + Resolver.sonatypeRepo("snapshots") + ), + scalacOptions ++= Seq( + "-feature", "-deprecation", "-unchecked", + "-language:experimental.macros", + CrossVersion.partialVersion(scalaVersion.value) match { + case Some((2, 11)) => "-Ywarn-unused-import" + case _ => "-Ywarn-unused:imports" + }, + "-Xfatal-warnings" + ), + testOptions in Test += Tests.Argument(TestFrameworks.ScalaTest, "-oFD"), + parallelExecution := false, // <- until TMap thread-safety issues are resolved + scalacOptions in (Compile, doc) ++= Seq( + "-doc-title", name.value, + "-doc-version", version.value, + "-doc-footer", projectName+" is developed by x.ai.", + "-sourcepath", (sourceDirectory in Compile).value.getPath, // needed for scaladoc to strip the location of the linked source path + "-doc-source-url", ghUrl+"/blob/"+version.value+"/src/main€{FILE_PATH}.scala", + "-implicits", + "-diagrams", // requires graphviz + "-groups" + ), + scalariformPreferences := scalariformPreferences.value + .setPreference(AlignParameters, true) + .setPreference(AlignArguments, true) + .setPreference(AlignSingleLineCaseStatements, true) + .setPreference(MultilineScaladocCommentsStartOnFirstLine, true) + .setPreference(SpaceInsideParentheses, true) + .setPreference(SpacesWithinPatternBinders, true) + .setPreference(SpacesAroundMultiImports, true) + .setPreference(DanglingCloseParenthesis, Preserve) + .setPreference(DoubleIndentConstructorArguments, true) ) -scalacOptions ++= Seq( - "-feature", "-deprecation", "-unchecked", - "-language:experimental.macros", - CrossVersion.partialVersion(scalaVersion.value) match { - case Some((2, 11)) => "-Ywarn-unused-import" - case _ => "-Ywarn-unused:imports" - }, - "-Xfatal-warnings" -) - -testOptions in Test += Tests.Argument(TestFrameworks.ScalaTest, "-oFD") -parallelExecution := false // <- until TMap thread-safety issues are resolved - -scalacOptions in (Compile, doc) ++= Seq( - "-doc-title", name.value, - "-doc-version", version.value, - "-doc-footer", projectName+" is developed by x.ai.", - "-sourcepath", (sourceDirectory in Compile).value.getPath, // needed for scaladoc to strip the location of the linked source path - "-doc-source-url", ghUrl+"/blob/"+version.value+"/src/main€{FILE_PATH}.scala", - "-implicits", - "-diagrams", // requires graphviz - "-groups" -) - -publishTo := sonatypePublishTo.value - -publishMavenStyle := true -publishArtifact in Test := false -pomIncludeRepository := { _ => false } - -scalariformPreferences := scalariformPreferences.value - .setPreference(AlignParameters, true) - .setPreference(AlignArguments, true) - .setPreference(AlignSingleLineCaseStatements, true) - .setPreference(MultilineScaladocCommentsStartOnFirstLine, true) - .setPreference(SpaceInsideParentheses, true) - .setPreference(SpacesWithinPatternBinders, true) - .setPreference(SpacesAroundMultiImports, true) - .setPreference(DanglingCloseParenthesis, Preserve) -.setPreference(DoubleIndentConstructorArguments, true) +lazy val root = Project(id = projectName, base = file(".")) + .aggregate(`play-json-extensions`.js, `play-json-extensions`.jvm) + .settings(sharedSettings) + .settings(publish / skip := true) +lazy val `play-json-extensions` = crossProject(JSPlatform, JVMPlatform) + .in(file(".")) + .settings(sharedSettings) + .settings( + publishTo := sonatypePublishTo.value, + publishMavenStyle := true, + publishArtifact in Test := false, + pomIncludeRepository := { _ => false } + ) diff --git a/project/plugins.sbt b/project/plugins.sbt index a372bb2..71d7f01 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,3 +1,6 @@ +addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.6.3") +addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.2.0") +addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.10.1") addSbtPlugin("org.scalariform" % "sbt-scalariform" % "1.8.2") addSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.0.3") addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "2.3") diff --git a/src/test/scala/PlayJsonExtensionsTest.scala b/src/test/scala/PlayJsonExtensionsTest.scala index d3125dd..f4dac01 100644 --- a/src/test/scala/PlayJsonExtensionsTest.scala +++ b/src/test/scala/PlayJsonExtensionsTest.scala @@ -1,13 +1,10 @@ package ai.x.test.play.json -import org.scalatest.FunSuite - import _root_.play.api.libs.json._ - import ai.x.play.json._ import ai.x.play.json.tuples._ - import ai.x.play.json.Encoders._ +import org.scalatest.funsuite.AnyFunSuite final case class RecursiveClass( o: Option[RecursiveClass], s: String ) object RecursiveClass { @@ -62,7 +59,7 @@ case class Ua( i: Int ) extends OP case class Unknown( json: JsValue ) extends OP case class Uzzzzzzz( s: String ) extends OP -class PlayJsonExtensionsTest extends FunSuite { +class PlayJsonExtensionsTest extends AnyFunSuite { test( "de/serialize symbol fields" ) { case class SymbolFieldsClass( ### :Int, $$$: Double, %%% : Boolean, -+-+ : Seq[Int] ) implicit val fmt1 = Jsonx.formatCaseClass[SymbolFieldsClass] @@ -332,7 +329,7 @@ abstract class JsonTestClasses { case class ClassOuter2( outer: List[ListOuter2] ) object ClassOuter2 { implicit def jsonFormat = Jsonx.formatCaseClass[ClassOuter2] } } -class JsonTests extends FunSuite { +class JsonTests extends AnyFunSuite { test( "json optionWithNull" ) { object JsonTestClasses extends JsonTestClasses { implicit def option[A]( implicit reads: Reads[A] ): Reads[Option[A]] = implicits.optionWithNull[A]