6

I'm using resourceGenerators sbt key to copy fastOptJs-generated .js files when using products, like this:

(resourceGenerators in Compile) <+=
        (fastOptJS in Compile in frontend, packageScalaJSLauncher in Compile in frontend, packageJSDependencies in Compile in frontend)
          .map((f1, f2, f3) => {
            Seq(f1.data, f2.data, f3)
          })

Running the following in sbt, I can see the path of generated file:

> show frontend/fastOptJS
[info] Attributed(/some/path/frontend/target/scala-2.11/frontend-fastopt.js)
[success] Total time: 0 s, completed Mar 12, 2016 1:59:22 PM

Similarly, I can easily see where Scala.js-generated launcher ends up:

> show frontend/packageScalaJSLauncher
[info] Attributed(/some/path/frontend/target/scala-2.11/frontend-launcher.js)
[success] Total time: 0 s, completed Mar 12, 2016 2:00:10 PM

I cannot, however, find a task/key that would point me to location of .js.map file. I tried looking in the plugin sources, but couldn't find it. Is there any way of doing that without resorting to creating a manual mapping in build.sbt?

Patryk Koryzna
  • 475
  • 4
  • 13

1 Answers1

5

Source maps generated by Scala.js always have the name of the corresponding .js file + ".map". So you can find the one associated with f1 with f1.getParentFile / (f1.getName + ".map").

Btw, no new build should use <+=. The more understandable += should be used instead:

resourceGenerators in Compile += Def.task {
  val f1 = (fastOptJS in Compile in frontend).value.data
  val f1SourceMap = f1.getParentFile / (f1.getName + ".map")
  val f2 = (packageScalaJSLauncher in Compile in frontend).value.data
  val f3 = (packageJSDependencies in Compile in frontend).value
  Seq(f1, f1SourceMap, f2, f3)
}

and to avoid the in Compile everywhere, you can use inConfig(Compile):

inConfig(Compile)(Seq(
  resourceGenerators += Def.task {
    val f1 = (fastOptJS in frontend).value.data
    val f1SourceMap = f1.getParentFile / (f1.getName + ".map")
    val f2 = (packageScalaJSLauncher in frontend).value.data
    val f3 = (packageJSDependencies in frontend).value
    Seq(f1, f1SourceMap, f2, f3)
  }
))
Anubian Noob
  • 13,426
  • 6
  • 53
  • 75
sjrd
  • 21,805
  • 2
  • 61
  • 91
  • 1
    Thanks, it worked. Still, I feel it'd be safer if plugin could provide that location as a sbt key, instead of fiddling with paths. – Patryk Koryzna Mar 16 '16 at 10:07
  • 1
    Feel free to [file a feature request](https://github.com/scala-js/scala-js/issues). – sjrd Mar 16 '16 at 11:43