Skip to content

Commit 3740ad5

Browse files
authored
Merge pull request scala-js/scala-js#3001 from sjrd/new-jsenv-api-0.6.x
Introduce a new surface API for JS envs with `Config` objects.
2 parents ca40d6c + f06ed90 commit 3740ad5

File tree

3 files changed

+80
-9
lines changed

3 files changed

+80
-9
lines changed

js-envs-test-suite/src/test/scala/org/scalajs/jsenv/test/JSDOMNodeJSEnvTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.scalajs.jsenv.test
22

3-
import org.scalajs.jsenv.nodejs.JSDOMNodeJSEnv
3+
import org.scalajs.jsenv.jsdomnodejs.JSDOMNodeJSEnv
44

55
import org.junit.Test
66
import org.junit.Assert._
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/* __ *\
2+
** ________ ___ / / ___ __ ____ Scala.js JS envs **
3+
** / __/ __// _ | / / / _ | __ / // __/ (c) 2013-2017, LAMP/EPFL **
4+
** __\ \/ /__/ __ |/ /__/ __ |/_// /_\ \ http://scala-js.org/ **
5+
** /____/\___/_/ |_/____/_/ | |__/ /____/ **
6+
** |/____/ **
7+
\* */
8+
9+
package org.scalajs.jsenv.jsdomnodejs
10+
11+
class JSDOMNodeJSEnv(config: JSDOMNodeJSEnv.Config)
12+
extends org.scalajs.jsenv.nodejs.JSDOMNodeJSEnv(config.executable,
13+
config.args, config.env, internal = ()) {
14+
15+
def this() = this(JSDOMNodeJSEnv.Config())
16+
}
17+
18+
object JSDOMNodeJSEnv {
19+
final class Config private (
20+
val executable: String,
21+
val args: List[String],
22+
val env: Map[String, String]
23+
) {
24+
private def this() = {
25+
this(
26+
executable = "node",
27+
args = Nil,
28+
env = Map.empty
29+
)
30+
}
31+
32+
def withExecutable(executable: String): Config =
33+
copy(executable = executable)
34+
35+
def withArgs(args: List[String]): Config =
36+
copy(args = args)
37+
38+
def withEnv(env: Map[String, String]): Config =
39+
copy(env = env)
40+
41+
private def copy(
42+
executable: String = executable,
43+
args: List[String] = args,
44+
env: Map[String, String] = env
45+
): Config = {
46+
new Config(executable, args, env)
47+
}
48+
}
49+
50+
object Config {
51+
/** Returns a default configuration for a [[JSDOMNodeJSEnv]].
52+
*
53+
* The defaults are:
54+
*
55+
* - `executable`: `"node"`
56+
* - `args`: `Nil`
57+
* - `env`: `Map.empty`
58+
*/
59+
def apply(): Config = new Config()
60+
}
61+
}

js-envs/src/main/scala/org/scalajs/jsenv/nodejs/JSDOMNodeJSEnv.scala

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,24 @@ import org.scalajs.jsenv._
1717

1818
import org.scalajs.core.ir.Utils.escapeJS
1919

20-
class JSDOMNodeJSEnv(
21-
@deprecatedName('nodejsPath)
22-
executable: String = "node",
23-
@deprecatedName('addArgs)
24-
args: Seq[String] = Seq.empty,
25-
@deprecatedName('addEnv)
26-
env: Map[String, String] = Map.empty)
27-
extends AbstractNodeJSEnv(executable, args, env, sourceMap = false) {
20+
class JSDOMNodeJSEnv private[jsenv] (
21+
executable: String,
22+
args: Seq[String],
23+
env: Map[String, String],
24+
internal: Unit
25+
) extends AbstractNodeJSEnv(executable, args, env, sourceMap = false) {
26+
27+
@deprecated("Use org.scalajs.jsenv.jsdomnodejs.JSDOMNodeJSEnv.", "0.6.18")
28+
def this(
29+
@deprecatedName('nodejsPath)
30+
executable: String = "node",
31+
@deprecatedName('addArgs)
32+
args: Seq[String] = Seq.empty,
33+
@deprecatedName('addEnv)
34+
env: Map[String, String] = Map.empty
35+
) = {
36+
this(executable, args, env, internal = ())
37+
}
2838

2939
protected def vmName: String = "Node.js with JSDOM"
3040

0 commit comments

Comments
 (0)