Skip to content

Allow users to fully customize Scala.js linker config via a new module - #6872

Merged
alexarchambault merged 3 commits into
com-lihaoyi:mainfrom
alexarchambault:scala-js-config
Feb 23, 2026
Merged

alexarchambault merged 3 commits into
com-lihaoyi:mainfrom
alexarchambault:scala-js-config

Conversation

@alexarchambault

@alexarchambault alexarchambault commented Feb 23, 2026 •

Copy link
Copy Markdown
Collaborator

This adds a new mill-libs-scalajslib-config module, that provides a new ScalaJSConfigModule, that users can use instead of ScalaJSModule. ScalaJSConfigModule allows users to adjust the Scala.js linker configuration using the Scala.js linker's own API, rather than Mill's redefinition of it, that lags behind and is lacking compared to the original one.

The ScalaJSConfigModule scaladoc explains how this module should be used. Basically, users need to add mill-libs-scalajslib-config in their build via the meta-build, alongside the versions they need of the Scala.js linker and js-deps modules. Like

import mill._
import mill.scalalib._

object `package` extends mill.meta.MillBuildRootModule {

  def scalaJSVersion = "1.20.2" // Scala.js version users want
 
  def mvnDeps = Seq(
    mvn"com.lihaoyi::mill-libs-scalajslib-config-1:${mill.api.BuildInfo.millVersion}",
    mvn"org.scala-js:scalajs-linker_2.13:$scalaJSVersion",
    mvn"org.scala-js:scalajs-js-envs_2.13:1.4.0"
  )
}

The corresponding linker API can then be used to customize the linker configuration:

package build
import mill.*
import mill.scalajslib.*
import mill.scalajslib.config.*
import mill.scalalib.*

object `package` extends ScalaJSConfigModule {
  def scalaVersion = "3.3.1"
  def mvnDeps = Seq(
    mvn"com.lihaoyi::upickle::4.4.1"
  )
  def scalaJSConfig = Task.Anon {
    super.scalaJSConfig()
      .withCheckIR(true)
      // ...
  }
  // two more tasks can be customized using the Scala.js linker's own API:
  // moduleInitializers: Task[Seq[org.scalajs.linker.interface.ModuleInitializer]]
  // scalaJsInputs: Task[Seq[org.scalajs.jsenv.Input]]
}

In more detail, bits of the current worker module were moved to the new config module (mainly code going from Mill's Scala.js linker params to actual Scala.js linker API stuff). The worker depends on the config module, in order to keep using the code that was moved.

If they feel like it, users can add the new config module in their build, alongside the linker and js-deps Scala.js modules. This somehow pre-loads parts of the worker class path in the main build. Later on, when the worker class path is loaded, parts of it (config and the mentioned Scala.js modules) are simply already around, and not isolated.

A drawback is that this prevents using any other Scala.js version in builds that do this: given some Scala.js JARs are already in the main build class path, they would clash with any other Scala.js version JARs loaded for the worker. But this limitation only applies to users that pre-load these modules, not users of the current ScalaJSModule.

@alexarchambault
alexarchambault marked this pull request as ready for review February 23, 2026 17:19
@alexarchambault
alexarchambault merged commit e5a5d9c into com-lihaoyi:main Feb 23, 2026
45 checks passed
@alexarchambault
alexarchambault deleted the scala-js-config branch February 23, 2026 23:20
@lefou lefou added this to the 1.1.3 milestone Feb 24, 2026
lihaoyi pushed a commit that referenced this pull request Mar 5, 2026
…dule, and add tests for it (#6902)

This cleans-up / clarifies the handling of full optimized Scala.js
linking in the newly added `ScalaJSConfigModule` (added in
#6872).

Full optimized linking is "just" a matter of setting the right
properties in the linker config. So instead of passing around an
`isFullLinkJS` flag alongside a linking config, we now just let users
make the config fully optimized, and only pass the config around.

The added tests check that fully optimized linking is taken into account
in `run` and `testForked`.
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.

3 participants