Skip to content

Commit f03bb41

Browse files
committed
More fixes, runs on JSDOM :)
1 parent a16090e commit f03bb41

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

build.sbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ lazy val runtime = CrossProject(
108108
)
109109
.jsSettings(
110110
scalaJSStage := FastOptStage,
111+
// Uncomment to test JSDOM
111112
// jsEnv := new org.scalajs.jsenv.jsdomnodejs.JSDOMNodeJSEnv()
112113
)
113114

scalac-scoverage-runtime/js/src/main/scala/scalajssupport/NodeFile.scala

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@ import scala.scalajs.js
55
class NodeFile(path: String)(implicit fs: FS, nodePath: NodePath)
66
extends JsFile {
77
def this(path: String, child: String)(implicit fs: FS, nodePath: NodePath) = {
8-
this(NodeFile.nodePath.join(path, child))
8+
this(nodePath.join(path, child))
99
}
1010

1111
def delete(): Unit = {
12-
if (isDirectory()) NodeFile.fs.rmdirSync(path)
13-
else NodeFile.fs.unlinkSync(path)
12+
if (isDirectory()) fs.rmdirSync(path)
13+
else fs.unlinkSync(path)
1414
}
1515

1616
def getAbsolutePath(): String = {
17-
NodeFile.fs.realpathSync(path)
17+
fs.realpathSync(path)
1818
}
1919

2020
def getName(): String = {
21-
NodeFile.nodePath.basename(path)
21+
nodePath.basename(path)
2222
}
2323

2424
def getPath(): String = {
@@ -27,7 +27,7 @@ class NodeFile(path: String)(implicit fs: FS, nodePath: NodePath)
2727

2828
def isDirectory(): Boolean = {
2929
try {
30-
NodeFile.fs.lstatSync(path).isDirectory()
30+
fs.lstatSync(path).isDirectory()
3131
} catch {
3232
// return false if the file does not exist
3333
case e: Exception => false
@@ -38,9 +38,9 @@ class NodeFile(path: String)(implicit fs: FS, nodePath: NodePath)
3838
path
3939
.split("/")
4040
.foldLeft("")((acc: String, x: String) => {
41-
val new_acc = NodeFile.nodePath.join(acc, x)
41+
val new_acc = nodePath.join(acc, x)
4242
try {
43-
NodeFile.fs.mkdirSync(new_acc)
43+
fs.mkdirSync(new_acc)
4444
} catch {
4545
case e: Exception =>
4646
}
@@ -49,16 +49,16 @@ class NodeFile(path: String)(implicit fs: FS, nodePath: NodePath)
4949
}
5050

5151
def listFiles(): Array[File] = {
52-
val files = NodeFile.fs.readdirSync(path)
52+
val files = fs.readdirSync(path)
5353
val filesArray = new Array[File](files.length)
5454
for ((item, i) <- filesArray.zipWithIndex) {
55-
filesArray(i) = new File(NodeFile.nodePath.join(this.getPath(), files(i)))
55+
filesArray(i) = new File(nodePath.join(this.getPath(), files(i)))
5656
}
5757
filesArray
5858
}
5959

6060
def readFile(): String = {
61-
NodeFile.fs.readFileSync(path, js.Dynamic.literal(encoding = "utf-8"))
61+
fs.readFileSync(path, js.Dynamic.literal(encoding = "utf-8"))
6262
}
6363

6464
}
@@ -116,8 +116,5 @@ private[scalajssupport] object NodeFile extends NodeLikeFile {
116116
}
117117

118118
private[scalajssupport] object JSDOMFile extends NodeLikeFile {
119-
lazy val require = {
120-
val process = js.Dynamic.global.Node.constructor("return process")()
121-
process.mainModule.require
122-
}
119+
lazy val require = js.Dynamic.global.Node.constructor("return require")()
123120
}

0 commit comments

Comments
 (0)