Skip to content

Commit 5ba4dec

Browse files
authored
Update Kotlin and kotlin-wrappers (#18)
1 parent 04774a3 commit 5ba4dec

File tree

6 files changed

+109
-120
lines changed

6 files changed

+109
-120
lines changed

apollo-mockserver/build.gradle.kts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import com.gradleup.librarian.gradle.librarianModule
22
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
3-
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
43

54
plugins {
65
id("org.jetbrains.kotlin.multiplatform")
@@ -24,7 +23,7 @@ kotlin {
2423
js(IR) {
2524
nodejs()
2625
}
27-
@OptIn(ExperimentalWasmDsl::class)
26+
@Suppress("OPT_IN_USAGE")
2827
wasmJs {
2928
nodejs()
3029
}
@@ -80,6 +79,11 @@ kotlin {
8079
implementation(libs.ktor.client.js)
8180
}
8281
}
82+
findByName("wasmJsMain")!!.apply {
83+
dependencies {
84+
implementation(libs.kotlin.stdlib.wasm.js)
85+
}
86+
}
8387

8488
findByName("jvmTest")?.apply {
8589
dependencies {

apollo-mockserver/src/jsMain/kotlin/com/apollographql/mockserver/TcpServer.js.kt

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,23 @@ package com.apollographql.mockserver
22

33
import js.typedarrays.toUint8Array
44
import kotlinx.coroutines.channels.Channel
5-
import node.buffer.Buffer
6-
import node.events.Event
5+
import node.events.once
76
import node.net.AddressInfo
87
import node.net.createServer
9-
import node.test.it
108
import okio.IOException
11-
import kotlin.coroutines.resume
12-
import kotlin.coroutines.suspendCoroutine
9+
import org.w3c.dom.events.Event
1310
import node.net.Server as WrappedServer
1411
import node.net.Socket as WrappedSocket
1512

1613
internal class NodeTcpSocket(private val netSocket: WrappedSocket) : TcpSocket {
1714
private val readQueue = Channel<ByteArray>(Channel.UNLIMITED)
1815

1916
init {
20-
netSocket.on(Event.DATA) { chunk ->
21-
val bytes = when (chunk) {
22-
is String -> chunk.encodeToByteArray()
23-
is Buffer -> chunk.toByteArray()
24-
else -> error("Unexpected chunk type: ${chunk::class}")
25-
}
26-
readQueue.trySend(bytes)
17+
netSocket.dataEvent.addHandler { (chunk) ->
18+
readQueue.trySend(chunk.toByteArray())
2719
}
2820

29-
netSocket.on(Event.CLOSE) { _ ->
21+
netSocket.closeEvent.addHandler { _ ->
3022
readQueue.close(IOException("The socket was closed"))
3123
}
3224
}
@@ -69,17 +61,15 @@ internal class NodeTcpServer(private val port: Int) : TcpServer {
6961
require(!isClosed) { "Server is closed" }
7062
val server = requireNotNull(this.server) { "Server is not listening, please call listen() before calling address()" }
7163

72-
return address ?: suspendCoroutine { cont ->
73-
server.once(Event.LISTENING) {
74-
val server = requireNotNull(this.server) {
75-
"close() was called during a call to address()"
76-
}
77-
val address = server.address().unsafeCast<AddressInfo>()
78-
this.address = Address(address.address, address.port.toInt()).also {
79-
cont.resume(it)
80-
}
81-
}
64+
if (address != null) {
65+
return address!!
8266
}
67+
68+
server.listeningEvent.once()
69+
70+
val ai = server.address().unsafeCast<AddressInfo>()
71+
address = Address(ai.address, ai.port.toInt())
72+
return address!!
8373
}
8474

8575
override fun close() {

build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import com.gradleup.librarian.gradle.librarianRoot
22

33
plugins {
4-
id("org.jetbrains.kotlin.multiplatform").version("2.0.0").apply(false)
4+
alias(libs.plugins.kgp).apply(false)
55
id("com.gradleup.librarian").version("0.0.6").apply(false)
6+
id("org.jetbrains.kotlinx.binary-compatibility-validator") version "0.16.3" apply false
67
}
78

89
librarianRoot()

gradle.properties

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@ org.gradle.jvmargs=-Xmx8g
22

33
#org.gradle.configuration-cache=true
44

5-
kotlin.wasm.stability.nowarn=true

gradle/libs.versions.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ ktor = "3.0.0"
44
atomicfu = "0.25.0"
55
kotlinx-coroutines = "1.9.0"
66
okhttp = "4.12.0"
7+
kotlin = "2.1.0"
78

89
[libraries]
9-
kotlin-node = "org.jetbrains.kotlin-wrappers:kotlin-node:18.16.12-pre.634"
10+
kotlin-node = "org.jetbrains.kotlin-wrappers:kotlin-node:22.5.5-pre.844"
1011
kotlinx-coroutines-core = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version.ref = "kotlinx-coroutines" }
1112
kotlinx-coroutines-test = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-test", version.ref = "kotlinx-coroutines" }
13+
kotlin-stdlib-wasm-js = { group = "org.jetbrains.kotlin", name = "kotlin-stdlib-wasm-js", version.ref = "kotlin" }
1214
okio = { group = "com.squareup.okio", name = "okio", version.ref = "okio" }
1315
atomicfu-library = { group = "org.jetbrains.kotlinx", name = "atomicfu", version.ref = "atomicfu" }
1416
ktor-server-core = { group = "io.ktor", name = "ktor-server-core", version.ref = "ktor" }
@@ -19,3 +21,6 @@ ktor-client-core = { group = "io.ktor", name= "ktor-client-core", version.ref =
1921
ktor-client-cio = { group = "io.ktor", name= "ktor-client-cio", version.ref = "ktor" }
2022
ktor-client-js = { group = "io.ktor", name= "ktor-client-js", version.ref = "ktor" }
2123
okhttp = { group = "com.squareup.okhttp3", name = "okhttp", version.ref = "okhttp" }
24+
25+
[plugins]
26+
kgp = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin"}

0 commit comments

Comments
 (0)