Skip to content

Commit

Permalink
Port to Scala 2.13 (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
Atry authored Feb 3, 2023
1 parent 2b881ee commit a865197
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 9 deletions.
15 changes: 11 additions & 4 deletions .github/workflows/scala.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,17 @@ jobs:
strategy:
fail-fast: false
matrix:
scala:
- 2.10.7
- 2.11.12
- 2.12.11
include:
- scala: 2.11.12
sbt-args: --addPluginSbtFile=project/plugins.sbt.scala-js.1.x
- scala: 2.12.11
sbt-args: --addPluginSbtFile=project/plugins.sbt.scala-js.1.x
- scala: 2.13.4
sbt-args: --addPluginSbtFile=project/plugins.sbt.scala-js.1.x
- scala: 2.10.7
- scala: 2.11.12
- scala: 2.12.11
- scala: 2.13.4

steps:
- uses: actions/checkout@v3
Expand Down
3 changes: 2 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ fork in Global in compile := true

description in ThisBuild := "A collection of Scala language extension for specific domains."

lazy val each = crossProject.crossType(CrossType.Pure)
lazy val each = sbtcrossproject.CrossPlugin.autoImport.crossProject
.crossType(sbtcrossproject.CrossPlugin.autoImport.CrossType.Pure)

lazy val eachJVM = each.jvm

Expand Down
18 changes: 16 additions & 2 deletions each/build.sbt.shared
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,25 @@ libraryDependencies ++= {
}
}

addCompilerPlugin("org.scalamacros" % "paradise" % "2.1.1" cross CrossVersion.full)
libraryDependencies ++= PartialFunction.condOpt(VersionNumber(scalaVersion.value).matchesSemVer(SemanticSelector("<2.13"))) {
case true =>
compilerPlugin("org.scalamacros" % "paradise" % "2.1.1" cross CrossVersion.full)
}

scalacOptions ++= PartialFunction.condOpt(scalaBinaryVersion.value) {
case "2.13" =>
"-Ymacro-annotations"
}

libraryDependencies += "org.scala-lang" % "scala-compiler" % scalaVersion.value % Provided

libraryDependencies += "com.thoughtworks.sde" %%% "core" % "3.3.2"
libraryDependencies += {
if (scalaBinaryVersion.value == "2.10") {
"com.thoughtworks.sde" %%% "core" % "3.3.2"
} else {
"com.thoughtworks.sde" %%% "core" % "3.3.4"
}
}

libraryDependencies += "com.thoughtworks.sde" %%% "comprehension-monad" % "3.3.2"

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.thoughtworks.each

import scala.annotation.StaticAnnotation

private[each] object macrocompat {
class bundle extends StaticAnnotation
}
3 changes: 2 additions & 1 deletion each/src/test/scala/com/thoughtworks/each/MonadicTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,8 @@ class MonadicTest {
} catch {
case e: Exception => {
count += 1
100
// FIXME: compile time error on Scala 2.13 if removing `: Int`
100: Int
}
} finally {
count += 1
Expand Down
4 changes: 3 additions & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ addSbtPlugin(

addSbtPlugin("com.thoughtworks.sbt-scala-js-map" % "sbt-scala-js-map" % "4.0.0")

addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.32")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.33")

addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.17")

Expand All @@ -15,3 +15,5 @@ addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.2.1")
addSbtPlugin("org.lyranthe.sbt" % "partial-unification" % "1.1.2")

addSbtPlugin("com.thoughtworks.example" % "sbt-example" % "9.2.1")

addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.2.0")
22 changes: 22 additions & 0 deletions project/plugins.sbt.scala-js.1.x
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// An optional sbt file to replace Scala.js 1.0 with 0.6
dependencyOverrides += Defaults.sbtPluginExtra(
"org.scala-js" % "sbt-scalajs" % "1.0.1",
sbtBinaryVersion.value,
scalaBinaryVersion.value,
)

Compile / sourceGenerators += Def.task {
val file = (Compile / sourceManaged).value / "SkipPublishForNonScalaJSProjects.scala"
IO.write(file, """
import scalajscrossproject.ScalaJSCrossPlugin.autoImport._
import sbtcrossproject.CrossPlugin.autoImport._
import sbt._, Keys._
object SkipPublishForNonScalaJSProjects extends AutoPlugin {
override def trigger = allRequirements
override def projectSettings = Seq(
publish / skip := crossProjectPlatform.value != JSPlatform
)
}
""")
Seq(file)
}.taskValue

0 comments on commit a865197

Please sign in to comment.