From d4bbc12e671b602dc7c18f21dc52eb8f02a00c9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Doeraene?= Date: Fri, 31 May 2019 20:15:03 +0200 Subject: [PATCH 1/4] Use OpenJDK on Travis. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 3587cd4..e5f2681 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,7 @@ scala: - 2.11.12 - 2.12.6 jdk: - - oraclejdk8 + - openjdk8 env: - JSDOM_VERSION=9.12.0 - JSDOM_VERSION=10.0.0 From 9abf96d7c758783246ebe6e7fee903e715500715 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Doeraene?= Date: Fri, 31 May 2019 20:15:17 +0200 Subject: [PATCH 2/4] Upgrade to Scala 2.12.8. --- .travis.yml | 2 +- build.sbt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index e5f2681..7a15760 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ language: scala scala: - 2.10.7 - 2.11.12 - - 2.12.6 + - 2.12.8 jdk: - openjdk8 env: diff --git a/build.sbt b/build.sbt index 35fd313..5433989 100644 --- a/build.sbt +++ b/build.sbt @@ -2,7 +2,7 @@ inThisBuild(Seq( version := "1.0.0-SNAPSHOT", organization := "org.scala-js", - crossScalaVersions := Seq("2.12.6", "2.10.7", "2.11.12"), + crossScalaVersions := Seq("2.12.8", "2.10.7", "2.11.12"), scalaVersion := crossScalaVersions.value.head, scalacOptions ++= Seq("-deprecation", "-feature", "-Xfatal-warnings"), From 5f3395fad0510893782f7dd0e50959f82f8d15dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Doeraene?= Date: Fri, 31 May 2019 20:15:35 +0200 Subject: [PATCH 3/4] Upgrade to sbt 1.2.8. --- project/build.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project/build.properties b/project/build.properties index 133a8f1..c0bab04 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=0.13.17 +sbt.version=1.2.8 From b3f5f676df213e11e3662d579d99cdddd757e225 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Doeraene?= Date: Fri, 31 May 2019 21:10:05 +0200 Subject: [PATCH 4/4] Upgrade to Scala.js 1.0.0-M8. --- .../jsenv/jsdomnodejs/JSDOMNodeJSEnv.scala | 83 ++++++++++--------- project/plugins.sbt | 4 +- 2 files changed, 45 insertions(+), 42 deletions(-) diff --git a/jsdom-nodejs-env/src/main/scala/org/scalajs/jsenv/jsdomnodejs/JSDOMNodeJSEnv.scala b/jsdom-nodejs-env/src/main/scala/org/scalajs/jsenv/jsdomnodejs/JSDOMNodeJSEnv.scala index 21a75e8..472a3db 100644 --- a/jsdom-nodejs-env/src/main/scala/org/scalajs/jsenv/jsdomnodejs/JSDOMNodeJSEnv.scala +++ b/jsdom-nodejs-env/src/main/scala/org/scalajs/jsenv/jsdomnodejs/JSDOMNodeJSEnv.scala @@ -14,14 +14,15 @@ import scala.collection.immutable import scala.util.control.NonFatal import java.io._ -import java.nio.file.{Files, StandardCopyOption} +import java.nio.charset.StandardCharsets +import java.nio.file.{Files, Path, StandardCopyOption} import java.net.URI -import org.scalajs.io._ -import org.scalajs.io.JSUtils.escapeJS +import com.google.common.jimfs.Jimfs import org.scalajs.jsenv._ import org.scalajs.jsenv.nodejs._ +import org.scalajs.jsenv.JSUtils.escapeJS class JSDOMNodeJSEnv(config: JSDOMNodeJSEnv.Config) extends JSEnv { @@ -49,7 +50,7 @@ class JSDOMNodeJSEnv(config: JSDOMNodeJSEnv.Config) extends JSEnv { } } - private def validateInput(input: Input): List[VirtualBinaryFile] = { + private def validateInput(input: Input): List[Path] = { input match { case Input.ScriptsToLoad(scripts) => scripts @@ -58,8 +59,7 @@ class JSDOMNodeJSEnv(config: JSDOMNodeJSEnv.Config) extends JSEnv { } } - private def internalStart(files: List[VirtualBinaryFile], - runConfig: RunConfig): JSRun = { + private def internalStart(files: List[Path], runConfig: RunConfig): JSRun = { val command = config.executable :: config.args val externalConfig = ExternalJSRun.Config() .withEnv(env) @@ -70,9 +70,7 @@ class JSDOMNodeJSEnv(config: JSDOMNodeJSEnv.Config) extends JSEnv { private def env: Map[String, String] = Map("NODE_MODULE_CONTEXTS" -> "0") ++ config.env - private def codeWithJSDOMContext( - scripts: List[VirtualBinaryFile]): List[VirtualBinaryFile] = { - + private def codeWithJSDOMContext(scripts: List[Path]): List[Path] = { val scriptsURIs = scripts.map(JSDOMNodeJSEnv.materialize(_)) val scriptsURIsAsJSStrings = scriptsURIs.map(uri => '"' + escapeJS(uri.toASCIIString) + '"') @@ -116,7 +114,9 @@ class JSDOMNodeJSEnv(config: JSDOMNodeJSEnv.Config) extends JSEnv { |})(); |""".stripMargin } - List(MemVirtualBinaryFile.fromStringUTF8("codeWithJSDOMContext.js", jsDOMCode)) + List(Files.write( + Jimfs.newFileSystem().getPath("codeWithJSDOMContext.js"), + jsDOMCode.getBytes(StandardCharsets.UTF_8))) } } @@ -124,34 +124,35 @@ object JSDOMNodeJSEnv { private lazy val validator = ExternalJSRun.supports(RunConfig.Validator()) // Copied from NodeJSEnv.scala upstream - private def write(files: List[VirtualBinaryFile])(out: OutputStream): Unit = { + private def write(files: List[Path])(out: OutputStream): Unit = { val p = new PrintStream(out, false, "UTF8") try { - files.foreach { - case file: FileVirtualBinaryFile => - val fname = file.file.getAbsolutePath - p.println(s"""require("${escapeJS(fname)}");""") - case f => - val in = f.inputStream - try { - val buf = new Array[Byte](4096) - - @tailrec - def loop(): Unit = { - val read = in.read(buf) - if (read != -1) { - p.write(buf, 0, read) - loop() - } - } - - loop() - } finally { - in.close() - } - - p.println() + def writeRunScript(path: Path): Unit = { + try { + val f = path.toFile + val pathJS = "\"" + escapeJS(f.getAbsolutePath) + "\"" + p.println(s""" + require('vm').runInThisContext( + require('fs').readFileSync($pathJS, { encoding: "utf-8" }), + { filename: $pathJS, displayErrors: true } + ); + """) + } catch { + case _: UnsupportedOperationException => + val code = new String(Files.readAllBytes(path), StandardCharsets.UTF_8) + val codeJS = "\"" + escapeJS(code) + "\"" + val pathJS = "\"" + escapeJS(path.toString) + "\"" + p.println(s""" + require('vm').runInThisContext( + $codeJS, + { filename: $pathJS, displayErrors: true } + ); + """) + } } + + for (file <- files) + writeRunScript(file) } finally { p.close() } @@ -178,12 +179,14 @@ object JSDOMNodeJSEnv { } } - private def materialize(file: VirtualBinaryFile): URI = { - file match { - case file: FileVirtualFile => file.file.toURI - case file => tmpFile(file.path, file.inputStream) + private def materialize(path: Path): URI = { + try { + path.toFile.toURI + } catch { + case _: UnsupportedOperationException => + tmpFile(path.toString, Files.newInputStream(path)) } - } +} final class Config private ( val executable: String, diff --git a/project/plugins.sbt b/project/plugins.sbt index 0e2167a..c165824 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,6 +1,6 @@ -addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.0.0-M7") +addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.0.0-M8") -libraryDependencies += "org.scala-js" %% "scalajs-env-nodejs" % "1.0.0-M7" +libraryDependencies += "org.scala-js" %% "scalajs-env-nodejs" % "1.0.0-M8" unmanagedSourceDirectories in Compile += baseDirectory.value.getParentFile / "jsdom-nodejs-env/src/main/scala"