Skip to content

Commit

Permalink
update magnolia. drop scala-js
Browse files Browse the repository at this point in the history
  • Loading branch information
xuwei-k committed Apr 27, 2024
1 parent 9f68251 commit 2124bca
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ jobs:
with:
java-version: 8
distribution: temurin
- run: sbt -v scalafmtSbtCheck scalafmtCheckAll "+ scalapropsMagnoliaJVM/test" "+ scalapropsMagnoliaJS/test"
- run: sbt -v scalafmtSbtCheck scalafmtCheckAll "+ test"
8 changes: 0 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,10 @@

### build.sbt

for jvm

```scala
libraryDependencies += "com.github.scalaprops" %% "scalaprops-magnolia" % "0.7.0"
```

for scala-js

```scala
libraryDependencies += "com.github.scalaprops" %%% "scalaprops-magnolia" % "0.7.0"
```

### example

Import the content of `scalaprop.ScalapropsMagnolia` close to where you want `scalaprops.Gen` type classes to be automatically available for case classes / sealed hierarchies,
Expand Down
32 changes: 5 additions & 27 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import sbtrelease._
import ReleaseStateTransformations._
import sbtcrossproject.CrossPlugin.autoImport.{crossProject, CrossType}

ThisBuild / onChangedBuildSource := ReloadOnSourceChanges

Expand Down Expand Up @@ -63,8 +62,7 @@ lazy val commonSettings = nocomma {
)
}

lazy val scalapropsMagnolia = crossProject(JVMPlatform, JSPlatform)
.crossType(CrossType.Pure)
lazy val scalapropsMagnolia = project
.in(file("."))
.settings(
scalapropsCoreSettings,
Expand Down Expand Up @@ -109,9 +107,10 @@ lazy val scalapropsMagnolia = crossProject(JVMPlatform, JSPlatform)
}
scalapropsVersion := "0.9.1"
libraryDependencies ++= Seq(
"com.propensive" %%% "magnolia" % "0.14.5",
"com.github.scalaprops" %%% "scalaprops-gen" % scalapropsVersion.value,
"com.github.scalaprops" %%% "scalaprops" % scalapropsVersion.value % "test"
"org.scala-lang" % "scala-reflect" % scalaVersion.value % Provided,
"com.softwaremill.magnolia1_2" %% "magnolia" % "1.1.9",
"com.github.scalaprops" %% "scalaprops-gen" % scalapropsVersion.value,
"com.github.scalaprops" %% "scalaprops" % scalapropsVersion.value % "test"
)
(Compile / doc / scalacOptions) ++= {
val tag = tagOrHash.value
Expand All @@ -123,24 +122,3 @@ lazy val scalapropsMagnolia = crossProject(JVMPlatform, JSPlatform)
)
}
})
.jsSettings(
scalacOptions += {
val a = (LocalRootProject / baseDirectory).value.toURI.toString
val g = "https://raw.githubusercontent.com/scalaprops/scalaprops-magnolia/" + tagOrHash.value
s"-P:scalajs:mapSourceURI:$a->$g/"
}
)

lazy val notPublish = nocomma {
publishArtifact := false
publish := {}
publishLocal := {}
PgpKeys.publishSigned := {}
PgpKeys.publishLocalSigned := {}
}

commonSettings
notPublish
name := "root"
Compile / sources := Nil
Test / sources := Nil
2 changes: 0 additions & 2 deletions project/plugin.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ addSbtPlugin("com.github.scalaprops" % "sbt-scalaprops" % "0.5.0")
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.21")
addSbtPlugin("com.github.sbt" % "sbt-release" % "1.4.0")
addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.2.1")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.16.0")
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.3.2")
addSbtPlugin("com.eed3si9n" % "sbt-nocomma" % "0.1.1")

scalacOptions ++= Seq(
Expand Down
6 changes: 3 additions & 3 deletions src/main/scala/scalaprops/ScalapropsMagnoliaCogen.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package scalaprops

import magnolia.{CaseClass, Magnolia, SealedTrait}
import magnolia1.{CaseClass, Magnolia, SealedTrait}

object ScalapropsMagnoliaCogen {
type Typeclass[T] = scalaprops.Cogen[T]

def combine[T](ctx: CaseClass[Typeclass, T]): Typeclass[T] =
def join[T](ctx: CaseClass[Typeclass, T]): Typeclass[T] =
new Cogen[T] {
def cogen[B](t: T, g: CogenState[B]) = {
ctx.parameters.zipWithIndex.foldLeft(g) { case (state, (p, i)) =>
Expand All @@ -14,7 +14,7 @@ object ScalapropsMagnoliaCogen {
}
}

def dispatch[T](ctx: SealedTrait[Typeclass, T]): Typeclass[T] =
def split[T](ctx: SealedTrait[Typeclass, T]): Typeclass[T] =
new Cogen[T] {
def cogen[B](t: T, g: CogenState[B]) = {
val index = ctx.subtypes.indexWhere(_.cast.isDefinedAt(t))
Expand Down
6 changes: 3 additions & 3 deletions src/main/scala/scalaprops/ScalapropsMagnoliaGen.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package scalaprops

import magnolia.{CaseClass, Magnolia, SealedTrait}
import magnolia1.{CaseClass, Magnolia, SealedTrait}

object ScalapropsMagnoliaGen {
type Typeclass[T] = scalaprops.Gen[T]

def combine[T](ctx: CaseClass[Gen, T]): Gen[T] =
def join[T](ctx: CaseClass[Gen, T]): Gen[T] =
Gen.gen[T] { (size, rand) =>
var r = rand
val result = ctx.construct { p =>
Expand All @@ -17,7 +17,7 @@ object ScalapropsMagnoliaGen {
r -> result
}

def dispatch[T](ctx: SealedTrait[Gen, T]): Gen[T] = {
def split[T](ctx: SealedTrait[Gen, T]): Gen[T] = {
val gs: Seq[Gen[T]] = ctx.subtypes.map { x => x.typeclass.asInstanceOf[Gen[T]] }
Gen.choose(0, gs.size - 1).flatMap(gs)
}
Expand Down

0 comments on commit 2124bca

Please sign in to comment.