Skip to content

Commit

Permalink
Apply useCommonJs() to fix issues with kotlin-node
Browse files Browse the repository at this point in the history
  • Loading branch information
lukellmann committed Mar 3, 2024
1 parent e733e07 commit 5bcc68e
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ kotlin {
jvm()
js {
nodejs()
useCommonJs()
}
jvmToolchain(Jvm.target)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ kotlin {
jvm()
js {
nodejs()
useCommonJs()
}
jvmToolchain(Jvm.target)

Expand Down
3 changes: 2 additions & 1 deletion gateway/src/jsMain/kotlin/DefaultGateway.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.kord.gateway

import io.ktor.client.plugins.websocket.*
import node.process.process

internal actual fun Throwable.isTimeout() = this is WebSocketException && "ENOTFOUND" in toString()
internal actual val os: String get() = js("process.platform") as String
internal actual val os: String get() = process.platform.toString()
1 change: 0 additions & 1 deletion gateway/src/jsMain/kotlin/internal/JsInflater.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
@file:JsModule("fast-zlib")
@file:JsNonModule

package dev.kord.gateway.internal

Expand Down
3 changes: 2 additions & 1 deletion test-kit/src/jsMain/kotlin/Platform.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.kord.test

import io.ktor.utils.io.*
import node.process.process

actual object Platform {
actual const val IS_JVM: Boolean = false
Expand All @@ -10,7 +11,7 @@ actual object Platform {
) as Boolean
}

actual fun getEnv(name: String) = js("process.env[name]") as String?
actual fun getEnv(name: String) = process.env[name]

actual suspend fun file(project: String, path: String): String =
if (Platform.IS_NODE) nodeFile(project, path) else TODO("Browser JS is not supported yet")
Expand Down
3 changes: 2 additions & 1 deletion test-kit/src/jsMain/kotlin/Platform.node.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package dev.kord.test
import io.ktor.utils.io.*
import node.buffer.BufferEncoding
import node.fs.readFile
import node.process.process

internal suspend fun nodeFile(project: String, path: String): String =
readFile("${js("process.env[\"PROJECT_ROOT\"]")}/$project/src/commonTest/resources/$path", BufferEncoding.utf8)
readFile("${process.env["PROJECT_ROOT"]}/$project/src/commonTest/resources/$path", BufferEncoding.utf8)

internal suspend fun nodeReadFile(project: String, path: String) = ByteReadChannel(nodeFile(project, path))

0 comments on commit 5bcc68e

Please sign in to comment.