Skip to content

Commit

Permalink
Merge pull request #118 from Atry/scalajs-1.x
Browse files Browse the repository at this point in the history
Workaround for breaking API changes in sbt-scalajs 1.x
  • Loading branch information
Atry authored Dec 25, 2019
2 parents c8b6b44 + dfba3e2 commit d6585f5
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 9 deletions.
6 changes: 5 additions & 1 deletion travis/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ libraryDependencies += "com.jsuereth" %% "scala-arm" % "2.0"

addSbtPlugin("com.eed3si9n" % "sbt-unidoc" % "0.4.2")

addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.31")
libraryDependencies += Defaults.sbtPluginExtra(
"org.scala-js" % "sbt-scalajs" % "1.0.0-RC2",
(sbtBinaryVersion in pluginCrossBuild).value,
(scalaBinaryVersion in update).value
) % Optional

libraryDependencies += "org.yaml" % "snakeyaml" % "1.25"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,62 @@
package com.thoughtworks.sbtBestPractice.travis

import sbt.{AutoPlugin, Def}
import sbt._
import org.scalajs.sbtplugin.ScalaJSPlugin
import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport._
import scala.language.reflectiveCalls

/**
* @author 杨博 (Yang Bo)
*/
object TravisScalaJs extends AutoPlugin {
private def reflectiveLinkerSetting[
StandardConfig <: {
def withBatchMode(batchMode: Boolean): StandardConfig
}
](key: SettingKey[StandardConfig]): Def.Setting[StandardConfig] = {
key := {
key.value.withBatchMode(Travis.travisRepoSlug.?.value.isDefined)
}
}

private def scalaJSLinkerConfig06[
StandardConfig <: {
def withBatchMode(batchMode: Boolean): StandardConfig
}
] = {
// The type of ScalaJSPlugin v0.6
type ScalaJSPlugin06 = {
def autoImport: {
def scalaJSLinkerConfig: SettingKey[StandardConfig]
}
}
ScalaJSPlugin.asInstanceOf[ScalaJSPlugin06].autoImport.scalaJSLinkerConfig
}

override def requires = Travis && ScalaJSPlugin
override def projectSettings: Seq[Def.Setting[_]] = {
Seq(try {
// sbt-scalajs 1.x
reflectiveLinkerSetting(ScalaJSPlugin.autoImport.scalaJSLinkerConfig)
} catch {
case _: NoClassDefFoundError =>
// sbt-scalajs 0.6.x
reflectiveLinkerSetting(scalaJSLinkerConfig06)
})
}

override def projectSettings: Seq[Def.Setting[_]] = Seq(
scalaJSLinkerConfig := {
scalaJSLinkerConfig.value.withBatchMode(Travis.travisRepoSlug.?.value.isDefined)
override def requires = {
try {
ScalaJSPlugin && Travis
} catch {
case _: NoClassDefFoundError =>
Travis
}
)
override def trigger = allRequirements
}

override def trigger = {
if (requires == Travis) {
noTrigger
} else {
allRequirements
}
}
}

0 comments on commit d6585f5

Please sign in to comment.