Skip to content

Commit

Permalink
Fixes #55: Use correct scope with scalaJSLinkerConfig. (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
vmunier committed Feb 15, 2020
1 parent 9b824be commit b24b8d7
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 33 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ There are two plugins: `WebScalaJS` and `ScalaJSWeb`.
The plugin copies the Scala files to the SbtWeb assets, so that they can be served to the browser and used for Source Maps.

Source Map and Scala files _do not exist in production_ by default to prevent your users from seeing the source files.
But it can easily be enabled in production too by setting `scalaJSLinkerConfig in fullOptJS ~= (_.withSourceMap(true))` in the Scala.js projects.
But it can easily be enabled in production too by setting `scalaJSLinkerConfig in (Compile, fullOptJS) ~= (_.withSourceMap(true))` in the Scala.js projects.

## Scala.js continuous compilation

Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/webscalajs/ScalaJSWeb.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ object ScalaJSWeb extends AutoPlugin {
import autoImport._

override def projectSettings: Seq[Setting[_]] = Seq(
scalaJSLinkerConfig in fullOptJS ~= (_.withSourceMap(false)),
scalaJSLinkerConfig in (Compile, fullOptJS) ~= (_.withSourceMap(false)),
sourceMappings := SourceMappings.fromFiles((unmanagedSourceDirectories in Compile).value),
scalacOptions ++= sourceMappingOptions(sourceMappings.value)
)
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/webscalajs/WebScalaJS.scala
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ object WebScalaJS extends AutoPlugin {
def sourcemapScalaFiles(optJS: TaskKey[Attributed[File]]): Initialize[Task[Seq[PathMapping]]] = Def.taskDyn {
val projectsWithSourceMaps = filterInitializeSeq(
scalaJSProjects,
(p: Project) => Def.setting(scalaJSLinkerConfig.in(p, optJS).value.sourceMap)).value
(p: Project) => Def.setting(scalaJSLinkerConfig.in(p, Compile, optJS).value.sourceMap)).value

Def.task {
val sourceDirectories = settingOnProjects(transitiveDependencies(projectsWithSourceMaps), unmanagedSourceDirectories).value
Expand Down
8 changes: 4 additions & 4 deletions src/sbt-test/sbt-web-scalajs/akka-http-scalajs/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ lazy val server = (project in file("server")).settings(commonSettings).settings(
// triggers scalaJSPipeline when using compile or continuous compilation
compile in Compile := ((compile in Compile) dependsOn scalaJSPipeline).value,
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-http" % "10.1.3",
"com.typesafe.akka" %% "akka-stream" % "2.5.13",
"com.vmunier" %% "scalajs-scripts" % "1.1.2"
"com.typesafe.akka" %% "akka-http" % "10.1.11",
"com.typesafe.akka" %% "akka-stream" % "2.6.3",
"com.vmunier" %% "scalajs-scripts" % "1.1.4"
),
WebKeys.packagePrefix in Assets := "public/",
managedClasspath in Runtime += (packageBin in Assets).value
Expand All @@ -31,7 +31,7 @@ lazy val sharedJvm = shared.jvm
lazy val sharedJs = shared.js

lazy val commonSettings = Seq(
scalaVersion := "2.12.10",
scalaVersion := "2.13.1",
organization := "com.example"
)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh

baseDir="$( cd "$( dirname "$0" )" && pwd )"
cd $baseDir

expectedNbScalaFiles=$1
expectedNbSourceMapFiles=$2
archive="$baseDir/server/target/universal/server-0.1.0-SNAPSHOT.zip"
unzip -o $archive
nbScalaFiles=$(unzip -l "server-0.1.0-SNAPSHOT/lib/*web-assets.jar" | grep ".*\.scala$" | wc -l)
nbSourceMapFiles=$(unzip -l "server-0.1.0-SNAPSHOT/lib/*web-assets.jar" | grep ".*\.map$" | wc -l)

echo "Number of Scala files: "$((nbScalaFiles))" ($expectedNbScalaFiles expected)"
echo "Number of Source Map files: "$((nbSourceMapFiles))" ($expectedNbSourceMapFiles expected)"
[ "$nbScalaFiles" -eq "$expectedNbScalaFiles" -a "$nbSourceMapFiles" -eq "$expectedNbSourceMapFiles" ]
12 changes: 0 additions & 12 deletions src/sbt-test/sbt-web-scalajs/akka-http-scalajs/countScalaFiles.sh

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.3.2
sbt.version=1.3.8
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ sys.props.get("plugin.version") match {
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin)
}

val scalaJSVersion = Option(System.getenv("SCALAJS_VERSION")).getOrElse("0.6.27")
val scalaJSVersion = Option(System.getenv("SCALAJS_VERSION")).getOrElse("0.6.31")

// fast development turnaround when using sbt ~re-start
addSbtPlugin("io.spray" % "sbt-revolver" % "0.9.1")
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.3.5")
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.6.1")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % scalaJSVersion)
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "0.5.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-twirl" % "1.3.15")
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "0.6.1")
addSbtPlugin("com.typesafe.sbt" % "sbt-twirl" % "1.5.0")
19 changes: 10 additions & 9 deletions src/sbt-test/sbt-web-scalajs/akka-http-scalajs/test
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
> clean
> akka-http-scalajs/clean

# produce archive with no source maps
> universal:packageBin
$ exec chmod +x countScalaFiles.sh
$ exec ./countScalaFiles.sh 0
$ exec chmod +x countScalaAndSourceMapFiles.sh
$ exec ./countScalaAndSourceMapFiles.sh 0 0

# cleaning needed, otherwise source map files (.map) are not generated
> akka-http-scalajs/clean

# produce archive with source maps
> set scalaJSLinkerConfig in (client, fullOptJS) ~= (_.withSourceMap(true))
> set scalaJSLinkerConfig in (sharedJs, fullOptJS) ~= (_.withSourceMap(true))
> set scalaJSLinkerConfig in (client, Compile, fullOptJS) ~= (_.withSourceMap(true))
> set scalaJSLinkerConfig in (sharedJs, Compile, fullOptJS) ~= (_.withSourceMap(true))
> universal:packageBin
$ exec chmod +x countScalaFiles.sh
# The Scala files are replicated into two folders (META-INF, public) inside the JAR.
# So, we expect to see double the number of Scala files that exist in client and shared.
$ exec ./countScalaFiles.sh 4
$ exec chmod +x countScalaAndSourceMapFiles.sh
$ exec ./countScalaAndSourceMapFiles.sh 2 1

0 comments on commit b24b8d7

Please sign in to comment.