Skip to content

Commit 2452f5a

Browse files
authored
Merge pull request scala-js#4613 from sjrd/warn-when-scalajs-compiler-flag-plugin-missing
Fix scala-js#4610: Warn when `-scalajs` or `-Xplugin:scalajs-compiler.jar` is missing.
2 parents 316b0a7 + ea6c65d commit 2452f5a

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

sbt-plugin/src/main/scala/org/scalajs/sbtplugin/ScalaJSPluginInternal.scala

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,26 @@ private[sbtplugin] object ScalaJSPluginInternal {
366366
val classpath = Attributed.data(fullClasspath.value)
367367
val log = streams.value.log
368368
val tlog = sbtLogger2ToolsLogger(log)
369+
val config = configuration.value.name
370+
371+
/* #4610 Warn if `-Xplugin:scalajs-compiler.jar` (Scala 2) or
372+
* `-scalajs` (Scala 3) is missing from the `scalacOptions`.
373+
* This feature is not automatically tested.
374+
*/
375+
def warnMissingScalacOption(thingMissing: String): Unit = {
376+
log.warn(
377+
s"$thingMissing was missing from `$config / scalacOptions`, but it is required to produce Scala.js IR.")
378+
log.warn("Linking, running and/or testing will probably go wrong.")
379+
log.warn("The most likely cause is that you used `scalacOptions := ...` instead of using `++=`.")
380+
}
381+
val scalacOpts = scalacOptions.value
382+
if (scalaVersion.value.startsWith("2.")) {
383+
if (!scalacOpts.exists(opt => opt.startsWith("-Xplugin:") && opt.contains("scalajs-compiler")))
384+
warnMissingScalacOption("The `scalajs-compiler.jar` compiler plugin")
385+
} else {
386+
if (!scalacOpts.contains("-scalajs"))
387+
warnMissingScalacOption("The `-scalajs` flag")
388+
}
369389

370390
val (irFiles, paths) = enhanceIRVersionNotSupportedException {
371391
tlog.time("Update IR cache") {

0 commit comments

Comments
 (0)