Merge pull request #4 from exoego/scala-js-support

Add Scala.js support
This commit is contained in:
eugene yokota 2019-05-09 07:50:47 -04:00 committed by GitHub
commit d2ac3e6fd7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 56 additions and 9 deletions

View File

@ -67,6 +67,10 @@ sealed trait ProjectMatrix extends CompositeProject {
def jvm: ProjectFinder
def jsPlatform(settings: Setting[_]*): ProjectMatrix
def js: ProjectFinder
def projectRefs: Seq[ProjectReference]
}
@ -86,6 +90,8 @@ object ProjectMatrix {
val jvmIdSuffix: String = "JVM"
val jvmDirectorySuffix: String = "-jvm"
val jsIdSuffix: String = "JS"
val jsDirectorySuffix: String = "-js"
/** A row in the project matrix, typically representing a platform.
*/
@ -199,19 +205,26 @@ object ProjectMatrix {
override def jvmPlatform(settings: Setting[_]*): ProjectMatrix =
custom(jvmIdSuffix, jvmDirectorySuffix, Nil, { _.settings(settings) })
override def jvm: ProjectFinder = new ProjectFinder {
def get: Seq[Project] = projectMatrix.toSeq collect {
case ((r, sv), v) if r.idSuffix == jvmIdSuffix => v
}
def apply(sv: String): Project =
(projectMatrix.toSeq collect {
case ((r, `sv`), v) if r.idSuffix == jvmIdSuffix => v
}).headOption.getOrElse(sys.error(s"$sv was not found"))
}
override def jsPlatform(settings: Setting[_]*): ProjectMatrix =
custom(jsIdSuffix, jsDirectorySuffix, Nil, { _.settings(settings) })
override def jvm: ProjectFinder = new SuffixBaseProjectFinder(jvmIdSuffix)
override def js: ProjectFinder = new SuffixBaseProjectFinder(jsIdSuffix)
override def projectRefs: Seq[ProjectReference] =
componentProjects map { case p => (p: ProjectReference) }
private final class SuffixBaseProjectFinder(idSuffix: String) extends ProjectFinder {
def get: Seq[Project] = projectMatrix.toSeq collect {
case ((r, sv), v) if r.idSuffix == idSuffix => v
}
def apply(sv: String): Project =
(projectMatrix.toSeq collectFirst {
case ((r, `sv`), v) if r.idSuffix == idSuffix => v
}).getOrElse(sys.error(s"$sv was not found"))
}
override def custom(
idSuffix: String,
directorySuffix: String,

View File

@ -0,0 +1,19 @@
// lazy val root = (project in file("."))
// .aggregate(core.projectRefs ++ app.projectRefs: _*)
// .settings(
// )
lazy val core = (projectMatrix in file("core"))
.scalaVersions("2.12.6", "2.11.12")
.settings(
name := "core"
)
.jsPlatform()
lazy val app = (projectMatrix in file("app"))
.dependsOn(core)
.scalaVersions("2.12.6")
.settings(
name := "app"
)
.jsPlatform()

View File

@ -0,0 +1,6 @@
package a
class Core {
}
object Core extends Core

View File

@ -0,0 +1,5 @@
sys.props.get("plugin.version") match {
case Some(x) => addSbtPlugin("com.eed3si9n" % "sbt-projectmatrix" % x)
case _ => sys.error("""|The system property 'plugin.version' is not defined.
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin)
}

View File

@ -0,0 +1,4 @@
> compile
$ exists core/target/js-2.12/classes/a/Core.class
$ exists core/target/js-2.11/classes/a/Core.class