diff options
author | Jakob Odersky <jakob@odersky.com> | 2016-11-07 18:06:30 -0800 |
---|---|---|
committer | Jakob Odersky <jakob@odersky.com> | 2016-11-08 16:52:27 -0800 |
commit | 71e5666ceeab0db8bb69c3bfcd2ddef5ab982029 (patch) | |
tree | d3420020e70e88a1532d8d0960c2544bf14eb015 /src/main | |
parent | a11c7826f2ba4ae20a0ab4e004e53ba910157bc3 (diff) | |
download | workbench-71e5666ceeab0db8bb69c3bfcd2ddef5ab982029.tar.gz workbench-71e5666ceeab0db8bb69c3bfcd2ddef5ab982029.tar.bz2 workbench-71e5666ceeab0db8bb69c3bfcd2ddef5ab982029.zip |
Update scalajs versions, related dependencies and remove obsolete features
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/scala/workbench/Server.scala | 17 | ||||
-rw-r--r-- | src/main/scala/workbench/WorkbenchPlugin.scala (renamed from src/main/scala/workbench/Plugin.scala) | 105 |
2 files changed, 54 insertions, 68 deletions
diff --git a/src/main/scala/workbench/Server.scala b/src/main/scala/workbench/Server.scala index 1d6d1ba..5953fcb 100644 --- a/src/main/scala/workbench/Server.scala +++ b/src/main/scala/workbench/Server.scala @@ -8,13 +8,13 @@ import spray.httpx.encoding.Gzip import spray.routing.SimpleRoutingApp import akka.actor.ActorDSL._ -import upickle.{Reader, Writer, Js} +import upickle.Js +import upickle.default.{Reader, Writer} import spray.http.{HttpEntity, AllOrigins, HttpResponse} import spray.http.HttpHeaders.`Access-Control-Allow-Origin` import concurrent.duration._ import scala.concurrent.Future import scala.io.Source -import org.scalajs.core.tools.optimizer.{ScalaJSClosureOptimizer, ScalaJSOptimizer} import org.scalajs.core.tools.io._ import org.scalajs.core.tools.logging.Level import scala.tools.nsc @@ -24,12 +24,11 @@ import scala.tools.nsc.backend.JavaPlatform import scala.tools.nsc.util.ClassPath.JavaContext import scala.collection.mutable import scala.tools.nsc.typechecker.Analyzer -import org.scalajs.core.tools.classpath.{CompleteClasspath, PartialClasspath} import scala.tools.nsc.util.{JavaClassPath, DirectoryClassPath} import spray.http.HttpHeaders._ import spray.http.HttpMethods._ -class Server(url: String, port: Int, bootSnippet: String) extends SimpleRoutingApp{ +class Server(url: String, port: Int) extends SimpleRoutingApp{ val corsHeaders: List[ModeledHeader] = List( `Access-Control-Allow-Methods`(OPTIONS, GET, POST), @@ -47,9 +46,9 @@ class Server(url: String, port: Int, bootSnippet: String) extends SimpleRoutingA /** * The connection from workbench server to the client */ - object Wire extends autowire.Client[Js.Value, upickle.Reader, upickle.Writer] with ReadWrite{ + object Wire extends autowire.Client[Js.Value, Reader, Writer] with ReadWrite{ def doCall(req: Request): Future[Js.Value] = { - longPoll ! Js.Arr(upickle.writeJs(req.path), Js.Obj(req.args.toSeq:_*)) + longPoll ! Js.Arr(upickle.default.writeJs(req.path), Js.Obj(req.args.toSeq:_*)) Future.successful(Js.Null) } } @@ -68,7 +67,7 @@ class Server(url: String, port: Int, bootSnippet: String) extends SimpleRoutingA case object Clear import system.dispatcher - system.scheduler.schedule(0 seconds, 10 seconds, self, Clear) + system.scheduler.schedule(0.seconds, 10.seconds, self, Clear) def respond(a: ActorRef, s: String) = { a ! HttpResponse( entity = s, @@ -116,7 +115,7 @@ class Server(url: String, port: Int, bootSnippet: String) extends SimpleRoutingA (function(){ $body - com.lihaoyi.workbench.WorkbenchClient().main(${upickle.write(bootSnippet)}, ${upickle.write(url)}, ${upickle.write(port)}) + com.lihaoyi.workbench.WorkbenchClient().main(${upickle.default.write(url)}, ${upickle.default.write(port)}) }).call(this) """ } @@ -132,4 +131,4 @@ class Server(url: String, port: Int, bootSnippet: String) extends SimpleRoutingA } def kill() = system.shutdown() -}
\ No newline at end of file +} diff --git a/src/main/scala/workbench/Plugin.scala b/src/main/scala/workbench/WorkbenchPlugin.scala index a120d0f..31fd659 100644 --- a/src/main/scala/workbench/Plugin.scala +++ b/src/main/scala/workbench/WorkbenchPlugin.scala @@ -5,24 +5,19 @@ import sbt.Keys._ import autowire._ import org.scalajs.sbtplugin.ScalaJSPlugin import org.scalajs.core.tools.io._ -import org.scalajs.core.tools.optimizer.ScalaJSOptimizer import org.scalajs.sbtplugin.ScalaJSPluginInternal._ import org.scalajs.sbtplugin.Implicits._ -object Plugin extends AutoPlugin { +object WorkbenchPlugin extends AutoPlugin { override def requires = ScalaJSPlugin object autoImport { val refreshBrowsers = taskKey[Unit]("Sends a message to all connected web pages asking them to refresh the page") - val updateBrowsers = taskKey[Unit]("Partially resets some of the stuff in the browser") + val updatedJS = taskKey[List[String]]("Provides the addresses of the JS files that have changed") val spliceBrowsers = taskKey[Unit]("Attempts to do a live update of the code running in the browser while maintaining state") val localUrl = settingKey[(String, Int)]("localUrl") - private[Plugin] val server = settingKey[Server]("local websocket server") - - val bootSnippet = settingKey[String]("piece of javascript to make things happen") - val updatedJS = taskKey[List[String]]("Provides the addresses of the JS files that have changed") val sjs = inputKey[Unit]("Run a command via the sjs REPL, which compiles it to Javascript and runs it in the browser") val replFile = taskKey[File]("The temporary file which holds the source code for the currently executing sjs REPL") val sjsReset = taskKey[Unit]("Reset the currently executing sjs REPL") @@ -30,30 +25,12 @@ object Plugin extends AutoPlugin { import autoImport._ import ScalaJSPlugin.AutoImport._ + val server = settingKey[Server]("local websocket server") + lazy val replHistory = collection.mutable.Buffer.empty[String] val workbenchSettings = Seq( localUrl := ("localhost", 12345), - updatedJS := { - var files: List[String] = Nil - ((crossTarget in Compile).value * "*.js").get.foreach { - (x: File) => - streams.value.log.info("workbench: Checking " + x.getName) - FileFunction.cached(streams.value.cacheDirectory / x.getName, FilesInfo.lastModified, FilesInfo.lastModified) { - (f: Set[File]) => - val fsPath = f.head.getAbsolutePath.drop(new File("").getAbsolutePath.length) - files = fsPath :: files - f - }(Set(x)) - } - files - }, - updatedJS := { - updatedJS.value.map{ path => - val url = localUrl.value - s"http://${url._1}:${url._2}$path" - } - }, (extraLoggers in ThisBuild) := { val clientLogger = FullLogger{ new Logger { @@ -71,16 +48,28 @@ object Plugin extends AutoPlugin { streams.value.log.info("workbench: Reloading Pages...") server.value.Wire[Api].reload().call() }, - updateBrowsers := { - val changed = updatedJS.value - // There is no point in clearing the browser if no js files have changed. - if (changed.length > 0) { - server.value.Wire[Api].clear().call() - - changed.foreach { path => - streams.value.log.info("workbench: Refreshing " + path) - server.value.Wire[Api].run(path, Some(bootSnippet.value)).call() - } + // this currently requires the old <<= syntax + // see https://github.com/sbt/sbt/issues/1444 + refreshBrowsers <<= refreshBrowsers.triggeredBy(fastOptJS in Compile), + updatedJS := { + var files: List[String] = Nil + ((crossTarget in Compile).value * "*.js").get.foreach { + (x: File) => + streams.value.log.info("workbench: Checking " + x.getName) + FileFunction.cached(streams.value.cacheDirectory / x.getName, FilesInfo.lastModified, FilesInfo.lastModified) { + (f: Set[File]) => + val fsPath = f.head.getAbsolutePath.drop(new File("").getAbsolutePath.length) + files = fsPath :: files + f + }(Set(x)) + } + files + }, + updatedJS := { + val paths = updatedJS.value + val url = localUrl.value + paths.map { path => + s"http://${url._1}:${url._2}$path" } }, spliceBrowsers := { @@ -91,17 +80,17 @@ object Plugin extends AutoPlugin { path <- changed if !path.endsWith(".js.js") }{ - streams.value.log.info("workbench: Splicing " + path) - val prefix = "http://localhost:12345/" + val url = localUrl.value + val prefix = s"http://${url._1}:${url._2}/" val s = munge(sbt.IO.read(new sbt.File(path.drop(prefix.length)))) sbt.IO.write(new sbt.File(path.drop(prefix.length) + ".js"), s.getBytes) - server.value.Wire[Api].run(path + ".js", None).call() + server.value.Wire[Api].run(path + ".js").call() } } }, - server := new Server(localUrl.value._1, localUrl.value._2, bootSnippet.value), + server := new Server(localUrl.value._1, localUrl.value._2), (onUnload in Global) := { (onUnload in Global).value.compose{ state => server.value.kill() state @@ -110,7 +99,6 @@ object Plugin extends AutoPlugin { artifactPath in sjs := crossTarget.value / "repl.js", replFile := { val f = sourceManaged.value / "repl.scala" - println("Creating replFile\n" + replHistory.mkString("\n")) sbt.IO.write(f, replHistory.mkString("\n")) f }, @@ -140,21 +128,21 @@ object Plugin extends AutoPlugin { Some(output.getParentFile.toURI()) else None - import ScalaJSOptimizer._ - - (scalaJSOptimizer in fastOptJS).value.optimizeCP( - (scalaJSPreLinkClasspath in fastOptJS).value, - Config( - output = WritableFileVirtualJSFile(output), - cache = None, - wantSourceMap = (emitSourceMaps in fastOptJS).value, - relativizeSourceMapBase = relSourceMapBase, - checkIR = (scalaJSOptimizerOptions in fastOptJS).value.checkScalaJSIR, - disableOptimizer = (scalaJSOptimizerOptions in fastOptJS).value.disableOptimizer, - batchMode = (scalaJSOptimizerOptions in fastOptJS).value.batchMode - ), - s.log - ) + // TODO: re-enable this feature for latest scalajs + // NOTE: maybe use 'scalaJSOptimizerOptions in fullOptJS' + // (scalaJSOptimizer in fastOptJS).value.optimizeCP( + // (scalaJSPreLinkClasspath in fastOptJS).value, + // Config( + // output = WritableFileVirtualJSFile(output), + // cache = None, + // wantSourceMap = (emitSourceMaps in fastOptJS).value, + // relativizeSourceMapBase = relSourceMapBase, + // checkIR = (scalaJSOptimizerOptions in fastOptJS).value.checkScalaJSIR, + // disableOptimizer = (scalaJSOptimizerOptions in fastOptJS).value.disableOptimizer, + // batchMode = (scalaJSOptimizerOptions in fastOptJS).value.batchMode + // ), + // s.log + // ) // end of C&P val outPath = sbt.IO.relativize( baseDirectory.value, @@ -167,8 +155,7 @@ object Plugin extends AutoPlugin { ) Def.task { server.value.Wire[Api].run( - s"http://localhost:12345/$outPath", - None + s"http://localhost:12345/$outPath" ).call() () } |