diff --git a/build.sbt b/build.sbt index 7d0e81a5e..0d18f1e6b 100644 --- a/build.sbt +++ b/build.sbt @@ -1,154 +1,11 @@ -import _root_.scalafix.sbt.BuildInfo.scalafixVersion -import scalatex.ScalatexReadme - -ThisBuild / shellPrompt := ((s: State) => Project.extract(s).currentRef.project + "> ") - -lazy val scalafixRules = project - .in(file("scalafix")) - .settings( - libraryDependencies += ("ch.epfl.scala" %% "scalafix-core" % scalafixVersion).cross(CrossVersion.for3Use2_13), - ) - -def sourceMapsToGithub: Project => Project = - p => p.settings( - scalacOptions ++= { - val isDotty = scalaVersion.value startsWith "3" - val ver = version.value - if (isSnapshot.value) - Nil - else { - val a = p.base.toURI.toString.replaceFirst("[^/]+/?$", "") - val g = s"https://raw.githubusercontent.com/scala-js/scala-js-dom" - val flag = if (isDotty) "-scalajs-mapSourceURI" else "-P:scalajs:mapSourceURI" - s"$flag:$a->$g/v$ver/" :: Nil - } - } - ) - -lazy val root = project - .in(file(".")) - .enablePlugins(ScalaJSPlugin) - .enablePlugins(ScalafixPlugin) - .dependsOn(scalafixRules % ScalafixConfig) - .configure(sourceMapsToGithub) - -name := "Scala.js DOM" - -ThisBuild / crossScalaVersions := Seq("2.11.12", "2.12.14", "2.13.6", "3.0.1") -ThisBuild / scalaVersion := crossScalaVersions.value.find(_.startsWith("2.13.")).get - -val inCI = sys.props.get("CI").exists(_.contains("1")) - -val commonSettings = Seq( - organization := "org.scala-js", - scalacOptions ++= Seq( - "-deprecation", - "-feature", - ), - scalacOptions ++= (if (!inCI) Seq.empty else Seq( - "-Xfatal-warnings", - )), - scalacOptions ++= (CrossVersion.partialVersion(scalaVersion.value) match { - case Some((2, 11)) => "-Ywarn-unused-import" :: Nil - case Some((2, 12)) => "-Ywarn-unused:imports,patvars,locals,implicits" :: Nil - case Some((2, 13)) => "-Wunused:imports,patvars,locals,implicits" :: Nil - case _ => Nil - }), -) - -val noPublishSettings = Seq( - publish / skip := true -) - -normalizedName := "scalajs-dom" - -commonSettings - -homepage := Some(url("http://scala-js.org/")) - -licenses += ("MIT", url("http://opensource.org/licenses/mit-license.php")) - -def hasNewCollections(version: String): Boolean = { - !version.startsWith("2.11.") && - !version.startsWith("2.12.") -} - -/** Returns the appropriate subdirectory of `sourceDir` depending on whether - * the `scalaV` uses the new collections (introduced in 2.13) or not. - */ -def collectionsEraDependentDirectory(scalaV: String, sourceDir: File): File = - if (hasNewCollections(scalaV)) sourceDir / "scala-new-collections" - else sourceDir / "scala-old-collections" - -inConfig(Compile)(Def.settings( - unmanagedSourceDirectories += - collectionsEraDependentDirectory(scalaVersion.value, sourceDirectory.value) -)) - -versionScheme := Some("early-semver") - -pomExtra := ( - - - japgolly - David Barri - https://github.com/japgolly - - - armanbilge - Arman Bilge - https://github.com/armanbilge - - - sjrd - Sébastien Doeraene - https://github.com/sjrd/ - - - gzm0 - Tobias Schlatter - https://github.com/gzm0/ - - - lihaoyi - Li Haoyi - https://github.com/lihaoyi/ - - -) - -pomIncludeRepository := { _ => false } - -lazy val readme = ScalatexReadme( - projectId = "readme", - wd = file(""), - url = "https://github.com/scala-js/scala-js-dom/tree/master", - source = "Index", - autoResources = Seq("example-opt.js") -).settings( - scalaVersion := "2.12.10", - scalacOptions ++= Seq("-deprecation", "-feature", "-Xfatal-warnings"), - (Compile / resources) += (example / Compile / fullOptJS).value.data -).settings(noPublishSettings: _*) - -lazy val example = project. - enablePlugins(ScalaJSPlugin). - settings(commonSettings: _*). - settings(noPublishSettings: _*). - dependsOn(root) - -addCommandAlias("prePR", "+prePR_nonCross") - -val prePR_nonCross = taskKey[Unit]("Performs all necessary work required before submitting a PR, for a single version of Scala.") - -ThisBuild / prePR_nonCross := Def.sequential( - root / clean, - root / Compile / scalafmt, - Def.taskDyn { - if (scalaVersion.value.startsWith("2.")) - (root / Compile / scalafix).toTask("") - else - Def.task[Unit]((root / Compile / compile).value) - }, - example / Compile / compile, -).value +ThisBuild / homepage := Some(url("https://scala-js.org")) +ThisBuild / licenses += ("MIT", url("https://opensource.org/licenses/mit-license.php")) +ThisBuild / organization := "org.scala-js" +ThisBuild / shellPrompt := ((s: State) => Project.extract(s).currentRef.project + "> ") +ThisBuild / versionScheme := Some("early-semver") + +val root = Build.root +val scalafixRules = Build.scalafixRules +val dom = Build.dom +val example = Build.example +val readme = Build.readme diff --git a/prePR.sbt b/prePR.sbt new file mode 100644 index 000000000..515fae1d5 --- /dev/null +++ b/prePR.sbt @@ -0,0 +1,17 @@ +import Build._ + +addCommandAlias("prePR", "+prePR_nonCross") + +val prePR_nonCross = taskKey[Unit]("Performs all necessary work required before submitting a PR, for a single version of Scala.") + +ThisBuild / prePR_nonCross := Def.sequential( + root / clean, + dom / Compile / scalafmt, + Def.taskDyn { + if (scalaVersion.value.startsWith("2.")) + (dom / Compile / scalafix).toTask("") + else + Def.task[Unit]((dom / Compile / compile).value) + }, + root / Compile / compile, +).value diff --git a/project/Build.scala b/project/Build.scala new file mode 100644 index 000000000..de90efa55 --- /dev/null +++ b/project/Build.scala @@ -0,0 +1,65 @@ +import sbt._ +import sbt.Keys._ +import org.scalajs.sbtplugin.ScalaJSPlugin +import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport._ +import scalafix.sbt.ScalafixPlugin +import scalafix.sbt.ScalafixPlugin.autoImport._ +import scalatex.ScalatexReadme +import Dependencies._ +import Lib._ + +object Build { + + // TODO: Change root from {.root => .} and dom from {. => dom} + + lazy val root = project + .in(file(".root")) + .configure(commonSettings, crossScala, preventPublication) + .settings( + name := "Scala.js DOM", + ) + .aggregate( + scalafixRules, + dom, + example, + // readme, // This is a Scala 2.12 only module + ) + + lazy val dom = project + .in(file(".")) + .dependsOn(scalafixRules % ScalafixConfig) + .enablePlugins(ScalaJSPlugin, ScalafixPlugin) + .configure(commonSettings, crossScala, publicationSetttings) + .settings( + moduleName := "scalajs-dom", + Compile / unmanagedSourceDirectories += + collectionsEraDependentDirectory(scalaVersion.value, (Compile / sourceDirectory).value), + ) + + lazy val scalafixRules = project + .in(file("scalafix")) + .configure(commonSettings, crossScala, preventPublication) + .settings( + libraryDependencies += Dep.scalafixCore.value, + ) + + lazy val example = project + .dependsOn(dom) + .enablePlugins(ScalaJSPlugin) + .configure(commonSettings, crossScala, preventPublication) + + lazy val readme = + ScalatexReadme( + projectId = "readme", + wd = file(""), + url = "https://github.com/scala-js/scala-js-dom/tree/master", + source = "Index", + autoResources = Seq("example-opt.js"), + ) + .configure(commonSettings, preventPublication) + .settings( + scalaVersion := Ver.scala212, + Compile / resources += (example / Compile / fullOptJS).value.data, + ) + +} diff --git a/project/Dependencies.scala b/project/Dependencies.scala new file mode 100644 index 000000000..48bcddade --- /dev/null +++ b/project/Dependencies.scala @@ -0,0 +1,17 @@ +import sbt._ +import sbt.Keys._ +import scalafix.sbt.BuildInfo.scalafixVersion + +object Dependencies { + + object Ver { + val scala211 = "2.11.12" + val scala212 = "2.12.14" + val scala213 = "2.13.6" + val scala3 = "3.0.1" + } + + object Dep { + val scalafixCore = Def.setting("ch.epfl.scala" %% "scalafix-core" % scalafixVersion cross CrossVersion.for3Use2_13) + } +} diff --git a/project/Lib.scala b/project/Lib.scala new file mode 100644 index 000000000..26727423e --- /dev/null +++ b/project/Lib.scala @@ -0,0 +1,103 @@ +import sbt._ +import sbt.Keys._ +import Dependencies._ + +object Lib { + + val inCI = sys.props.get("CI").exists(_.contains("1")) + + def commonSettings: Project => Project = _ + .configure(sourceMapsToGithub) + .settings( + scalacOptions ++= Seq( + "-deprecation", + "-feature", + ), + scalacOptions ++= (if (!inCI) Seq.empty else Seq( + "-Xfatal-warnings", + )), + scalacOptions ++= (CrossVersion.partialVersion(scalaVersion.value) match { + case Some((2, 11)) => "-Ywarn-unused-import" :: Nil + case Some((2, 12)) => "-Ywarn-unused:imports,patvars,locals,implicits" :: Nil + case Some((2, 13)) => "-Wunused:imports,patvars,locals,implicits" :: Nil + case _ => Nil + }), + ) + + def crossScala: Project => Project = _ + .settings( + crossScalaVersions := Seq( + Ver.scala211, + Ver.scala212, + Ver.scala213, + Ver.scala3, + ), + scalaVersion := Ver.scala213, + ) + + val publicationSetttings: Project => Project = + _.settings( + pomExtra := ( + + + japgolly + David Barri + https://github.com/japgolly + + + armanbilge + Arman Bilge + https://github.com/armanbilge + + + sjrd + Sébastien Doeraene + https://github.com/sjrd/ + + + gzm0 + Tobias Schlatter + https://github.com/gzm0/ + + + lihaoyi + Li Haoyi + https://github.com/lihaoyi/ + + + ), + pomIncludeRepository := { _ => false }, + ) + + val preventPublication: Project => Project = + _.settings(publish / skip := true) + + private def sourceMapsToGithub: Project => Project = + p => p.settings( + scalacOptions ++= { + val isDotty = scalaVersion.value startsWith "3" + val ver = version.value + if (isSnapshot.value) + Nil + else { + val a = p.base.toURI.toString.replaceFirst("[^/]+/?$", "") + val g = s"https://raw.githubusercontent.com/scala-js/scala-js-dom" + val flag = if (isDotty) "-scalajs-mapSourceURI" else "-P:scalajs:mapSourceURI" + s"$flag:$a->$g/v$ver/" :: Nil + } + } + ) + + def hasNewCollections(version: String): Boolean = + !version.startsWith("2.11.") && !version.startsWith("2.12.") + + /** Returns the appropriate subdirectory of `sourceDir` depending on whether + * the `scalaVer` uses the new collections (introduced in 2.13) or not. + */ + def collectionsEraDependentDirectory(scalaVer: String, sourceDir: File): File = + if (hasNewCollections(scalaVer)) + sourceDir / "scala-new-collections" + else + sourceDir / "scala-old-collections" + +} diff --git a/project/plugins.sbt b/project/plugins.sbt index 248f964c3..51e7424b4 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,9 +1,5 @@ -addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.5.1") - -addSbtPlugin("com.lihaoyi" % "scalatex-sbt-plugin" % "0.3.11") - -addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.0.7") - -addSbtPlugin("com.geirsson" % "sbt-ci-release" % "1.5.7") - -addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.30") +addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.30") +addSbtPlugin("com.geirsson" % "sbt-ci-release" % "1.5.7") +addSbtPlugin("com.lihaoyi" % "scalatex-sbt-plugin" % "0.3.11") +addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.5.1") +addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.0.7") diff --git a/scalafix/src/main/scala/org/scalajs/dom/scalafix/MutableState.scala b/scalafix/src/main/scala/org/scalajs/dom/scalafix/MutableState.scala index 679027465..7e0882f2e 100644 --- a/scalafix/src/main/scala/org/scalajs/dom/scalafix/MutableState.scala +++ b/scalafix/src/main/scala/org/scalajs/dom/scalafix/MutableState.scala @@ -3,7 +3,6 @@ package org.scalajs.dom.scalafix import scala.annotation.tailrec import scala.collection.immutable.SortedSet import scala.collection.mutable -import scala.meta._ import scalafix.v1._ final class MutableState {