Skip to content

add scala.js support - #33

Open
sief wants to merge 1 commit into
dwickern:masterfrom
sief:add-scalajs-support
Open

add scala.js support#33
sief wants to merge 1 commit into
dwickern:masterfrom
sief:add-scalajs-support

Conversation

@sief

@sief sief commented Aug 27, 2026

Copy link
Copy Markdown

Fixes #24. Scala.js support was dropped in 8771b8b when Scala 3 support was
added; this adds the .jsPlatform rows back.

3.0.0  _2.11 _2.12 _2.13 _sjs1_2.11 _sjs1_2.12 _sjs1_2.13
5.0.0  _2.12 _2.13 _3

Since the build already uses sbt-projectmatrix, this mirrors the existing
.jvmPlatform rows rather than restructuring into crossProject. Published
artifacts go from 3 to 6 (Scala 3.3.8 / 2.13.18 / 2.12.21 × JVM / JS).

  • add sbt-scalajs 1.22.0
  • extract the per-version deps into scala2Settings / scala3Settings so
    both platforms share them instead of duplicating across four rows
  • test deps %%%%% to resolve the _sjs1_ artifacts
  • javax.annotation-api moves to a jvmSettings seq — it's a plain Java
    artifact used only by AnnotationTest
  • install Node.js in the test workflow, which the JS test rows run against
  • README: document %%%, note the Node requirement, and correct the install
    snippet from 4.0.0 to 5.0.0

Toolchain bumps

The Scala.js artifacts require newer standard libraries than the pinned
compilers, so adding the JS rows would otherwise leave each row compiling
against a scala-library newer than its own compiler — the direction SIP-51
warns about:

requires scala-library
scalajs-library_2.13 1.22.0 2.13.18 (build pinned 2.13.16)
scalajs-library_2.12 1.22.0 2.12.21 (build pinned 2.12.20)
scala3-library_3 3.3.5 2.13.15, vs 2.13.18 on the JS classpath

Scala moves to 3.3.8 / 2.13.18 / 2.12.21, staying on the 3.3.x LTS line.

sbt moves 1.9.9 → 1.13.0, which is what enforces SIP-51 — on 1.9.9 the
mismatch above compiles silently, so pinning 1.13.0 makes it a checked
invariant rather than a convention. test, mdoc and publishLocal are all
clean on 1.13.0, and ci-release behaves identically to 1.9.9 with
sbt-ci-release 1.9.2.

No main-source changes were needed

src/main has no platform directories, so the source compiled for JS is
identical to the JVM source. AnnotationTest already lives in
src/test/scalajvm, so projectmatrix excludes it from the JS rows.
ConstantsTest references the Java class JavaConstants, but only inside
nameOf(...), which the macro erases to a string literal — javac compiles it
so the test typechecks, and no reference reaches the linker.

src/test/scalajs/ScalaJsTest.scala is new: it covers js.* types and facade
members, and asserts the macros still produce compile-time constants via
@JSExportTopLevel, whose argument must be a literal string. That property is
otherwise only tested by the JVM-only AnnotationTest, so without it the JS
rows would lose the guarantee entirely.

Verification

sbt test mdoc passes on all six rows:

Row Suites Tests
JVM 3.3.8 5 49
JS 3.3.8 5 47
JVM 2.13.18 / 2.12.21 4 45 each
JS 2.13.18 / 2.12.21 4 43 each

The JVM/JS delta is 2 on every version: JS lacks AnnotationTest's 5 cases
and gains ScalaJsTest's 3.

Separately, I published the artifacts locally and built a small consumer
project against them — %% on the JVM and %%% on Scala.js, both provided,
as the README instructs. All four combinations (JVM/JS × Scala 3.3.8/2.13.18)
resolve, link, and print the expected names, and the fully optimized JS output
contains the computed names as literals with no reference to the library.

Scala.js 1.22.0's linker is Java 8 bytecode, so CI stays on JDK 8.

Note: no 5.x release has JS artifacts yet, so the README's Scala.js line
deliberately doesn't pin a version — the first release cut after this merge
will be the first resolvable with %%%.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Scala.js in v4.0.0

1 participant