Skip to content

Commit 2d415e1

Browse files
committed
Merge branch 'topic/mima' into issue/445
2 parents 4fe536d + 69df48c commit 2d415e1

19 files changed

+49384
-21
lines changed

.github/pull_request_template.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Hi there!
2+
3+
Before submitting a PR containing any Scala changes, please make sure you...
4+
5+
* run `sbt prePR`
6+
* commit changes to `api-reports`
7+
8+
Thanks for contributing!

.github/release-drafter.yml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name-template: 'v$NEXT_PATCH_VERSION'
2+
tag-template: 'v$NEXT_PATCH_VERSION'
3+
template: |
4+
# What's Changed
5+
$CHANGES
6+
categories:
7+
- title: 'New'
8+
label: 'type: feature'
9+
- title: 'Bug Fixes'
10+
label: 'type: bug'
11+
- title: 'Maintenance'
12+
label: 'type: maintenance'
13+
- title: 'Documentation'
14+
label: 'type: docs'
15+
- title: 'Dependency Updates'
16+
label: 'type: dependencies'

.github/workflows/ci.yml

+14-1
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,33 @@ jobs:
2121
env:
2222
SCALAJS_VERSION: "${{ matrix.scalajsversion == '0.6.x' && '0.6.28' || '' }}"
2323
steps:
24+
2425
- uses: actions/checkout@v2
2526
- uses: olafurpg/setup-scala@v13
2627
with:
2728
java-version: "[email protected]"
2829
- uses: coursier/cache-action@v6
30+
31+
- name: Hacks for Scala 2.10
32+
if: matrix.scalaversion == '2.10.7'
33+
run: ./prepareForScala210.sh
34+
2935
- name: Build
3036
run: sbt "++${{ matrix.scalaversion }}" package
37+
3138
- name: Test generate documentation
3239
run: sbt "++${{ matrix.scalaversion }}" doc
40+
3341
- name: Build examples
3442
run: sbt "++${{ matrix.scalaversion }}" example/compile
35-
- name: scalafmt
43+
44+
- name: Validate formatting
3645
run: sbt "++${{ matrix.scalaversion }}" scalafmtCheck
3746

47+
- name: Validate api report
48+
if: matrix.scalajsversion == '1.x' && matrix.scalaversion != '2.11.12'
49+
run: ./api-reports/validate "${{ matrix.scalaversion }}"
50+
3851
readme:
3952
runs-on: ubuntu-latest
4053
steps:

.github/workflows/release-drafter.yml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Release Drafter
2+
3+
on:
4+
push:
5+
# branches to consider in the event; optional, defaults to all
6+
branches:
7+
- master
8+
- series/1.x
9+
10+
jobs:
11+
update_release_draft:
12+
runs-on: ubuntu-latest
13+
steps:
14+
# Drafts your next Release notes as Pull Requests are merged into "master"
15+
- uses: release-drafter/release-drafter@v5
16+
env:
17+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/release.yml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Release
2+
on:
3+
push:
4+
branches: ["master", "series/1.x"]
5+
tags: ["v*"]
6+
jobs:
7+
publish:
8+
runs-on: ubuntu-latest
9+
strategy:
10+
matrix:
11+
scalajsversion: ["1.x", "0.6.x"]
12+
env:
13+
SCALAJS_VERSION: "${{ matrix.scalajsversion == '0.6.x' && '0.6.28' || '' }}"
14+
steps:
15+
- uses: actions/checkout@v2
16+
with:
17+
fetch-depth: 0
18+
- uses: olafurpg/setup-scala@v13
19+
- run: sbt ci-release
20+
env:
21+
PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}
22+
PGP_SECRET: ${{ secrets.PGP_SECRET }}
23+
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
24+
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
.idea_modules
77
.metals
88
.project
9+
.sbtboot
910
.settings/
1011
.vscode
1112
metals.sbt

.scalafix.conf

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
rules = [
2+
GenerateApiReport,
3+
]

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[Documentation](http://scala-js.github.io/scala-js-dom)
1+
[Documentation](http://scala-js.github.io/scala-js-dom) / [Scaladoc](https://javadoc.io/doc/org.scala-js/scalajs-dom_sjs1_2.13)

api-reports/2_12.txt

+24,453
Large diffs are not rendered by default.

api-reports/2_13.txt

+24,453
Large diffs are not rendered by default.

api-reports/validate

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
cd "$(dirname "$0")"
4+
5+
[ $# -ne 1 ] && echo "Usage: $0 <scala version>" && exit 1
6+
7+
series="${1%.*}"
8+
file="${series/./_}.txt"
9+
echo -n "Validating $file ... "
10+
11+
help='Run `sbt +compile` and check in the differences to the '"$(basename "$0") directory"
12+
13+
if [ ! -e "$file" ]; then
14+
echo "file not found. $help"
15+
exit 2
16+
elif [ -n "$(git status --porcelain -- "$file")" ]; then
17+
echo "out-of-date. $help"
18+
exit 3
19+
else
20+
echo "ok"
21+
fi

build.sbt

+32-19
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
1+
import _root_.scalafix.sbt.BuildInfo.scalafixVersion // delete if Scala 2.10
12
import scalatex.ScalatexReadme
23

3-
lazy val root = project.in(file(".")).
4-
enablePlugins(ScalaJSPlugin)
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, // delete if Scala 2.10
10+
)
11+
12+
lazy val root = project
13+
.in(file("."))
14+
.enablePlugins(ScalaJSPlugin)
15+
.enablePlugins(ScalafixPlugin) // delete if Scala 2.10
16+
.dependsOn(scalafixRules % ScalafixConfig) // delete if Scala 2.10
517

618
name := "Scala.js DOM"
719

@@ -12,11 +24,14 @@ ThisBuild / crossScalaVersions := {
1224
ThisBuild / scalaVersion := crossScalaVersions.value.head
1325

1426
val commonSettings = Seq(
15-
version := "1.2.0-SNAPSHOT",
1627
organization := "org.scala-js",
1728
scalacOptions ++= Seq("-deprecation", "-feature", "-Xfatal-warnings")
1829
)
1930

31+
val noPublishSettings = Seq(
32+
publish / skip := true
33+
)
34+
2035
normalizedName := "scalajs-dom"
2136

2237
commonSettings
@@ -58,21 +73,6 @@ scalacOptions ++= {
5873
else Nil
5974
}
6075

61-
scmInfo := Some(ScmInfo(
62-
url("https://github.com/scala-js/scala-js-dom"),
63-
"scm:git:[email protected]:scala-js/scala-js-dom.git",
64-
Some("scm:git:[email protected]:scala-js/scala-js-dom.git")))
65-
66-
publishMavenStyle := true
67-
68-
publishTo := {
69-
val nexus = "https://oss.sonatype.org/"
70-
if (isSnapshot.value)
71-
Some("snapshots" at nexus + "content/repositories/snapshots")
72-
else
73-
Some("releases" at nexus + "service/local/staging/deploy/maven2")
74-
}
75-
7676
pomExtra := (
7777
<developers>
7878
<developer>
@@ -115,9 +115,22 @@ lazy val readme = ScalatexReadme(
115115
scalaVersion := "2.12.10",
116116
scalacOptions ++= Seq("-deprecation", "-feature", "-Xfatal-warnings"),
117117
(Compile / resources) += (example / Compile / fullOptJS).value.data
118-
)
118+
).settings(noPublishSettings: _*)
119119

120120
lazy val example = project.
121121
enablePlugins(ScalaJSPlugin).
122122
settings(commonSettings: _*).
123+
settings(noPublishSettings: _*).
123124
dependsOn(root)
125+
126+
addCommandAlias("prePR", "+prePR_nonCross")
127+
128+
val prePR_nonCross = taskKey[Unit]("Performs all necessary work required before submitting a PR, for a single version of Scala.")
129+
130+
ThisBuild / prePR_nonCross := Def.sequential(
131+
root / clean,
132+
root / Compile / scalafmt,
133+
root / Compile / compile,
134+
(root / Compile / scalafix).toTask(""), // delete if Scala 2.10
135+
example / Compile / compile,
136+
).value

prepareForScala210.sh

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
cd "$(dirname "$0")"
4+
5+
sed -i -e '/delete if Scala 2.10/d' *.sbt project/*.sbt
6+
rm scalafix.sbt

project/plugins.sbt

+4
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@ addSbtPlugin("org.scala-js" % "sbt-scalajs" % scalaJSVersion)
66
addSbtPlugin("com.lihaoyi" % "scalatex-sbt-plugin" % "0.3.11")
77

88
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.0.0")
9+
10+
addSbtPlugin("com.geirsson" % "sbt-ci-release" % "1.5.7")
11+
12+
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.29") // delete if Scala 2.10

scalafix.sbt

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
ThisBuild / semanticdbEnabled := true
2+
ThisBuild / semanticdbVersion := "4.4.27"
3+
ThisBuild / scalafixScalaBinaryVersion := CrossVersion.binaryScalaVersion(scalaVersion.value)
4+
5+
ThisBuild / scalacOptions ++= {
6+
if (scalaVersion.value startsWith "2")
7+
"-Yrangepos" :: Nil
8+
else
9+
Nil
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.scalajs.dom.scalafix.GenerateApiReport
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
package org.scalajs.dom.scalafix
2+
3+
import java.nio.charset.StandardCharsets
4+
import java.nio.file.{Paths, Files}
5+
import scala.meta._
6+
import scalafix.v1._
7+
8+
class GenerateApiReport extends SemanticRule("GenerateApiReport") {
9+
import MutableState.{global => state, ScopeType}
10+
11+
private[this] def enabled = state ne null
12+
13+
override def beforeStart(): Unit = {
14+
Util.scalaSeriesVer match {
15+
case "2.11" => // disabled - can't read classfiles
16+
case _ => MutableState.global = new MutableState // can't set state= in early Scala versions
17+
}
18+
}
19+
20+
override def fix(implicit doc: SemanticDocument): Patch = {
21+
22+
if (enabled)
23+
doc.tree.traverse {
24+
case a: Defn.Class => process(a.symbol, a.templ, ScopeType.Class)
25+
case a: Defn.Object => process(a.symbol, a.templ, ScopeType.Object)
26+
case a: Defn.Trait => process(a.symbol, a.templ, ScopeType.Trait)
27+
case a: Pkg.Object => process(a.symbol, a.templ, ScopeType.Object)
28+
case _ =>
29+
}
30+
31+
Patch.empty
32+
}
33+
34+
private def process(sym: Symbol, body: Template, typ: ScopeType)(implicit doc: SemanticDocument): Unit = {
35+
// Skip non-public scopes
36+
val info = sym.info.get
37+
if (!info.isPublic && !info.isPackageObject)
38+
return
39+
40+
val parents = Util.parents(sym).iterator.map(Util.typeSymbol).toList
41+
val domParents = parents.iterator.filter(isScalaJsDom).toSet
42+
val isJsType = parents.exists(isScalaJs)
43+
val s = state.register(sym, isJsType, typ, domParents)
44+
45+
def letsSeeHowLazyWeCanBeLol(t: Tree): Unit = {
46+
// Skip non-public members
47+
if (!t.symbol.info.get.isPublic)
48+
return
49+
50+
// Remove definition bodies
51+
val t2: Tree =
52+
t match {
53+
case Defn.Def(mods, name, tparams, paramss, Some(tpe), _) => Decl.Def(mods, name, tparams, paramss, tpe)
54+
case Defn.Val(mods, pats, Some(tpe), _) => Decl.Val(mods, pats, tpe)
55+
case Defn.Var(mods, pats, Some(tpe), _) => Decl.Var(mods, pats, tpe)
56+
case _ => t
57+
}
58+
59+
val desc =
60+
t2
61+
.toString
62+
.replace('\n', ' ')
63+
.replace("=", " = ")
64+
.replace("@inline ", "")
65+
.replaceAll(", *", ", ")
66+
.replaceAll(" {2,}", " ")
67+
.trim
68+
.stripSuffix(" = js.native")
69+
.replaceAll(" = js.native(?=[^\n])", "?")
70+
71+
s.add(desc)
72+
}
73+
74+
body.traverse {
75+
76+
// Skip inner members that we collect at the outer scope
77+
case _: Defn.Class =>
78+
case _: Defn.Object =>
79+
case _: Defn.Trait =>
80+
case _: Pkg.Object =>
81+
82+
case d: Decl => letsSeeHowLazyWeCanBeLol(d)
83+
case d: Defn => letsSeeHowLazyWeCanBeLol(d)
84+
85+
case _ =>
86+
}
87+
}
88+
89+
private def isScalaJs(sym: Symbol): Boolean =
90+
sym.toString startsWith "scala/scalajs/js/"
91+
92+
private def isScalaJsDom(sym: Symbol): Boolean =
93+
sym.toString startsWith "org/scalajs/dom/"
94+
95+
override def afterComplete(): Unit =
96+
if (enabled) {
97+
saveReport()
98+
MutableState.global = null // can't set state= in early Scala versions
99+
}
100+
101+
private def saveReport(): Unit = {
102+
val scalaVer = Util.scalaSeriesVer.replace('.', '_')
103+
val projectRoot = System.getProperty("user.dir")
104+
val reportFile = Paths.get(s"$projectRoot/api-reports/$scalaVer.txt")
105+
val api = state.result().iterator.map(_.stripPrefix("org/scalajs/dom/")).mkString("\n")
106+
107+
val content =
108+
s"""|scala-js-dom API
109+
|================
110+
|
111+
|This is generated automatically on compile via custom Scalafix rule '${name.value}'.
112+
|
113+
|Flags:
114+
| [J-] = JavaScript type
115+
| [S-] = Scala type
116+
| [-${ScopeType.Class.id}] = Class
117+
| [-${ScopeType.Trait.id}] = Trait
118+
| [-${ScopeType.Object.id}] = Object
119+
|
120+
|
121+
|$api
122+
|""".stripMargin
123+
124+
println(s"[info] Generating $reportFile")
125+
Files.write(reportFile, content.getBytes(StandardCharsets.UTF_8))
126+
}
127+
}

0 commit comments

Comments
 (0)