Skip to content

Commit 9f93761

Browse files
authored
Merge pull request #23 from sjrd/scalajs-1.0.0-M8
Upgrade to Scala.js 1.0.0-M8.
2 parents a7a4e85 + b3f5f67 commit 9f93761

File tree

5 files changed

+49
-46
lines changed

5 files changed

+49
-46
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ language: scala
33
scala:
44
- 2.10.7
55
- 2.11.12
6-
- 2.12.6
6+
- 2.12.8
77
jdk:
8-
- oraclejdk8
8+
- openjdk8
99
env:
1010
- JSDOM_VERSION=9.12.0
1111
- JSDOM_VERSION=10.0.0

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ inThisBuild(Seq(
22
version := "1.0.0-SNAPSHOT",
33
organization := "org.scala-js",
44

5-
crossScalaVersions := Seq("2.12.6", "2.10.7", "2.11.12"),
5+
crossScalaVersions := Seq("2.12.8", "2.10.7", "2.11.12"),
66
scalaVersion := crossScalaVersions.value.head,
77
scalacOptions ++= Seq("-deprecation", "-feature", "-Xfatal-warnings"),
88

jsdom-nodejs-env/src/main/scala/org/scalajs/jsenv/jsdomnodejs/JSDOMNodeJSEnv.scala

Lines changed: 43 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@ import scala.collection.immutable
1414
import scala.util.control.NonFatal
1515

1616
import java.io._
17-
import java.nio.file.{Files, StandardCopyOption}
17+
import java.nio.charset.StandardCharsets
18+
import java.nio.file.{Files, Path, StandardCopyOption}
1819
import java.net.URI
1920

20-
import org.scalajs.io._
21-
import org.scalajs.io.JSUtils.escapeJS
21+
import com.google.common.jimfs.Jimfs
2222

2323
import org.scalajs.jsenv._
2424
import org.scalajs.jsenv.nodejs._
25+
import org.scalajs.jsenv.JSUtils.escapeJS
2526

2627
class JSDOMNodeJSEnv(config: JSDOMNodeJSEnv.Config) extends JSEnv {
2728

@@ -49,7 +50,7 @@ class JSDOMNodeJSEnv(config: JSDOMNodeJSEnv.Config) extends JSEnv {
4950
}
5051
}
5152

52-
private def validateInput(input: Input): List[VirtualBinaryFile] = {
53+
private def validateInput(input: Input): List[Path] = {
5354
input match {
5455
case Input.ScriptsToLoad(scripts) =>
5556
scripts
@@ -58,8 +59,7 @@ class JSDOMNodeJSEnv(config: JSDOMNodeJSEnv.Config) extends JSEnv {
5859
}
5960
}
6061

61-
private def internalStart(files: List[VirtualBinaryFile],
62-
runConfig: RunConfig): JSRun = {
62+
private def internalStart(files: List[Path], runConfig: RunConfig): JSRun = {
6363
val command = config.executable :: config.args
6464
val externalConfig = ExternalJSRun.Config()
6565
.withEnv(env)
@@ -70,9 +70,7 @@ class JSDOMNodeJSEnv(config: JSDOMNodeJSEnv.Config) extends JSEnv {
7070
private def env: Map[String, String] =
7171
Map("NODE_MODULE_CONTEXTS" -> "0") ++ config.env
7272

73-
private def codeWithJSDOMContext(
74-
scripts: List[VirtualBinaryFile]): List[VirtualBinaryFile] = {
75-
73+
private def codeWithJSDOMContext(scripts: List[Path]): List[Path] = {
7674
val scriptsURIs = scripts.map(JSDOMNodeJSEnv.materialize(_))
7775
val scriptsURIsAsJSStrings =
7876
scriptsURIs.map(uri => '"' + escapeJS(uri.toASCIIString) + '"')
@@ -116,42 +114,45 @@ class JSDOMNodeJSEnv(config: JSDOMNodeJSEnv.Config) extends JSEnv {
116114
|})();
117115
|""".stripMargin
118116
}
119-
List(MemVirtualBinaryFile.fromStringUTF8("codeWithJSDOMContext.js", jsDOMCode))
117+
List(Files.write(
118+
Jimfs.newFileSystem().getPath("codeWithJSDOMContext.js"),
119+
jsDOMCode.getBytes(StandardCharsets.UTF_8)))
120120
}
121121
}
122122

123123
object JSDOMNodeJSEnv {
124124
private lazy val validator = ExternalJSRun.supports(RunConfig.Validator())
125125

126126
// Copied from NodeJSEnv.scala upstream
127-
private def write(files: List[VirtualBinaryFile])(out: OutputStream): Unit = {
127+
private def write(files: List[Path])(out: OutputStream): Unit = {
128128
val p = new PrintStream(out, false, "UTF8")
129129
try {
130-
files.foreach {
131-
case file: FileVirtualBinaryFile =>
132-
val fname = file.file.getAbsolutePath
133-
p.println(s"""require("${escapeJS(fname)}");""")
134-
case f =>
135-
val in = f.inputStream
136-
try {
137-
val buf = new Array[Byte](4096)
138-
139-
@tailrec
140-
def loop(): Unit = {
141-
val read = in.read(buf)
142-
if (read != -1) {
143-
p.write(buf, 0, read)
144-
loop()
145-
}
146-
}
147-
148-
loop()
149-
} finally {
150-
in.close()
151-
}
152-
153-
p.println()
130+
def writeRunScript(path: Path): Unit = {
131+
try {
132+
val f = path.toFile
133+
val pathJS = "\"" + escapeJS(f.getAbsolutePath) + "\""
134+
p.println(s"""
135+
require('vm').runInThisContext(
136+
require('fs').readFileSync($pathJS, { encoding: "utf-8" }),
137+
{ filename: $pathJS, displayErrors: true }
138+
);
139+
""")
140+
} catch {
141+
case _: UnsupportedOperationException =>
142+
val code = new String(Files.readAllBytes(path), StandardCharsets.UTF_8)
143+
val codeJS = "\"" + escapeJS(code) + "\""
144+
val pathJS = "\"" + escapeJS(path.toString) + "\""
145+
p.println(s"""
146+
require('vm').runInThisContext(
147+
$codeJS,
148+
{ filename: $pathJS, displayErrors: true }
149+
);
150+
""")
151+
}
154152
}
153+
154+
for (file <- files)
155+
writeRunScript(file)
155156
} finally {
156157
p.close()
157158
}
@@ -178,12 +179,14 @@ object JSDOMNodeJSEnv {
178179
}
179180
}
180181

181-
private def materialize(file: VirtualBinaryFile): URI = {
182-
file match {
183-
case file: FileVirtualFile => file.file.toURI
184-
case file => tmpFile(file.path, file.inputStream)
182+
private def materialize(path: Path): URI = {
183+
try {
184+
path.toFile.toURI
185+
} catch {
186+
case _: UnsupportedOperationException =>
187+
tmpFile(path.toString, Files.newInputStream(path))
185188
}
186-
}
189+
}
187190

188191
final class Config private (
189192
val executable: String,

project/build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version=0.13.17
1+
sbt.version=1.2.8

project/plugins.sbt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.0.0-M7")
1+
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.0.0-M8")
22

3-
libraryDependencies += "org.scala-js" %% "scalajs-env-nodejs" % "1.0.0-M7"
3+
libraryDependencies += "org.scala-js" %% "scalajs-env-nodejs" % "1.0.0-M8"
44

55
unmanagedSourceDirectories in Compile +=
66
baseDirectory.value.getParentFile / "jsdom-nodejs-env/src/main/scala"

0 commit comments

Comments
 (0)