Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Kotlin and kotlin-wrappers #18

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions apollo-mockserver/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import com.gradleup.librarian.gradle.librarianModule
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl

plugins {
id("org.jetbrains.kotlin.multiplatform")
Expand All @@ -24,7 +23,7 @@ kotlin {
js(IR) {
nodejs()
}
@OptIn(ExperimentalWasmDsl::class)
@Suppress("OPT_IN_USAGE")
wasmJs {
nodejs()
}
Expand Down Expand Up @@ -80,6 +79,11 @@ kotlin {
implementation(libs.ktor.client.js)
}
}
findByName("wasmJsMain")!!.apply {
dependencies {
implementation(libs.kotlin.stdlib.wasm.js)
}
}

findByName("jvmTest")?.apply {
dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,23 @@ package com.apollographql.mockserver

import js.typedarrays.toUint8Array
import kotlinx.coroutines.channels.Channel
import node.buffer.Buffer
import node.events.Event
import node.events.once
import node.net.AddressInfo
import node.net.createServer
import node.test.it
import okio.IOException
import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine
import org.w3c.dom.events.Event
import node.net.Server as WrappedServer
import node.net.Socket as WrappedSocket

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

init {
netSocket.on(Event.DATA) { chunk ->
val bytes = when (chunk) {
is String -> chunk.encodeToByteArray()
is Buffer -> chunk.toByteArray()
else -> error("Unexpected chunk type: ${chunk::class}")
}
readQueue.trySend(bytes)
netSocket.dataEvent.addHandler { (chunk) ->
readQueue.trySend(chunk.toByteArray())
}

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

return address ?: suspendCoroutine { cont ->
server.once(Event.LISTENING) {
val server = requireNotNull(this.server) {
"close() was called during a call to address()"
}
val address = server.address().unsafeCast<AddressInfo>()
this.address = Address(address.address, address.port.toInt()).also {
cont.resume(it)
}
}
if (address != null) {
return address!!
}

server.listeningEvent.once()

val ai = server.address().unsafeCast<AddressInfo>()
address = Address(ai.address, ai.port.toInt())
return address!!
}

override fun close() {
Expand Down
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import com.gradleup.librarian.gradle.librarianRoot

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

librarianRoot()
1 change: 0 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ org.gradle.jvmargs=-Xmx8g

#org.gradle.configuration-cache=true

kotlin.wasm.stability.nowarn=true
7 changes: 6 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ ktor = "3.0.0"
atomicfu = "0.25.0"
kotlinx-coroutines = "1.9.0"
okhttp = "4.12.0"
kotlin = "2.1.0"

[libraries]
kotlin-node = "org.jetbrains.kotlin-wrappers:kotlin-node:18.16.12-pre.634"
kotlin-node = "org.jetbrains.kotlin-wrappers:kotlin-node:22.5.5-pre.844"
kotlinx-coroutines-core = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version.ref = "kotlinx-coroutines" }
kotlinx-coroutines-test = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-test", version.ref = "kotlinx-coroutines" }
kotlin-stdlib-wasm-js = { group = "org.jetbrains.kotlin", name = "kotlin-stdlib-wasm-js", version.ref = "kotlin" }
okio = { group = "com.squareup.okio", name = "okio", version.ref = "okio" }
atomicfu-library = { group = "org.jetbrains.kotlinx", name = "atomicfu", version.ref = "atomicfu" }
ktor-server-core = { group = "io.ktor", name = "ktor-server-core", version.ref = "ktor" }
Expand All @@ -19,3 +21,6 @@ ktor-client-core = { group = "io.ktor", name= "ktor-client-core", version.ref =
ktor-client-cio = { group = "io.ktor", name= "ktor-client-cio", version.ref = "ktor" }
ktor-client-js = { group = "io.ktor", name= "ktor-client-js", version.ref = "ktor" }
okhttp = { group = "com.squareup.okhttp3", name = "okhttp", version.ref = "okhttp" }

[plugins]
kgp = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin"}
Loading