Skip to content

Commit

Permalink
Cross-compile to Scala.js 1.1+
Browse files Browse the repository at this point in the history
  • Loading branch information
viktor-podzigun committed Aug 9, 2021
1 parent 4773a92 commit 0a40a46
Show file tree
Hide file tree
Showing 11 changed files with 249 additions and 119 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ env:
- secure: SVb4Odan6bePQ6v8BhAWYkW2JhHYiS4UojkmEZacEsobjgNAkI4qSGYjC8pcIvBUKnFPafHRG/ggtrZ8ml1beX9bXQxJsmGOutJEMuQyInPUDXdvUHABNBd/8NL8tJhZS6Ijnzbar6i78vizZNW88V9HpWwk2HZQyHw9q5mp1R0nHOG9L1474I62hnc/rclAPecWgUbiTft2mPXRohmb8aFhqAceYao+1g1LY4AuXyPiM3s4sU1YzdL/DJLWVbt8WUAmPUfiAKpGSQY98bBBxCfJrNDezIhENcY/MTo5+cGEcVtfJKu9psL5fShOPUChnnonHSb34/XWyocgN8ZrCQTfhqI1lIzB8HOc3nRiKwPfUcZ2MQ5P4fJi62rzfhEz8/r3HlvhKM+m1++wc7ocsb7+ku59xn93DWYkXKVkD2r3DnzaANd2FMFplopFSEgBJVGTKOXQSSVriMKeTpg2q13PvDhhUTIgOus4MX+n/q4XiAFLygCceRXq1mXFKi0sjWLrJkBldkg8VA1dL31RdK5ZN5K+56gSYPVhvOVeKx2URkbNDV3Y0z8rM33852VI7pdkRuGAZZFfKwVGOFlc5HcbLRln0e2oql1KtOWjyfFicT9pjHfeg2dfIrKBKMrJGavaLdh8kuX/0kKp37SdP+mJtVqJTwwoCXJol6tcl/s=
- secure: IblLuw3rbTHi3Bozgz2h5IUaL9VfdLAdep4u95V4A/GGxR/nfXkfOuxT10c1+OrYc2+KxKDGChhlTvMd6HsHi5LUmPgfgB4MQMXs4OTsBDX3mMD4uSWbzBFyq/Z0YdbJxfQisJkseWDl7HWGuiAJyiRUdLkyEj3L9mtIqqHzsfN47V1mgAriilo+bDeLLm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yyXsac4Axi4ATuX2qhoQlRA+GmrqUsc/Se40/GnwPnJKmys0I5FB8EpQ/Wwq3CFgJ9353jFpbB0OcVcL4JskD8Mv/W1s=
jobs:
- SCALAJS_VERSION=0.6.31
- SCALAJS_VERSION=1.1.0
before_install:
- nvm install 12 &&
nvm use 12
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
[![Build Status](https://travis-ci.com/scommons/scommons-api.svg?branch=master)](https://travis-ci.com/scommons/scommons-api)
[![Coverage Status](https://coveralls.io/repos/github/scommons/scommons-api/badge.svg?branch=master)](https://coveralls.io/github/scommons/scommons-api?branch=master)
[![scala-index](https://index.scala-lang.org/scommons/scommons-api/scommons-api-core/latest-by-scala-version.svg?targetType=Js)](https://index.scala-lang.org/scommons/scommons-api/scommons-api-core)
[![Scala.js](https://www.scala-js.org/assets/badges/scalajs-0.6.29.svg)](https://www.scala-js.org)
[![Scala.js 0.6](https://www.scala-js.org/assets/badges/scalajs-0.6.29.svg)](https://www.scala-js.org)
[![Scala.js 1.0](https://www.scala-js.org/assets/badges/scalajs-1.1.0.svg)](https://www.scala-js.org)

## scommons-api
Common REST API Scala/Scala.js components
Expand Down
10 changes: 9 additions & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
//resolvers += "Typesafe repository" at "https://repo.typesafe.com/typesafe/releases/"
resolvers += "Sonatype Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/"

addSbtPlugin(("org.scommons.sbt" % "sbt-scommons-plugin" % "0.5.0-SNAPSHOT").changing())
val scalaJSVersion =
Option(System.getenv("SCALAJS_VERSION")).getOrElse("0.6.31")

//addSbtPlugin("org.scommons.sbt" % "sbt-scommons-plugin" % "0.5.0")
if (scalaJSVersion.startsWith("0.6")) {
addSbtPlugin(("org.scommons.sbt" % "sbt-scommons-plugin-sjs06" % "0.5.0-SNAPSHOT").changing())
}
else {
addSbtPlugin(("org.scommons.sbt" % "sbt-scommons-plugin" % "0.5.0-SNAPSHOT").changing())
}

addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.5")
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.0")
Expand Down
2 changes: 2 additions & 0 deletions project/src/main/scala/definitions/ApiAdmin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ object ApiAdmin {
)
).jvmSettings(
// Add JVM-specific settings here
JvmModule.settings: _*
).jsSettings(
// Add JS-specific settings here
ScalaJsModule.settings: _*
)

lazy val jvm: Project = `scommons-api-admin`.jvm
Expand Down
12 changes: 7 additions & 5 deletions project/src/main/scala/definitions/ApiCore.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import sbt.Keys._
import sbt._
import sbtcrossproject.CrossPlugin.autoImport._
import sbtcrossproject.{CrossProject, JVMPlatform}
import scommons.sbtplugin.project.CommonModule

import scalajscrossproject.ScalaJSCrossPlugin.autoImport._
import scommons.sbtplugin.project.CommonModule

object ApiCore {

Expand All @@ -28,10 +27,13 @@ object ApiCore {
TestLibs.scalaMockJs.value % "test"
)
).jvmSettings(
// Add JVM-specific settings here
Seq(
libraryDependencies ++= Seq(
Libs.jodaTime.value
)
) ++ JvmModule.settings: _*
).jsSettings(
//Opt-in @ScalaJSDefined by default
scalacOptions += "-P:scalajs:sjsDefinedByDefault"
ScalaJsModule.settings: _*
)

lazy val jvm: Project = `scommons-api-core`.jvm
Expand Down
8 changes: 6 additions & 2 deletions project/src/main/scala/definitions/ApiJodaTime.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@ object ApiJodaTime {
TestLibs.scalaMockJs.value % "test"
)
).jvmSettings(
// Add JVM-specific settings here
Seq(
libraryDependencies ++= Seq(
Libs.jodaTime.value
)
) ++ JvmModule.settings: _*
).jsSettings(
// Add JS-specific settings here
ScalaJsModule.settings: _*
)

lazy val jvm: Project = `scommons-api-joda-time`.jvm
Expand Down
1 change: 1 addition & 0 deletions project/src/main/scala/definitions/ApiPlayWs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ object ApiPlayWs extends ApiModule {
override val base: File = file("play-ws")

override def definition: Project = super.definition
.settings(JvmModule.settings: _*)
.settings(
description := "Common Scala ApiHttpClient implementation using play-ws library"
)
Expand Down
6 changes: 2 additions & 4 deletions project/src/main/scala/definitions/ApiXhr.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,14 @@ object ApiXhr extends ApiModule {
override def definition: Project = {
super.definition
.enablePlugins(ScalaJSPlugin)
.settings(ScalaJsModule.settings: _*)
.settings(
description := "Scala Commons ApiHttpClient implementation using JavaScript XMLHttpRequest",

// disable scoverage, until the following issue is fixed:
// https://github.com/scoverage/scalac-scoverage-plugin/issues/196
coverageEnabled := false,
coverageExcludedPackages := "scommons.api.http.xhr.raw",

//Opt-in @ScalaJSDefined by default
scalacOptions += "-P:scalajs:sjsDefinedByDefault"
coverageExcludedPackages := "scommons.api.http.xhr.raw"
)
}

Expand Down
13 changes: 13 additions & 0 deletions project/src/main/scala/definitions/JvmModule.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package definitions

import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport._
import sbt.Keys._
import sbt._

object JvmModule {

val settings: Seq[Setting[_]] = Seq(
// avoid double-publishing when cross-compiling to Scala.js 1.1+
skip in publish := !scalaJSVersion.startsWith("0.6")
)
}
47 changes: 47 additions & 0 deletions project/src/main/scala/definitions/ScalaJsModule.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package definitions

import org.scalajs.jsenv.nodejs.NodeJSEnv
import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport._
import sbt.Keys._
import sbt._
import scoverage.ScoverageKeys.{coverageEnabled, coverageScalacPluginVersion}
import scoverage.ScoverageSbtPlugin._

object ScalaJsModule {

val settings: Seq[Setting[_]] = Seq(
// required for node.js >= v12.12.0
// see:
// https://github.com/nodejs/node/pull/29919
jsEnv in Test := new NodeJSEnv(NodeJSEnv.Config().withArgs(List("--enable-source-maps"))),
scalaJSLinkerConfig in Test ~= {
_.withSourceMap(true)
},
//Opt-in @ScalaJSDefined by default
scalacOptions += {
if (scalaJSVersion.startsWith("0.6")) "-P:scalajs:sjsDefinedByDefault"
else ""
},

//TODO: remove these temporal fixes for Scala.js 1.1+ and scoverage
coverageScalacPluginVersion := {
val current = coverageScalacPluginVersion.value
if (scalaJSVersion.startsWith("0.6")) current
else "1.4.2" //the only version that supports Scala.js 1.1+
},
libraryDependencies ~= { modules =>
if (scalaJSVersion.startsWith("0.6")) modules
else modules.filter(_.organization != OrgScoverage)
},
libraryDependencies ++= {
if (coverageEnabled.value) {
if (scalaJSVersion.startsWith("0.6")) Nil
else Seq(
OrgScoverage %% s"${ScalacRuntimeArtifact}_sjs1" % coverageScalacPluginVersion.value,
OrgScoverage %% ScalacPluginArtifact % coverageScalacPluginVersion.value % ScoveragePluginConfig.name
)
}
else Nil
}
)
}
Loading

0 comments on commit 0a40a46

Please sign in to comment.