Skip to content

Commit 5ac9b0c

Browse files
authored
Bump KGP to 2.2.20, remove kotlin-node dependency (#35)
* Remove kotlin-node * Remove kotlin-node dependency * wip * apiDump * internal
1 parent 9cd01f4 commit 5ac9b0c

File tree

10 files changed

+320
-218
lines changed

10 files changed

+320
-218
lines changed

apollo-mockserver/api/apollo-mockserver.klib.api

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ final object com.apollographql.mockserver/PingFrame : com.apollographql.mockserv
172172

173173
final object com.apollographql.mockserver/PongFrame : com.apollographql.mockserver/WebSocketMessage // com.apollographql.mockserver/PongFrame|null[0]
174174

175-
final const val com.apollographql.mockserver/VERSION // com.apollographql.mockserver/VERSION|{}VERSION[0]
175+
final val com.apollographql.mockserver/VERSION // com.apollographql.mockserver/VERSION|{}VERSION[0]
176176
final fun <get-VERSION>(): kotlin/String // com.apollographql.mockserver/VERSION.<get-VERSION>|<get-VERSION>(){}[0]
177177

178178
final fun (com.apollographql.mockserver/MockServer).com.apollographql.mockserver/assertNoRequest() // com.apollographql.mockserver/assertNoRequest|[email protected](){}[0]

apollo-mockserver/build.gradle.kts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import com.gradleup.librarian.gradle.Librarian
22
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
3+
import org.jetbrains.kotlin.gradle.plugin.getKotlinPluginVersion
4+
import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeHostTest
5+
import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeTest
36

47
plugins {
58
id("org.jetbrains.kotlin.multiplatform")
@@ -22,8 +25,9 @@ kotlin {
2225
tvosSimulatorArm64()
2326
linuxArm64()
2427
linuxX64()
25-
js(IR) {
28+
js {
2629
nodejs()
30+
useCommonJs()
2731
}
2832
@Suppress("OPT_IN_USAGE")
2933
wasmJs {
@@ -40,6 +44,7 @@ kotlin {
4044
withLinuxArm64()
4145
withLinuxX64()
4246
}
47+
withJs()
4348
withJvm()
4449
withLinuxArm64()
4550
withLinuxX64()
@@ -60,7 +65,7 @@ kotlin {
6065

6166
findByName("jsMain")?.apply {
6267
dependencies {
63-
implementation(libs.kotlin.node)
68+
implementation("org.jetbrains.kotlin:kotlin-stdlib-js:${getKotlinPluginVersion()}")
6469
}
6570
}
6671

@@ -83,6 +88,7 @@ kotlin {
8388
findByName("jsTest")?.apply {
8489
dependencies {
8590
implementation(libs.ktor.client.js)
91+
implementation("org.jetbrains.kotlin:kotlin-test-js:${getKotlinPluginVersion()}")
8692
}
8793
}
8894
findByName("wasmJsMain")!!.apply {
@@ -108,3 +114,15 @@ kotlin {
108114
}
109115
}
110116

117+
if (System.getenv("CI") == "true") {
118+
listOf(
119+
"watchosSimulatorArm64Test",
120+
"iosX64Test",
121+
"tvosSimulatorArm64Test",
122+
"iosSimulatorArm64Test",
123+
"tvosX64Test"
124+
).forEach {
125+
println("Task '$it' is long and is skipped in CI.")
126+
gradle.startParameter.excludedTaskNames.add(it)
127+
}
128+
}

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

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11
package com.apollographql.mockserver
22

3-
import js.typedarrays.toUint8Array
43
import kotlinx.coroutines.channels.Channel
5-
import node.events.once
6-
import node.net.AddressInfo
7-
import node.net.createServer
4+
import kotlinx.coroutines.suspendCancellableCoroutine
85
import okio.IOException
96
import org.w3c.dom.events.Event
10-
import node.net.Server as WrappedServer
11-
import node.net.Socket as WrappedSocket
7+
import kotlin.coroutines.resume
8+
import com.apollographql.mockserver.Server as WrappedServer
9+
import com.apollographql.mockserver.Socket as WrappedSocket
1210

1311
internal class NodeTcpSocket(private val netSocket: WrappedSocket) : TcpSocket {
1412
private val readQueue = Channel<ByteArray>(Channel.UNLIMITED)
1513

1614
init {
17-
netSocket.dataEvent.addHandler { (chunk) ->
18-
readQueue.trySend(chunk.toByteArray())
15+
netSocket.on("data") { chunk ->
16+
val buffer = chunk.unsafeCast<Buffer>()
17+
readQueue.trySend(buffer.buffer.toByteArray())
1918
}
2019

21-
netSocket.closeEvent.addHandler { _ ->
20+
netSocket.on("close") { _ ->
2221
readQueue.close(IOException("The socket was closed"))
2322
}
2423
}
@@ -29,7 +28,7 @@ internal class NodeTcpSocket(private val netSocket: WrappedSocket) : TcpSocket {
2928

3029
override fun send(data: ByteArray) {
3130
// Enqueue everything
32-
netSocket.write(data.toUint8Array())
31+
netSocket.write(data.toUint8Array()) {}
3332
}
3433

3534
override fun close() {
@@ -57,6 +56,12 @@ internal class NodeTcpServer(private val port: Int) : TcpServer {
5756
}
5857
}
5958

59+
private suspend fun WrappedServer.waitForListening() = suspendCancellableCoroutine { continuation ->
60+
on("listening") {
61+
continuation.resume(Unit)
62+
}
63+
}
64+
6065
override suspend fun address(): Address {
6166
require(!isClosed) { "Server is closed" }
6267
val server = requireNotNull(this.server) { "Server is not listening, please call listen() before calling address()" }
@@ -65,7 +70,7 @@ internal class NodeTcpServer(private val port: Int) : TcpServer {
6570
return address!!
6671
}
6772

68-
server.listeningEvent.once()
73+
server.waitForListening()
6974

7075
val ai = server.address().unsafeCast<AddressInfo>()
7176
address = Address(ai.address, ai.port.toInt())
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.apollographql.mockserver
2+
3+
import org.khronos.webgl.ArrayBuffer
4+
import org.khronos.webgl.Uint8Array
5+
6+
/**
7+
* https://nodejs.org/docs/latest/api/buffer.html
8+
*/
9+
internal external interface Buffer {
10+
val buffer: ArrayBuffer
11+
}
12+
13+
/***
14+
* https://nodejs.org/docs/latest/api/net.html
15+
*/
16+
internal external interface Socket {
17+
fun on(event: String, listener: (dynamic) -> Unit)
18+
fun destroy()
19+
fun write(
20+
buffer: Uint8Array,
21+
callback: (dynamic) -> Unit,
22+
): Boolean
23+
}
24+
25+
internal external interface Server {
26+
fun listen(port: Int)
27+
fun close()
28+
fun address(): Any?
29+
fun on(event: String, listener: (dynamic) -> Unit)
30+
}
31+
32+
internal external interface AddressInfo {
33+
var address: String
34+
var family: String
35+
var port: Double
36+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.apollographql.mockserver
2+
3+
import org.khronos.webgl.ArrayBuffer
4+
import org.khronos.webgl.Int8Array
5+
import org.khronos.webgl.Uint8Array
6+
7+
internal fun ArrayBuffer.toByteArray(): ByteArray = Int8Array(this).unsafeCast<ByteArray>()
8+
9+
10+
internal fun ByteArray.toUint8Array(): Uint8Array {
11+
val i8a = unsafeCast<Int8Array>()
12+
return Uint8Array(i8a.buffer, i8a.byteOffset, i8a.byteLength)
13+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* From https://nodejs.org/api/https.html
3+
*/
4+
@file:JsModule("node:net")
5+
6+
package com.apollographql.mockserver
7+
8+
9+
internal external fun createServer(requestListener: (Socket) -> Unit): Server

build.gradle.kts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ import com.gradleup.librarian.gradle.Librarian
22

33
plugins {
44
alias(libs.plugins.kgp).apply(false)
5-
id("com.gradleup.librarian").version("0.1.1-SNAPSHOT-e64004307778d825d359d0a6d1243f7d16ca2653").apply(false)
6-
id("org.jetbrains.kotlinx.binary-compatibility-validator").version("0.18.1")
7-
id("com.gradleup.nmcp").version("1.0.4-SNAPSHOT-aa74448010e9ec667068e89bdd97ed5edbdf059b")
5+
alias(libs.plugins.librarian).apply(false)
6+
alias(libs.plugins.nmcp).apply(false)
87
}
98

109
Librarian.root(project)

gradle/libs.versions.toml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,24 @@ 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"
7+
kgp = "2.2.20"
88

99
[libraries]
10-
kotlin-node = "org.jetbrains.kotlin-wrappers:kotlin-node:22.5.5-pre.844"
1110
kotlinx-coroutines-core = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version.ref = "kotlinx-coroutines" }
1211
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" }
12+
kotlin-stdlib-wasm-js = { group = "org.jetbrains.kotlin", name = "kotlin-stdlib-wasm-js", version.ref = "kgp" }
1413
okio = { group = "com.squareup.okio", name = "okio", version.ref = "okio" }
1514
atomicfu-library = { group = "org.jetbrains.kotlinx", name = "atomicfu", version.ref = "atomicfu" }
1615
ktor-server-core = { group = "io.ktor", name = "ktor-server-core", version.ref = "ktor" }
1716
ktor-server-cio = { group = "io.ktor", name = "ktor-server-cio", version.ref = "ktor" }
1817
ktor-server-websockets = { group = "io.ktor", name = "ktor-server-websockets", version.ref = "ktor" }
1918
ktor-network = { module = "io.ktor:ktor-network", version.ref = "ktor" }
20-
ktor-client-core = { group = "io.ktor", name= "ktor-client-core", version.ref = "ktor" }
21-
ktor-client-cio = { group = "io.ktor", name= "ktor-client-cio", version.ref = "ktor" }
22-
ktor-client-js = { group = "io.ktor", name= "ktor-client-js", version.ref = "ktor" }
19+
ktor-client-core = { group = "io.ktor", name = "ktor-client-core", version.ref = "ktor" }
20+
ktor-client-cio = { group = "io.ktor", name = "ktor-client-cio", version.ref = "ktor" }
21+
ktor-client-js = { group = "io.ktor", name = "ktor-client-js", version.ref = "ktor" }
2322
okhttp = { group = "com.squareup.okhttp3", name = "okhttp", version.ref = "okhttp" }
2423

2524
[plugins]
26-
kgp = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin"}
25+
kgp = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kgp" }
26+
librarian = { id = "com.gradleup.librarian", version = "0.1.1-SNAPSHOT-4b2cda1c023f0fad4064d8ccb7ab6ca4d10d09f1" }
27+
nmcp = { id = "com.gradleup.nmcp", version = "1.1.1-SNAPSHOT-79a7d177a1f1b73774d157982aab8550222268d3" }

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-9.0.0-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-9.1.0-rc-1-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

0 commit comments

Comments
 (0)