-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Workaround for breaking API changes in sbt-scalajs 1.x
- Loading branch information
Showing
2 changed files
with
54 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 49 additions & 8 deletions
57
travis/src/main/scala/com/thoughtworks/sbtBestPractice/travis/TravisScalaJs.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |