Skip to content

Commit 5abb211

Browse files
authored
Merge pull request #539 from scala-js/topic/refactorBuild
Refactor sbt build
2 parents cc3ac44 + 384b9fa commit 5abb211

File tree

7 files changed

+218
-164
lines changed

7 files changed

+218
-164
lines changed

build.sbt

Lines changed: 11 additions & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -1,154 +1,11 @@
1-
import _root_.scalafix.sbt.BuildInfo.scalafixVersion
2-
import scalatex.ScalatexReadme
3-
4-
ThisBuild / shellPrompt := ((s: State) => Project.extract(s).currentRef.project + "> ")
5-
6-
lazy val scalafixRules = project
7-
.in(file("scalafix"))
8-
.settings(
9-
libraryDependencies += ("ch.epfl.scala" %% "scalafix-core" % scalafixVersion).cross(CrossVersion.for3Use2_13),
10-
)
11-
12-
def sourceMapsToGithub: Project => Project =
13-
p => p.settings(
14-
scalacOptions ++= {
15-
val isDotty = scalaVersion.value startsWith "3"
16-
val ver = version.value
17-
if (isSnapshot.value)
18-
Nil
19-
else {
20-
val a = p.base.toURI.toString.replaceFirst("[^/]+/?$", "")
21-
val g = s"https://raw.githubusercontent.com/scala-js/scala-js-dom"
22-
val flag = if (isDotty) "-scalajs-mapSourceURI" else "-P:scalajs:mapSourceURI"
23-
s"$flag:$a->$g/v$ver/" :: Nil
24-
}
25-
}
26-
)
27-
28-
lazy val root = project
29-
.in(file("."))
30-
.enablePlugins(ScalaJSPlugin)
31-
.enablePlugins(ScalafixPlugin)
32-
.dependsOn(scalafixRules % ScalafixConfig)
33-
.configure(sourceMapsToGithub)
34-
35-
name := "Scala.js DOM"
36-
37-
ThisBuild / crossScalaVersions := Seq("2.11.12", "2.12.14", "2.13.6", "3.0.1")
38-
ThisBuild / scalaVersion := crossScalaVersions.value.find(_.startsWith("2.13.")).get
39-
40-
val inCI = sys.props.get("CI").exists(_.contains("1"))
41-
42-
val commonSettings = Seq(
43-
organization := "org.scala-js",
44-
scalacOptions ++= Seq(
45-
"-deprecation",
46-
"-feature",
47-
),
48-
scalacOptions ++= (if (!inCI) Seq.empty else Seq(
49-
"-Xfatal-warnings",
50-
)),
51-
scalacOptions ++= (CrossVersion.partialVersion(scalaVersion.value) match {
52-
case Some((2, 11)) => "-Ywarn-unused-import" :: Nil
53-
case Some((2, 12)) => "-Ywarn-unused:imports,patvars,locals,implicits" :: Nil
54-
case Some((2, 13)) => "-Wunused:imports,patvars,locals,implicits" :: Nil
55-
case _ => Nil
56-
}),
57-
)
58-
59-
val noPublishSettings = Seq(
60-
publish / skip := true
61-
)
62-
63-
normalizedName := "scalajs-dom"
64-
65-
commonSettings
66-
67-
homepage := Some(url("http://scala-js.org/"))
68-
69-
licenses += ("MIT", url("http://opensource.org/licenses/mit-license.php"))
70-
71-
def hasNewCollections(version: String): Boolean = {
72-
!version.startsWith("2.11.") &&
73-
!version.startsWith("2.12.")
74-
}
75-
76-
/** Returns the appropriate subdirectory of `sourceDir` depending on whether
77-
* the `scalaV` uses the new collections (introduced in 2.13) or not.
78-
*/
79-
def collectionsEraDependentDirectory(scalaV: String, sourceDir: File): File =
80-
if (hasNewCollections(scalaV)) sourceDir / "scala-new-collections"
81-
else sourceDir / "scala-old-collections"
82-
83-
inConfig(Compile)(Def.settings(
84-
unmanagedSourceDirectories +=
85-
collectionsEraDependentDirectory(scalaVersion.value, sourceDirectory.value)
86-
))
87-
88-
versionScheme := Some("early-semver")
89-
90-
pomExtra := (
91-
<developers>
92-
<developer>
93-
<id>japgolly</id>
94-
<name>David Barri</name>
95-
<url>https://github.com/japgolly</url>
96-
</developer>
97-
<developer>
98-
<id>armanbilge</id>
99-
<name>Arman Bilge</name>
100-
<url>https://github.com/armanbilge</url>
101-
</developer>
102-
<developer>
103-
<id>sjrd</id>
104-
<name>Sébastien Doeraene</name>
105-
<url>https://github.com/sjrd/</url>
106-
</developer>
107-
<developer>
108-
<id>gzm0</id>
109-
<name>Tobias Schlatter</name>
110-
<url>https://github.com/gzm0/</url>
111-
</developer>
112-
<developer>
113-
<id>lihaoyi</id>
114-
<name>Li Haoyi</name>
115-
<url>https://github.com/lihaoyi/</url>
116-
</developer>
117-
</developers>
118-
)
119-
120-
pomIncludeRepository := { _ => false }
121-
122-
lazy val readme = ScalatexReadme(
123-
projectId = "readme",
124-
wd = file(""),
125-
url = "https://github.com/scala-js/scala-js-dom/tree/master",
126-
source = "Index",
127-
autoResources = Seq("example-opt.js")
128-
).settings(
129-
scalaVersion := "2.12.10",
130-
scalacOptions ++= Seq("-deprecation", "-feature", "-Xfatal-warnings"),
131-
(Compile / resources) += (example / Compile / fullOptJS).value.data
132-
).settings(noPublishSettings: _*)
133-
134-
lazy val example = project.
135-
enablePlugins(ScalaJSPlugin).
136-
settings(commonSettings: _*).
137-
settings(noPublishSettings: _*).
138-
dependsOn(root)
139-
140-
addCommandAlias("prePR", "+prePR_nonCross")
141-
142-
val prePR_nonCross = taskKey[Unit]("Performs all necessary work required before submitting a PR, for a single version of Scala.")
143-
144-
ThisBuild / prePR_nonCross := Def.sequential(
145-
root / clean,
146-
root / Compile / scalafmt,
147-
Def.taskDyn {
148-
if (scalaVersion.value.startsWith("2."))
149-
(root / Compile / scalafix).toTask("")
150-
else
151-
Def.task[Unit]((root / Compile / compile).value)
152-
},
153-
example / Compile / compile,
154-
).value
1+
ThisBuild / homepage := Some(url("https://scala-js.org"))
2+
ThisBuild / licenses += ("MIT", url("https://opensource.org/licenses/mit-license.php"))
3+
ThisBuild / organization := "org.scala-js"
4+
ThisBuild / shellPrompt := ((s: State) => Project.extract(s).currentRef.project + "> ")
5+
ThisBuild / versionScheme := Some("early-semver")
6+
7+
val root = Build.root
8+
val scalafixRules = Build.scalafixRules
9+
val dom = Build.dom
10+
val example = Build.example
11+
val readme = Build.readme

prePR.sbt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import Build._
2+
3+
addCommandAlias("prePR", "+prePR_nonCross")
4+
5+
val prePR_nonCross = taskKey[Unit]("Performs all necessary work required before submitting a PR, for a single version of Scala.")
6+
7+
ThisBuild / prePR_nonCross := Def.sequential(
8+
root / clean,
9+
dom / Compile / scalafmt,
10+
Def.taskDyn {
11+
if (scalaVersion.value.startsWith("2."))
12+
(dom / Compile / scalafix).toTask("")
13+
else
14+
Def.task[Unit]((dom / Compile / compile).value)
15+
},
16+
root / Compile / compile,
17+
).value

project/Build.scala

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import sbt._
2+
import sbt.Keys._
3+
import org.scalajs.sbtplugin.ScalaJSPlugin
4+
import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport._
5+
import scalafix.sbt.ScalafixPlugin
6+
import scalafix.sbt.ScalafixPlugin.autoImport._
7+
import scalatex.ScalatexReadme
8+
import Dependencies._
9+
import Lib._
10+
11+
object Build {
12+
13+
// TODO: Change root from {.root => .} and dom from {. => dom}
14+
15+
lazy val root = project
16+
.in(file(".root"))
17+
.configure(commonSettings, crossScala, preventPublication)
18+
.settings(
19+
name := "Scala.js DOM",
20+
)
21+
.aggregate(
22+
scalafixRules,
23+
dom,
24+
example,
25+
// readme, // This is a Scala 2.12 only module
26+
)
27+
28+
lazy val dom = project
29+
.in(file("."))
30+
.dependsOn(scalafixRules % ScalafixConfig)
31+
.enablePlugins(ScalaJSPlugin, ScalafixPlugin)
32+
.configure(commonSettings, crossScala, publicationSetttings)
33+
.settings(
34+
moduleName := "scalajs-dom",
35+
Compile / unmanagedSourceDirectories +=
36+
collectionsEraDependentDirectory(scalaVersion.value, (Compile / sourceDirectory).value),
37+
)
38+
39+
lazy val scalafixRules = project
40+
.in(file("scalafix"))
41+
.configure(commonSettings, crossScala, preventPublication)
42+
.settings(
43+
libraryDependencies += Dep.scalafixCore.value,
44+
)
45+
46+
lazy val example = project
47+
.dependsOn(dom)
48+
.enablePlugins(ScalaJSPlugin)
49+
.configure(commonSettings, crossScala, preventPublication)
50+
51+
lazy val readme =
52+
ScalatexReadme(
53+
projectId = "readme",
54+
wd = file(""),
55+
url = "https://github.com/scala-js/scala-js-dom/tree/master",
56+
source = "Index",
57+
autoResources = Seq("example-opt.js"),
58+
)
59+
.configure(commonSettings, preventPublication)
60+
.settings(
61+
scalaVersion := Ver.scala212,
62+
Compile / resources += (example / Compile / fullOptJS).value.data,
63+
)
64+
65+
}

project/Dependencies.scala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import sbt._
2+
import sbt.Keys._
3+
import scalafix.sbt.BuildInfo.scalafixVersion
4+
5+
object Dependencies {
6+
7+
object Ver {
8+
val scala211 = "2.11.12"
9+
val scala212 = "2.12.14"
10+
val scala213 = "2.13.6"
11+
val scala3 = "3.0.1"
12+
}
13+
14+
object Dep {
15+
val scalafixCore = Def.setting("ch.epfl.scala" %% "scalafix-core" % scalafixVersion cross CrossVersion.for3Use2_13)
16+
}
17+
}

project/Lib.scala

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import sbt._
2+
import sbt.Keys._
3+
import Dependencies._
4+
5+
object Lib {
6+
7+
val inCI = sys.props.get("CI").exists(_.contains("1"))
8+
9+
def commonSettings: Project => Project = _
10+
.configure(sourceMapsToGithub)
11+
.settings(
12+
scalacOptions ++= Seq(
13+
"-deprecation",
14+
"-feature",
15+
),
16+
scalacOptions ++= (if (!inCI) Seq.empty else Seq(
17+
"-Xfatal-warnings",
18+
)),
19+
scalacOptions ++= (CrossVersion.partialVersion(scalaVersion.value) match {
20+
case Some((2, 11)) => "-Ywarn-unused-import" :: Nil
21+
case Some((2, 12)) => "-Ywarn-unused:imports,patvars,locals,implicits" :: Nil
22+
case Some((2, 13)) => "-Wunused:imports,patvars,locals,implicits" :: Nil
23+
case _ => Nil
24+
}),
25+
)
26+
27+
def crossScala: Project => Project = _
28+
.settings(
29+
crossScalaVersions := Seq(
30+
Ver.scala211,
31+
Ver.scala212,
32+
Ver.scala213,
33+
Ver.scala3,
34+
),
35+
scalaVersion := Ver.scala213,
36+
)
37+
38+
val publicationSetttings: Project => Project =
39+
_.settings(
40+
pomExtra := (
41+
<developers>
42+
<developer>
43+
<id>japgolly</id>
44+
<name>David Barri</name>
45+
<url>https://github.com/japgolly</url>
46+
</developer>
47+
<developer>
48+
<id>armanbilge</id>
49+
<name>Arman Bilge</name>
50+
<url>https://github.com/armanbilge</url>
51+
</developer>
52+
<developer>
53+
<id>sjrd</id>
54+
<name>Sébastien Doeraene</name>
55+
<url>https://github.com/sjrd/</url>
56+
</developer>
57+
<developer>
58+
<id>gzm0</id>
59+
<name>Tobias Schlatter</name>
60+
<url>https://github.com/gzm0/</url>
61+
</developer>
62+
<developer>
63+
<id>lihaoyi</id>
64+
<name>Li Haoyi</name>
65+
<url>https://github.com/lihaoyi/</url>
66+
</developer>
67+
</developers>
68+
),
69+
pomIncludeRepository := { _ => false },
70+
)
71+
72+
val preventPublication: Project => Project =
73+
_.settings(publish / skip := true)
74+
75+
private def sourceMapsToGithub: Project => Project =
76+
p => p.settings(
77+
scalacOptions ++= {
78+
val isDotty = scalaVersion.value startsWith "3"
79+
val ver = version.value
80+
if (isSnapshot.value)
81+
Nil
82+
else {
83+
val a = p.base.toURI.toString.replaceFirst("[^/]+/?$", "")
84+
val g = s"https://raw.githubusercontent.com/scala-js/scala-js-dom"
85+
val flag = if (isDotty) "-scalajs-mapSourceURI" else "-P:scalajs:mapSourceURI"
86+
s"$flag:$a->$g/v$ver/" :: Nil
87+
}
88+
}
89+
)
90+
91+
def hasNewCollections(version: String): Boolean =
92+
!version.startsWith("2.11.") && !version.startsWith("2.12.")
93+
94+
/** Returns the appropriate subdirectory of `sourceDir` depending on whether
95+
* the `scalaVer` uses the new collections (introduced in 2.13) or not.
96+
*/
97+
def collectionsEraDependentDirectory(scalaVer: String, sourceDir: File): File =
98+
if (hasNewCollections(scalaVer))
99+
sourceDir / "scala-new-collections"
100+
else
101+
sourceDir / "scala-old-collections"
102+
103+
}

project/plugins.sbt

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.5.1")
2-
3-
addSbtPlugin("com.lihaoyi" % "scalatex-sbt-plugin" % "0.3.11")
4-
5-
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.0.7")
6-
7-
addSbtPlugin("com.geirsson" % "sbt-ci-release" % "1.5.7")
8-
9-
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.30")
1+
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.30")
2+
addSbtPlugin("com.geirsson" % "sbt-ci-release" % "1.5.7")
3+
addSbtPlugin("com.lihaoyi" % "scalatex-sbt-plugin" % "0.3.11")
4+
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.5.1")
5+
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.0.7")

scalafix/src/main/scala/org/scalajs/dom/scalafix/MutableState.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package org.scalajs.dom.scalafix
33
import scala.annotation.tailrec
44
import scala.collection.immutable.SortedSet
55
import scala.collection.mutable
6-
import scala.meta._
76
import scalafix.v1._
87

98
final class MutableState {

0 commit comments

Comments
 (0)