Skip to content

Commit d4943b9

Browse files
committed
refactor: Remove forked parts of scala js envs
As far as I can see this should work properly and it hits us even more to have duplicated part of code that is not maintained.
1 parent e386dc7 commit d4943b9

File tree

9 files changed

+47
-874
lines changed

9 files changed

+47
-874
lines changed

bridges/scalajs-1/src/main/scala/bloop/scalajs/JsBridge.scala

+17-23
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,23 @@ import bloop.config.Config.ModuleKindJS
1414
import bloop.data.Project
1515
import bloop.logging.DebugFilter
1616
import bloop.logging.{Logger => BloopLogger}
17-
import bloop.scalajs.jsenv.JsDomNodeJsEnv
18-
import bloop.scalajs.jsenv.NodeJSConfig
19-
import bloop.scalajs.jsenv.NodeJSEnv
2017

2118
import org.scalajs.jsenv.Input
19+
import org.scalajs.jsenv.jsdomnodejs.JSDOMNodeJSEnv
20+
import org.scalajs.jsenv.nodejs.NodeJSEnv
2221
import org.scalajs.linker.PathIRContainer
22+
import org.scalajs.linker.PathOutputDirectory
2323
import org.scalajs.linker.PathOutputFile
2424
import org.scalajs.linker.StandardImpl
2525
import org.scalajs.linker.interface.{ModuleKind => ScalaJSModuleKind, _}
2626
import org.scalajs.logging.Level
2727
import org.scalajs.logging.{Logger => JsLogger}
2828
import org.scalajs.testing.adapter.TestAdapter
2929
import org.scalajs.testing.adapter.TestAdapterInitializer
30+
import java.nio.file.Files
3031

3132
/**
3233
* Defines operations provided by the Scala.JS 1.x toolchain.
33-
*
34-
* The 1.x js bridge needs to inline the implementation of `NodeJSEnv`,
35-
* `JSDOMNodeJSEnv` and `ComRunner` because there is a bug in the latest
36-
* Scala.js release that does not run `close` on the underlying process,
37-
* skipping the destruction of the process running Scala.js tests. Aside
38-
* from leaking, this is fatal in Windows because the underlying process
39-
* is alive and keeps open references to the output JS file.
40-
*
41-
* We can remove all of the js environments and runners as soon as this
42-
* issue is fixed upstream. Note that our 0.6.x version handles cancellation
43-
* correctly.
4434
*/
4535
object JsBridge {
4636
private class Logger(logger: BloopLogger)(implicit filter: DebugFilter) extends JsLogger {
@@ -94,13 +84,13 @@ object JsBridge {
9484
classpath: Array[Path],
9585
runMain: java.lang.Boolean,
9686
mainClass: Option[String],
97-
target: Path,
87+
targetDirectory: Path,
9888
logger: BloopLogger,
9989
executionContext: ExecutionContext
10090
): Unit = {
10191
implicit val ec = executionContext
10292
implicit val logFilter: DebugFilter = DebugFilter.Link
103-
val linker = ScalaJSLinker.reuseOrCreate(config, target)
93+
val linker = ScalaJSLinker.reuseOrCreate(config, targetDirectory)
10494

10595
val cache = StandardImpl.irFileCache().newCache
10696
val irContainersPairs = PathIRContainer.fromClasspath(classpath)
@@ -126,11 +116,14 @@ object JsBridge {
126116
}
127117
}
128118

129-
val output = LinkerOutput(PathOutputFile(target))
130-
131119
val resultFuture = for {
132120
libraryIRs <- libraryIrsFuture
133-
_ <- linker.link(libraryIRs, moduleInitializers, output, new Logger(logger))
121+
_ <- linker.link(
122+
libraryIRs,
123+
moduleInitializers,
124+
PathOutputDirectory(targetDirectory),
125+
new Logger(logger)
126+
)
134127
} yield ()
135128

136129
Await.result(resultFuture, Duration.Inf)
@@ -151,11 +144,12 @@ object JsBridge {
151144
if (nodeModules.toFile().exists()) {
152145
logger.debug("Node.js module path: " + nodeModules.toString())
153146
val fullEnv = Map("NODE_PATH" -> nodeModules.toString()) ++ env
154-
val config =
155-
NodeJSConfig().withExecutable(nodePath).withCwd(Some(baseDirectory)).withEnv(fullEnv)
156147
val nodeEnv =
157-
if (!jsConfig.jsdom.contains(true)) new NodeJSEnv(logger, config)
158-
else new JsDomNodeJsEnv(logger, config)
148+
if (!jsConfig.jsdom.contains(true))
149+
new NodeJSEnv(
150+
NodeJSEnv.Config().withExecutable(nodePath).withEnv(fullEnv)
151+
)
152+
else new JSDOMNodeJSEnv(JSDOMNodeJSEnv.Config().withExecutable(nodePath).withEnv(fullEnv))
159153

160154
// The order of the scripts mandates the load order in the JavaScript runtime
161155
val input = jsConfig.kind match {

bridges/scalajs-1/src/main/scala/bloop/scalajs/jsenv/JsDomNodeJsEnv.scala

-198
This file was deleted.

0 commit comments

Comments
 (0)