Skip to content

Commit afc80ef

Browse files
Upgraded sbt to 1.6, scala.js to 1.8 and webpack to 5 (#12)
1 parent 430411a commit afc80ef

22 files changed

+145
-72
lines changed

.github/workflows/ci.yml

+20-18
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ name: CI
22

33
on:
44
push:
5+
paths-ignore:
6+
- '*.md'
57
branches: [ master ]
68
tags:
79
- '*'
@@ -13,34 +15,34 @@ jobs:
1315
runs-on: ubuntu-latest
1416
steps:
1517

16-
- name: Git checkout
17-
uses: actions/checkout@v2
18+
- name: Git checkout (merge)
19+
uses: actions/checkout@v3
20+
if: github.event_name != 'pull_request'
1821
with:
1922
fetch-depth: 0
2023

24+
- name: Git checkout (PR)
25+
uses: actions/checkout@v3
26+
if: github.event_name == 'pull_request'
27+
with:
28+
fetch-depth: 0
29+
# see: https://frontside.com/blog/2020-05-26-github-actions-pull_request/#how-does-pull_request-affect-actionscheckout
30+
ref: ${{ github.event.pull_request.head.sha }}
31+
2132
- name: Setup Node.js
22-
uses: actions/setup-node@v2
33+
uses: actions/setup-node@v3
2334
with:
24-
node-version: '12'
35+
node-version: '16'
2536

2637
- name: Set up JDK 8
27-
uses: actions/setup-java@v2
38+
uses: actions/setup-java@v3
2839
with:
2940
java-version: '8'
3041
distribution: 'adopt'
31-
32-
- name: Cache sbt
33-
uses: actions/cache@v2
34-
with:
35-
path: |
36-
~/.sbt
37-
~/.ivy2/cache
38-
~/.coursier/cache/v1
39-
~/.cache/coursier/v1
40-
key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt', 'project/**/*.scala') }}
42+
cache: 'sbt'
4143

4244
- name: Cache node_modules
43-
uses: actions/cache@v2
45+
uses: actions/cache@v3
4446
with:
4547
path: |
4648
~/.npm
@@ -62,7 +64,7 @@ jobs:
6264
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
6365

6466
- name: Publish SNAPSHOT
65-
run: sbt ";^^1.5.2 ;clean ;publish"
67+
run: sbt ";^^1.6.2 ;clean ;publish"
6668
if: ${{ !github.event.pull_request && env.TAG_NAME == '' }}
6769
env:
6870
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
@@ -75,7 +77,7 @@ jobs:
7577
echo $PGP_SECRET | base64 --decode > ./keys/secring.gpg
7678
VERSION="$(echo "$TAG_NAME" | cut -d'v' -f 2)"
7779
echo "Publish a release version=$VERSION for tag $TAG_NAME"
78-
version=$VERSION sbt ";^^1.5.2 ;clean ;publishSigned ;sonatypeBundleRelease"
80+
version=$VERSION sbt ";^^1.6.2 ;clean ;publishSigned ;sonatypeBundleRelease"
7981
if: ${{ env.TAG_NAME != '' }}
8082
env:
8183
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
*.class
22
*.log
3+
package-lock.json
34

45
# sbt specific
56
.cache

.sbtopts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-J-Xmx2G
2+
-J-XX:+UseG1GC

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
[![CI](https://github.com/scommons/sbt-scommons-plugin/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/scommons/sbt-scommons-plugin/actions/workflows/ci.yml?query=workflow%3Aci+branch%3Amaster)
33
[![Coverage Status](https://coveralls.io/repos/github/scommons/sbt-scommons-plugin/badge.svg?branch=master)](https://coveralls.io/github/scommons/sbt-scommons-plugin?branch=master)
44
[![scala-index](https://index.scala-lang.org/scommons/sbt-scommons-plugin/sbt-scommons-plugin/latest-by-scala-version.svg?targetType=Sbt)](https://index.scala-lang.org/scommons/sbt-scommons-plugin/sbt-scommons-plugin)
5-
[![Scala.js](https://www.scala-js.org/assets/badges/scalajs-1.5.0.svg)](https://www.scala-js.org)
5+
[![Scala.js](https://www.scala-js.org/assets/badges/scalajs-1.8.0.svg)](https://www.scala-js.org)
66

77
## sbt-scommons-plugin
88
Sbt auto-plugins with common tasks/utils for Scala Commons modules

build.sbt

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import definitions.GitHubActionsCI
2+
import org.scoverage.coveralls.Imports.CoverallsKeys._
13

24
val ideExcludedDirectories = SettingKey[Seq[File]]("ide-excluded-directories")
35
.withRank(KeyRanks.Invisible)
@@ -41,16 +43,18 @@ lazy val `sbt-scommons-plugin` = (project in file("."))
4143
coverageMinimum := 80,
4244
coverageHighlighting := false,
4345
coverageExcludedPackages := ".*mecha.*;.*project.*",
46+
coverallsFailBuildOnError := true,
47+
coverallsService := GitHubActionsCI.jobId.map(_ => GitHubActionsCI),
4448

4549
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.1.0"),
46-
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.5.1"),
47-
addSbtPlugin("ch.epfl.scala" % "sbt-scalajs-bundler" % "0.20.0"),
50+
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.10.1"),
51+
addSbtPlugin("ch.epfl.scala" % "sbt-scalajs-bundler" % "0.21.0"),
4852

4953
//addSbtPlugin("com.storm-enroute" % "mecha" % "0.3"), //TODO: use version for sbt 1.x
5054

5155
libraryDependencies ++= Seq(
52-
"org.scalatest" %% "scalatest" % "3.2.9" % "test",
53-
"org.scalamock" %% "scalamock" % "5.1.0" % "test"
56+
"org.scalatest" %% "scalatest" % "3.2.14" % "test",
57+
"org.scalamock" %% "scalamock" % "5.2.0" % "test"
5458
),
5559

5660
//resolvers += "Sonatype Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/",

project/build.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version = 1.5.2
1+
sbt.version = 1.6.2

project/plugins.sbt

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.5")
55
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.0")
66

7-
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.7.3")
8-
addSbtPlugin("org.scoverage" % "sbt-coveralls" % "1.2.7")
7+
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.9.3")
8+
addSbtPlugin("org.scoverage" % "sbt-coveralls" % "1.3.2")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package definitions
2+
3+
import org.scoverage.coveralls.CIService
4+
5+
import scala.io.Source
6+
import scala.util.parsing.json.{JSON, JSONObject}
7+
8+
case object GitHubActionsCI extends CIService {
9+
val name = ""
10+
val jobId: Option[String] = sys.env.get("GITHUB_RUN_ID")
11+
12+
// https://github.com/coverallsapp/github-action/blob/master/src/run.ts#L31-L40
13+
val pullRequest: Option[String] = for {
14+
eventName <- sys.env.get("GITHUB_EVENT_NAME") if eventName.startsWith("pull_request")
15+
payloadPath <- sys.env.get("GITHUB_EVENT_PATH")
16+
source = Source.fromFile(payloadPath, "utf-8")
17+
lines = try source.mkString finally source.close()
18+
payload <- JSON.parseRaw(lines)
19+
prNumber <- payload.asInstanceOf[JSONObject].obj.get("number")
20+
} yield prNumber.toString.stripSuffix(".0")
21+
22+
// https://docs.github.com/en/actions/learn-github-actions/environment-variables
23+
val currentBranch: Option[String] = pullRequest match {
24+
case Some(_) => sys.env.get("GITHUB_HEAD_REF")
25+
case None => sys.env.get("GITHUB_REF_NAME")
26+
}
27+
}

src/main/scala/scommons/sbtplugin/ScommonsPlugin.scala

+19-5
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport._
44
import sbt.Keys._
55
import sbt._
66
import scommons.sbtplugin.util.{BundlesUtils, ResourcesUtils}
7-
8-
import scalajsbundler.Webpack
7+
import scalajsbundler.{NpmPackage, Webpack}
98
import scalajsbundler.sbtplugin.ScalaJSBundlerPlugin
109
import scalajsbundler.sbtplugin.ScalaJSBundlerPlugin.autoImport._
1110

@@ -99,18 +98,33 @@ object ScommonsPlugin extends AutoPlugin {
9998
val nodeArgs = (Test / webpackNodeArgs).value
10099
val bundleName = bundleOutput.data.name.stripSuffix(".js")
101100
val webpackOutput = targetDir / s"$bundleName-webpack-out.js"
101+
val webpackVersion = (webpack / version).value
102102

103103
logger.info("Executing webpack...")
104104
val loader = bundleOutput.data
105105

106-
customWebpackConfigFile match {
106+
val configArgs = customWebpackConfigFile match {
107107
case Some(configFile) =>
108108
val customConfigFileCopy = Webpack.copyCustomWebpackConfigFiles(targetDir, webpackResources.value.get)(configFile)
109-
Webpack.run(nodeArgs: _*)("--mode", "development", "--config", customConfigFileCopy.getAbsolutePath, loader.absolutePath, "--output", webpackOutput.absolutePath)(targetDir, logger)
109+
Seq("--config", customConfigFileCopy.getAbsolutePath)
110110
case None =>
111-
Webpack.run(nodeArgs: _*)("--mode", "development", loader.absolutePath, "--output", webpackOutput.absolutePath)(targetDir, logger)
111+
Seq.empty
112112
}
113113

114+
val allArgs = Seq(
115+
"--entry", loader.absolutePath,
116+
"--output-path", targetDir.absolutePath,
117+
"--output-filename", webpackOutput.name
118+
) ++ configArgs
119+
120+
NpmPackage(webpackVersion).major match {
121+
case Some(5) =>
122+
Webpack.run(nodeArgs: _*)(allArgs: _*)(targetDir, logger)
123+
case Some(x) =>
124+
sys.error(s"Unsupported webpack major version $x")
125+
case None =>
126+
sys.error("No webpack version defined")
127+
}
114128
Attributed(webpackOutput)(bundleOutput.metadata)
115129
}
116130
else bundleOutput

src/main/scala/scommons/sbtplugin/project/CommonClientModule.scala

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package scommons.sbtplugin.project
22

33
import org.portablescala.sbtplatformdeps.PlatformDepsPlugin.autoImport._
4+
import org.scalajs.linker.interface.ESVersion
45
import org.scalajs.jsenv.nodejs.NodeJSEnv
56
import org.scalajs.sbtplugin.ScalaJSPlugin
67
import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport._
@@ -62,13 +63,18 @@ trait CommonClientModule extends CommonModule {
6263
object CommonClientModule {
6364

6465
val settings: Seq[Setting[_]] = Seq(
66+
scalacOptions ++= Seq(
67+
//see:
68+
// http://www.scala-js.org/news/2021/12/10/announcing-scalajs-1.8.0/
69+
"-P:scalajs:nowarnGlobalExecutionContext"
70+
),
6571
scalaJSLinkerConfig ~= {
6672
_.withModuleKind(ModuleKind.CommonJSModule)
6773
.withSourceMap(false)
68-
.withESFeatures(_.withUseECMAScript2015(false))
74+
.withESFeatures(_.withESVersion(ESVersion.ES5_1))
6975
},
7076
Test / requireJsDomEnv := false,
71-
webpack / version := "4.29.0",
77+
webpack / version := "5.74.0",
7278
webpackEmitSourceMaps := false,
7379
Test / parallelExecution := false,
7480

src/main/scala/scommons/sbtplugin/project/CommonLibs.scala

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ trait CommonLibs {
1111
val playJsonVer = "2.9.0"
1212
val playWsVer = "2.0.8"
1313
val jodaTimeVer = "2.10.5"
14+
val scalaJsJavaSecureRandomVer = "1.0.0"
1415

1516
//////////////////////////////////////////////////////////////////////////////
1617
// jvm dependencies
@@ -37,6 +38,8 @@ trait CommonLibs {
3738
lazy val scalajsDom = Def.setting("org.scala-js" %%% "scalajs-dom" % "2.2.0")
3839

3940
lazy val playJsonJs = Def.setting("com.typesafe.play" %%% "play-json" % playJsonVer)
41+
42+
lazy val scalaJsJavaSecureRandom = Def.setting("org.scala-js" %%% "scalajs-java-securerandom" % scalaJsJavaSecureRandomVer)
4043
}
4144

4245
object CommonLibs extends CommonLibs

src/main/scala/scommons/sbtplugin/project/CommonMobileModule.scala

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package scommons.sbtplugin.project
22

33
import org.portablescala.sbtplatformdeps.PlatformDepsPlugin.autoImport._
4+
import org.scalajs.linker.interface.ESVersion
45
import org.scalajs.jsenv.nodejs.NodeJSEnv
56
import org.scalajs.sbtplugin.ScalaJSPlugin
67
import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport._
@@ -52,17 +53,22 @@ object CommonMobileModule {
5253
"org.scommons.react-native" % "scommons-react-native-test" % "*"
5354
),
5455

56+
scalacOptions ++= Seq(
57+
//see:
58+
// http://www.scala-js.org/news/2021/12/10/announcing-scalajs-1.8.0/
59+
"-P:scalajs:nowarnGlobalExecutionContext"
60+
),
5561
scalaJSLinkerConfig ~= {
5662
_.withModuleKind(ModuleKind.CommonJSModule)
5763
.withSourceMap(false)
58-
.withESFeatures(_.withUseECMAScript2015(false))
64+
.withESFeatures(_.withESVersion(ESVersion.ES5_1))
5965
},
6066
scalaJSUseMainModuleInitializer := false,
6167
webpackBundlingMode := BundlingMode.LibraryOnly(),
6268

6369
// react-native DO NOT require DOM
6470
Test / requireJsDomEnv := false,
65-
webpack / version := "4.29.0",
71+
webpack / version := "5.74.0",
6672
webpackEmitSourceMaps := false,
6773
Test / parallelExecution := false,
6874

src/main/scala/scommons/sbtplugin/project/CommonModule.scala

+10-1
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,13 @@ object CommonModule {
3030

3131
val coverageMinimum = SettingKey[Double]("coverage-minimum")
3232
val coverageExcludedPackages = SettingKey[String]("coverage-excluded-packages")
33+
val coverallsFailBuildOnError = SettingKey[Boolean](
34+
"coverallsFailBuildOnError",
35+
"fail build if coveralls step fails"
36+
)
3337

3438
val settings: Seq[Setting[_]] = Seq(
35-
scalaVersion := "2.13.5",
39+
scalaVersion := "2.13.8",
3640
scalacOptions ++= Seq(
3741
//see https://docs.scala-lang.org/overviews/compiler-options/index.html#Warning_Settings
3842
//"-Xcheckinit",
@@ -54,6 +58,11 @@ object CommonModule {
5458
},
5559

5660
coverageMinimum := 80,
61+
coverallsFailBuildOnError := true,
62+
63+
//improving performance by disabling this feature that was introduced in:
64+
// https://github.com/scoverage/sbt-scoverage/releases/tag/v1.8.0
65+
Compile / compile / scalacOptions -= "-P:scoverage:reportTestName",
5766

5867
resolvers += "Sonatype Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/"
5968
)

src/main/scala/scommons/sbtplugin/project/CommonNodeJsModule.scala

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package scommons.sbtplugin.project
22

33
import org.portablescala.sbtplatformdeps.PlatformDepsPlugin.autoImport._
4+
import org.scalajs.linker.interface.ESVersion
45
import org.scalajs.jsenv.nodejs.NodeJSEnv
56
import org.scalajs.sbtplugin.ScalaJSPlugin
67
import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport._
@@ -38,13 +39,18 @@ trait CommonNodeJsModule extends CommonModule {
3839
object CommonNodeJsModule {
3940

4041
val settings: Seq[Setting[_]] = Seq(
42+
scalacOptions ++= Seq(
43+
//see:
44+
// http://www.scala-js.org/news/2021/12/10/announcing-scalajs-1.8.0/
45+
"-P:scalajs:nowarnGlobalExecutionContext"
46+
),
4147
scalaJSLinkerConfig ~= {
4248
_.withModuleKind(ModuleKind.CommonJSModule)
4349
.withSourceMap(false)
44-
.withESFeatures(_.withUseECMAScript2015(false))
50+
.withESFeatures(_.withESVersion(ESVersion.ES5_1))
4551
},
4652
Test / requireJsDomEnv := false,
47-
webpack / version := "4.29.0",
53+
webpack / version := "5.74.0",
4854
webpackEmitSourceMaps := false,
4955
Test / parallelExecution := false,
5056

src/main/scala/scommons/sbtplugin/project/CommonTestLibs.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import sbt._
55

66
trait CommonTestLibs {
77

8-
val scalaTestVersion = "3.2.9"
9-
val scalaTestPlusMockitoVersion = "3.2.9.0"
8+
val scalaTestVersion = "3.2.14"
9+
val scalaTestPlusMockitoVersion = "3.2.10.0"
1010
val scalaTestPlusPlayVersion = "5.1.0"
11-
val scalaMockVersion = "5.1.0"
11+
val scalaMockVersion = "5.2.0"
1212
val dockerTestkitVersion = "0.9.9"
1313

1414
val akkaVersion: String = CommonLibs.akkaVersion

0 commit comments

Comments
 (0)