Skip to content

Commit e524bc3

Browse files
committed
Let's see if this fixes classpath issues.
1 parent 96addd7 commit e524bc3

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

scalajslib/src/mill/scalajslib/ScalaJSModule.scala

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,13 @@ trait ScalaJSModule extends scalalib.ScalaModule { outer =>
7474
def scalaJSLinkerClasspath: T[Loose.Agg[PathRef]] = T {
7575
val commonDeps = Seq(
7676
ivy"org.scala-js::scalajs-sbt-test-adapter:${scalaJSVersion()}",
77-
ivy"com.armanbilge::scalajs-importmap:0.1.1"
77+
7878
)
79+
val maybeImportMap = scalaJSVersion() match {
80+
case s"1.$n.$_" if n.toIntOption.exists(_ < 16) => Seq[Dep]()
81+
case _ => Seq(ivy"com.armanbilge::scalajs-importmap:0.1.1")
82+
}
83+
7984
val envDeps = scalaJSBinaryVersion() match {
8085
case "0.6" =>
8186
Seq(
@@ -90,13 +95,13 @@ trait ScalaJSModule extends scalalib.ScalaModule { outer =>
9095
// we need to use the scala-library of the currently running mill
9196
resolveDependencies(
9297
repositoriesTask(),
93-
(commonDeps.iterator ++ envDeps)
98+
(commonDeps.iterator ++ envDeps ++ maybeImportMap)
9499
.map(Lib.depToBoundDep(_, mill.main.BuildInfo.scalaVersion, "")),
95100
ctx = Some(T.log)
96101
)
97102
}
98103

99-
def scalaJSToolsClasspath = T { scalaJSWorkerClasspath() ++ scalaJSLinkerClasspath() }
104+
def scalaJSToolsClasspath = T { scalaJSWorkerClasspath() ++ scalaJSLinkerClasspath()}
100105

101106
def fastLinkJS: Target[Report] = T.persistent {
102107
linkTask(isFullLinkJS = false, forceOutJs = false)()
@@ -268,9 +273,11 @@ trait ScalaJSModule extends scalalib.ScalaModule { outer =>
268273

269274
def moduleSplitStyle: Target[ModuleSplitStyle] = T { ModuleSplitStyle.FewestModules }
270275

271-
def scalaJSOptimizer: Target[Boolean] = T { true }
276+
def scalaJSOptimizer: Target[Boolean] = T { true }
272277

273-
def esModuleRemap: Target[Map[String, String]] = T { Map.empty[String, String] }
278+
def esModuleRemap: Target[Map[String, String]] = T {
279+
Map.empty[String, String]
280+
}
274281

275282
/** Whether to emit a source map. */
276283
def scalaJSSourceMap: Target[Boolean] = T { true }

scalajslib/test/src/mill/scalajslib/RemapEsModuleTests.scala

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ object EsModuleRemapTests extends TestSuite {
2525
)
2626
}
2727

28+
object OldJsModule extends ScalaJSModule {
29+
override def millSourcePath = workspacePath
30+
override def scalaVersion = sys.props.getOrElse("TEST_SCALA_2_13_VERSION", ???)
31+
override def scalaJSVersion = "1.15.0"
32+
override def scalaJSSourceMap = false
33+
override def moduleKind = ModuleKind.ESModule
34+
35+
override def esModuleRemap: Target[Map[String, String]] = Map(
36+
"@stdlib/linspace" -> remapTo
37+
)
38+
}
39+
2840
override lazy val millDiscover = Discover[this.type]
2941
}
3042

@@ -47,6 +59,13 @@ object EsModuleRemapTests extends TestSuite {
4759
val rawJs = os.read.lines(mainPath)
4860
assert(rawJs(1).contains(remapTo))
4961
}
62+
63+
test("should throw for older scalaJS versions") {
64+
val Left(ex) = evaluator(EsModuleRemap.OldJsModule.fastLinkJS)
65+
val error = ex.asFailing.get.toString()
66+
assert(error.contains("will work with scalaJS 1.16 and above. You are using scalaJS 1.15.0"))
67+
}
68+
5069
}
5170

5271
def prepareWorkspace(): Unit = {

scalajslib/worker/1/src/mill/scalajslib/worker/ScalaJSWorkerImpl.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ class ScalaJSWorkerImpl extends ScalaJSWorkerApi {
209209
irFiles = if (esModuleMap.isEmpty) {
210210
irFiles0
211211
} else {
212+
if (!minorIsGreaterThanOrEqual(16)) {
213+
throw new Exception(s"Remapping EsModule imports will work with scalaJS 1.16 and above. You are using scalaJS ${ScalaJSVersions.current} - consider upgrading?")
214+
}
212215
val remapFct = esModuleMap.toSeq.foldLeft((in: String) => in) { case (fct, (s1, s2)) =>
213216
val fct2: (String => String) = (in => in.replace(s1, s2))
214217
(in => fct(fct2(in)))

0 commit comments

Comments
 (0)