From dfba3e22f73307f76676ee1f10be9448f9e93d35 Mon Sep 17 00:00:00 2001 From: "Yang, Bo" Date: Wed, 25 Dec 2019 00:46:00 +0000 Subject: [PATCH] Workaround for breaking API changes in sbt-scalajs 1.x --- travis/build.sbt | 6 +- .../travis/TravisScalaJs.scala | 57 ++++++++++++++++--- 2 files changed, 54 insertions(+), 9 deletions(-) diff --git a/travis/build.sbt b/travis/build.sbt index f82bb13..e918305 100644 --- a/travis/build.sbt +++ b/travis/build.sbt @@ -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" diff --git a/travis/src/main/scala/com/thoughtworks/sbtBestPractice/travis/TravisScalaJs.scala b/travis/src/main/scala/com/thoughtworks/sbtBestPractice/travis/TravisScalaJs.scala index 89e6224..b0c33a3 100644 --- a/travis/src/main/scala/com/thoughtworks/sbtBestPractice/travis/TravisScalaJs.scala +++ b/travis/src/main/scala/com/thoughtworks/sbtBestPractice/travis/TravisScalaJs.scala @@ -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 + } + } }