summaryrefslogtreecommitdiff
path: root/scalajsplugin
diff options
context:
space:
mode:
authorRoman Timushev <rtimush@gmail.com>2017-12-29 10:28:51 +0100
committerRoman Timushev <rtimush@gmail.com>2017-12-29 19:05:00 +0100
commit1a0cce2d21e9d90058386890f77a57291a494359 (patch)
tree84776b5439c07292fd01a665b1fae2fd7510f0eb /scalajsplugin
parent8583a2a95a0bf0b3dcfb74bfb47ea18719be01c1 (diff)
downloadmill-1a0cce2d21e9d90058386890f77a57291a494359.tar.gz
mill-1a0cce2d21e9d90058386890f77a57291a494359.tar.bz2
mill-1a0cce2d21e9d90058386890f77a57291a494359.zip
Cross-publish for ScalaJS
Diffstat (limited to 'scalajsplugin')
-rw-r--r--scalajsplugin/src/main/scala/mill/scalajsplugin/ScalaJSModule.scala28
-rw-r--r--scalajsplugin/src/test/scala/mill/scalajsplugin/HelloJSWorldTests.scala40
2 files changed, 57 insertions, 11 deletions
diff --git a/scalajsplugin/src/main/scala/mill/scalajsplugin/ScalaJSModule.scala b/scalajsplugin/src/main/scala/mill/scalajsplugin/ScalaJSModule.scala
index 1c736537..c3e8a89d 100644
--- a/scalajsplugin/src/main/scala/mill/scalajsplugin/ScalaJSModule.scala
+++ b/scalajsplugin/src/main/scala/mill/scalajsplugin/ScalaJSModule.scala
@@ -7,20 +7,31 @@ import ammonite.ops.Path
import mill.eval.Result.Success
import mill.scalajsplugin.Lib._
import mill.scalaplugin.Lib.resolveDependencies
-import mill.scalaplugin.{Dep, ScalaModule, TestScalaModule}
+import mill.scalaplugin.{Dep, PublishModule, ScalaModule, TestScalaModule}
trait ScalaJSModule extends ScalaModule { outer =>
def scalaJSVersion: T[String]
- def scalaJSBinaryVersion = T{ scalaJSVersion().split('.').dropRight(1).mkString(".") }
+ private val ReleaseVersion = raw"""(\d+)\.(\d+)\.(\d+)""".r
+ private val MinorSnapshotVersion = raw"""(\d+)\.(\d+)\.([1-9]\d*)-SNAPSHOT""".r
+
+ def scalaJSBinaryVersion = T{
+ scalaJSVersion() match {
+ case ReleaseVersion(major, minor, _) => s"$major.$minor"
+ case MinorSnapshotVersion(major, minor, _) => s"$major.$minor"
+ case _ => scalaJSVersion()
+ }
+ }
+
+ def scalaJSBridgeVersion = T{ scalaJSVersion().split('.').dropRight(1).mkString(".") }
def scalaJSLinkerClasspath: T[Seq[PathRef]] = T{
- val jsBridgeKey = "MILL_SCALAJS_BRIDGE_" + scalaJSBinaryVersion().replace('.', '_')
+ val jsBridgeKey = "MILL_SCALAJS_BRIDGE_" + scalaJSBridgeVersion().replace('.', '_')
val jsBridgePath = sys.props(jsBridgeKey)
if (jsBridgePath != null) Success(jsBridgePath.split(File.pathSeparator).map(f => PathRef(Path(f), quick = true)).toVector)
else {
- val dep = scalaJSLinkerIvyDep(scalaJSBinaryVersion())
+ val dep = scalaJSLinkerIvyDep(scalaJSBridgeVersion())
resolveDependencies(
repositories,
scalaVersion(),
@@ -44,6 +55,15 @@ trait ScalaJSModule extends ScalaModule { outer =>
override def ivyDeps = T{ Seq(Dep("org.scala-js", "scalajs-library", scalaJSVersion())) }
+ // publish artifact with name "mill_sjs0.6.4_2.12" instead of "mill_sjs0.6_2.12"
+ def crossFullScalaJSVersion: T[Boolean] = false
+ def artifactScalaJSVersion: T[String] = T {
+ if (crossFullScalaJSVersion()) scalaJSVersion()
+ else scalaJSBinaryVersion()
+ }
+
+ override def artifactId: T[String] = T { s"${artifactName()}_sjs${artifactScalaJSVersion()}_${artifactScalaVersion()}" }
+
}
trait TestScalaJSModule extends ScalaJSModule with TestScalaModule \ No newline at end of file
diff --git a/scalajsplugin/src/test/scala/mill/scalajsplugin/HelloJSWorldTests.scala b/scalajsplugin/src/test/scala/mill/scalajsplugin/HelloJSWorldTests.scala
index ae824d86..e199c1da 100644
--- a/scalajsplugin/src/test/scala/mill/scalajsplugin/HelloJSWorldTests.scala
+++ b/scalajsplugin/src/test/scala/mill/scalajsplugin/HelloJSWorldTests.scala
@@ -5,15 +5,17 @@ import java.util.jar.JarFile
import javax.script.{ScriptContext, ScriptEngineManager}
import ammonite.ops._
-import ammonite.ops.ImplicitWd._
+import mill._
import mill.define.Cross
import mill.discover.Discovered
+import mill.scalaplugin.PublishModule
+import mill.scalaplugin.publish.{Developer, License, PomSettings, SCM}
import mill.util.TestEvaluator
import utest._
import scala.collection.JavaConverters._
-trait HelloJSWorldModule extends ScalaJSModule {
+trait HelloJSWorldModule extends ScalaJSModule with PublishModule {
def basePath = HelloJSWorldTests.workspacePath
override def mainClass = Some("Main")
}
@@ -26,6 +28,20 @@ object HelloJSWorld {
new HelloJSWorldModule {
def scalaVersion = scala
def scalaJSVersion = scalaJS
+ def pomSettings = PomSettings(
+ organization = "com.lihaoyi",
+ description = "hello js world ready for real world publishing",
+ url = "https://github.com/lihaoyi/hello-world-publish",
+ licenses = Seq(
+ License("Apache License, Version 2.0",
+ "http://www.apache.org/licenses/LICENSE-2.0")),
+ scm = SCM(
+ "https://github.com/lihaoyi/hello-world-publish",
+ "scm:git:https://github.com/lihaoyi/hello-world-publish"
+ ),
+ developers =
+ Seq(Developer("lihaoyi", "Li Haoyi", "https://github.com/lihaoyi"))
+ )
}
}
@@ -58,7 +74,7 @@ object HelloJSWorldTests extends TestSuite {
def tests: Tests = Tests {
prepareWorkspace()
'compile - {
- def testFromScratch(scalaVersion: String,
+ def testCompileFromScratch(scalaVersion: String,
scalaJSVersion: String): Unit = {
val Right((result, evalCount)) =
helloWorldEvaluator(HelloJSWorld.build(scalaVersion, scalaJSVersion).compile)
@@ -77,10 +93,10 @@ object HelloJSWorldTests extends TestSuite {
assert(unchangedEvalCount == 0)
}
- 'fromScratch_2124_0621 - testFromScratch("2.12.4", "0.6.21")
- 'fromScratch_2123_0621 - testFromScratch("2.12.3", "0.6.21")
- 'fromScratch_2118_0621 - testFromScratch("2.11.8", "0.6.21")
- 'fromScratch_2124_100M2 - testFromScratch("2.11.8", "1.0.0-M2")
+ 'fromScratch_2124_0621 - testCompileFromScratch("2.12.4", "0.6.21")
+ 'fromScratch_2123_0621 - testCompileFromScratch("2.12.3", "0.6.21")
+ 'fromScratch_2118_0621 - testCompileFromScratch("2.11.8", "0.6.21")
+ 'fromScratch_2124_100M2 - testCompileFromScratch("2.11.8", "1.0.0-M2")
}
def testRun(scalaVersion: String,
@@ -115,6 +131,16 @@ object HelloJSWorldTests extends TestSuite {
assert(entries.contains("Main$.sjsir"))
}
}
+ 'publish - {
+ def testArtifactId(scalaVersion: String,
+ scalaJSVersion: String,
+ artifactId: String): Unit = {
+ val Right((result, evalCount)) = helloWorldEvaluator(HelloJSWorld.build(scalaVersion, scalaJSVersion).artifact)
+ assert(result.id == artifactId)
+ }
+ 'artifactId_0621 - testArtifactId("2.12.4", "0.6.21", "hello-js-world_sjs0.6_2.12")
+ 'artifactId_0621 - testArtifactId("2.12.4", "1.0.0-M2", "hello-js-world_sjs1.0.0-M2_2.12")
+ }
}
def compileClassfiles(parentDir: Path) = Set(