Skip to content
Open
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
14 changes: 14 additions & 0 deletions buildSrc/src/main/kotlin/Compiler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_1_8
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerOptions
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompilerOptions
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsTargetDsl

val kordOptIns = listOf(
"kotlin.contracts.ExperimentalContracts",
Expand All @@ -28,6 +29,19 @@ internal fun KotlinJvmCompilerOptions.applyKordJvmCompilerOptions() {
freeCompilerArgs.add("-Xjdk-release=1.8")
}

internal fun KotlinJsTargetDsl.applyKordJsTarget() {
nodejs {
testTask {
useMocha {
// disable timeouts, some tests are too slow for default 2-second timeout:
// https://mochajs.org/#-timeout-ms-t-ms
timeout = "0"
}
}
}
useCommonJs()
}

internal fun NamedDomainObjectSet<KotlinSourceSet>.applyKordTestOptIns() {
named { it.contains("test", ignoreCase = true) }.configureEach {
// allow `ExperimentalCoroutinesApi` for `TestScope.currentTime`
Expand Down
1 change: 0 additions & 1 deletion buildSrc/src/main/kotlin/Git.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import org.gradle.api.Project
import org.gradle.api.provider.Provider

internal fun Project.git(vararg command: String) = providers.exec {
commandLine("git", *command)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
@file:OptIn(ExperimentalWasmDsl::class)

import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl

plugins {
org.jetbrains.kotlin.multiplatform
Expand All @@ -20,8 +23,10 @@ kotlin {
}
}
js {
nodejs()
useCommonJs()
applyKordJsTarget()
}
wasmJs {
applyKordJsTarget()
}
}

Expand Down
30 changes: 20 additions & 10 deletions buildSrc/src/main/kotlin/kord-multiplatform-module.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
@file:OptIn(ExperimentalWasmDsl::class)

import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest

plugins {
Expand Down Expand Up @@ -36,20 +39,22 @@ kotlin {
}
}
js {
nodejs {
testTask {
useMocha {
// disable timeouts, some tests are too slow for default 2-second timeout:
// https://mochajs.org/#-timeout-ms-t-ms
timeout = "0"
}
}
}
useCommonJs()
applyKordJsTarget()
}

wasmJs {
applyKordJsTarget()
}

applyDefaultHierarchyTemplate()

applyHierarchyTemplate {
group("wasmJsShared") {
withWasmJs()
withJs()
}
}

sourceSets {
applyKordTestOptIns()
commonMain {
Expand All @@ -67,6 +72,11 @@ kotlin {
jsMain {
dependsOn(nonJvmMain)
}
wasmJsMain {
dependsOn(nonJvmMain)
}
sourceSets["wasmJsSharedTest"].dependsOn(commonTest.get())
sourceSets["wasmJsSharedMain"].dependsOn(commonMain.get())
}
}

Expand Down
12 changes: 12 additions & 0 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,25 @@ kotlin {
jsMain {
dependencies {
api(libs.ktor.client.js)
}
}

wasmJsMain {
dependencies {
api(libs.ktor.client.wasmJs)
}
}

wasmJsSharedMain {
dependencies {

// workaround for https://youtrack.jetbrains.com/issue/KT-43500 /
// https://youtrack.jetbrains.com/issue/KT-64109#focus=Comments-27-10064206.0-0 /
// https://youtrack.jetbrains.com/issue/KT-61096 (intended to be compileOnly in commonMain only)
implementation(projects.kspAnnotations)
}
}

jvmTest {
dependencies {
implementation(libs.kbson)
Expand Down
9 changes: 9 additions & 0 deletions common/src/wasmJsMain/kotlin/HttpEngine.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package dev.kord.common.http

import dev.kord.common.annotation.KordInternal
import io.ktor.client.engine.*
import io.ktor.client.engine.js.*

/** @suppress */
@KordInternal
public actual fun httpEngine(): HttpClientEngineFactory<HttpClientEngineConfig> = Js
3 changes: 3 additions & 0 deletions core/src/wasmJsMain/kotlin/KordBuilder.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package dev.kord.core.builder.kord

public actual class KordBuilder actual constructor(token: String) : BaseKordBuilder(token)
14 changes: 14 additions & 0 deletions gateway/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
@file:OptIn(ExperimentalWasmDsl::class)

import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl

plugins {
`kord-multiplatform-module`
`kord-publishing`
Expand Down Expand Up @@ -26,6 +30,16 @@ kotlin {
implementation(libs.kotlin.node)
implementation(npm("fast-zlib", libs.versions.fastZlib.get()))

// workaround for https://youtrack.jetbrains.com/issue/KT-43500 /
// https://youtrack.jetbrains.com/issue/KT-64109#focus=Comments-27-10064206.0-0 /
// https://youtrack.jetbrains.com/issue/KT-61096 (intended to be compileOnly in commonMain only)
implementation(projects.kspAnnotations)
}
}
wasmJsMain {
dependencies {
implementation(npm("fast-zlib", libs.versions.fastZlib.get()))

// workaround for https://youtrack.jetbrains.com/issue/KT-43500 /
// https://youtrack.jetbrains.com/issue/KT-64109#focus=Comments-27-10064206.0-0 /
// https://youtrack.jetbrains.com/issue/KT-61096 (intended to be compileOnly in commonMain only)
Expand Down
25 changes: 15 additions & 10 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
[versions]

# api dependencies
kotlin = "2.1.10" # https://github.com/JetBrains/kotlin
ktor = "3.0.3" # https://github.com/ktorio/ktor
kotlinx-coroutines = "1.10.1" # https://github.com/Kotlin/kotlinx.coroutines
kotlinx-serialization = "1.8.0" # https://github.com/Kotlin/kotlinx.serialization
kotlinx-datetime = "0.6.1" # https://github.com/Kotlin/kotlinx-datetime
kord-cache = "0.5.6" # https://github.com/kordlib/cache
kotlin = "2.1.21-RC" # https://github.com/JetBrains/kotlin
ktor = "3.1.2" # https://github.com/ktorio/ktor
kotlinx-coroutines = "1.10.2" # https://github.com/Kotlin/kotlinx.coroutines
kotlinx-serialization = "1.8.1" # https://github.com/Kotlin/kotlinx.serialization
kotlinx-datetime = "0.6.2" # https://github.com/Kotlin/kotlinx-datetime
kotlinx-browser = "0.3" # https://github.com/kotlin/kotlinx-browser
kord-cache = "0.5.6" # https://github.com/kordlib/cache TODO need support wasm/Js

# implementation dependencies
kotlin-logging = "7.0.3" # https://github.com/oshai/kotlin-logging
slf4j = "2.0.16" # https://www.slf4j.org
kotlin-node = "2025.2.1-22.10.5" # https://github.com/JetBrains/kotlin-wrappers
kotlin-node = "2025.4.14-22.13.10" # https://github.com/JetBrains/kotlin-wrappers
bignum = "0.3.10" # https://github.com/ionspin/kotlin-multiplatform-bignum
stately = "2.1.0" # https://github.com/touchlab/Stately
fastZlib = "2.0.1" # https://github.com/timotejroiko/fast-zlib

# code generation
ksp = "2.1.10-1.0.29" # https://github.com/google/ksp
ksp = "2.1.21-RC-2.0.0" # https://github.com/google/ksp
kotlinpoet = "2.0.0" # https://github.com/square/kotlinpoet

# tests
junit-jupiter = "5.11.4" # https://github.com/junit-team/junit5
junit-platform = "1.11.4"
mockk = "1.13.16" # https://github.com/mockk/mockk
mockk = "1.14.0" # https://github.com/mockk/mockk
kbson = "0.4.0" # https://github.com/mongodb/kbson

# plugins
dokka = "2.0.0" # https://github.com/Kotlin/dokka
kotlinx-atomicfu = "0.27.0" # https://github.com/Kotlin/kotlinx-atomicfubbn
kotlinx-atomicfu = "0.27.0" # https://github.com/Kotlin/kotlinx-atomicfu

binary-compatibility-validator = "0.17.0" # https://github.com/Kotlin/binary-compatibility-validator
buildconfig = "5.5.1" # https://github.com/gmazzo/gradle-buildconfig-plugin
Expand All @@ -44,6 +45,7 @@ ktor-client-content-negotiation = { module = "io.ktor:ktor-client-content-negoti
ktor-serialization-kotlinx-json = { module = "io.ktor:ktor-serialization-kotlinx-json", version.ref = "ktor" }
ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor" }
ktor-client-js = { module = "io.ktor:ktor-client-js", version.ref = "ktor" }
ktor-client-wasmJs = { module = "io.ktor:ktor-client-js-wasm-js", version.ref = "ktor" }
ktor-client-okhttp = { module = "io.ktor:ktor-client-okhttp", version.ref = "ktor" }
ktor-client-mock = { module = "io.ktor:ktor-client-mock", version.ref = "ktor" }
ktor-network = { module = "io.ktor:ktor-network", version.ref = "ktor" }
Expand All @@ -54,6 +56,7 @@ kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-c
kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "kotlinx-coroutines" }
kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinx-serialization" }
kotlinx-datetime = { module = "org.jetbrains.kotlinx:kotlinx-datetime", version.ref = "kotlinx-datetime" }
kotlinx-browser = { module = "org.jetbrains.kotlinx:kotlinx-browser", version.ref = "kotlinx-browser" }

# other
kotlin-logging = { module = "io.github.oshai:kotlin-logging", version.ref = "kotlin-logging" }
Expand All @@ -73,6 +76,7 @@ kotlinpoet-ksp = { module = "com.squareup:kotlinpoet-ksp", version.ref = "kotlin
kotlin-test-annotations-common = { module = "org.jetbrains.kotlin:kotlin-test-annotations-common", version.ref = "kotlin" }
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test-common", version.ref = "kotlin" }
kotlin-test-js = { module = "org.jetbrains.kotlin:kotlin-test-js", version.ref = "kotlin" }
kotlin-test-wasmJs = { module = "org.jetbrains.kotlin:kotlin-test-wasm-js", version.ref = "kotlin" }
kotlin-test-junit5 = { module = "org.jetbrains.kotlin:kotlin-test-junit5", version.ref = "kotlin" }
junit-jupiter-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "junit-jupiter" }
junit-jupiter-engine = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "junit-jupiter" }
Expand All @@ -97,6 +101,7 @@ ktor-client-serialization = ["ktor-client-content-negotiation", "ktor-serializat

test-common = ["kotlin-test-annotations-common", "kotlin-test", "kotlinx-coroutines-test"]
test-js = ["kotlin-test-js", "kotlin-node"]
test-wasmJs = ["kotlin-test-wasmJs"]
test-jvm = ["kotlin-test-junit5", "junit-jupiter-api"]
test-jvm-runtime = ["junit-jupiter-engine", "junit-platform-launcher", "slf4j-simple"]

Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionSha256Sum=8d97a97984f6cbd2b85fe4c60a743440a347544bf18818048e611f5288d46c94
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12.1-bin.zip
distributionSha256Sum=20f1b1176237254a6fc204d8434196fa11a4cfb387567519c61556e8710aed78
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
2 changes: 1 addition & 1 deletion gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ fi
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.
Expand Down
5 changes: 5 additions & 0 deletions rest/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,10 @@ kotlin {
implementation(libs.slf4j.api)
}
}
wasmJsMain {
dependencies {
implementation(libs.kotlinx.browser)
}
}
}
}
26 changes: 26 additions & 0 deletions rest/src/wasmJsMain/kotlin/RecoveredStackTrace.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package dev.kord.rest.request

internal external interface JsError {
var stack: String?
}

internal actual fun RecoveredStackTrace.sanitizeStackTrace() {
// Remove artifacts of stack trace capturing
// ContextException:
// REMOVE: at 0.doResume_0(/home/mik/IdeaProjects/ktor-suspend-function-gun-tests/src/commonMain/kotlin/Request.kt:12)
// REMOVE: at <global>.doCatching(/home/mik/IdeaProjects/ktor-suspend-function-gun-tests/src/commonMain/kotlin/Request.kt:11)
// at _no_name_provided__304.doResume_0(/home/mik/IdeaProjects/ktor-suspend-function-gun-tests/src/commonTest/kotlin/Test.kt:10)
// at _no_name_provided__304.invoke_29q9u6(/home/mik/IdeaProjects/ktor-suspend-function-gun-tests/src/commonTest/kotlin/Test.kt:9)

val error = this as JsError
val original = error.stack ?: return
error.stack = original
.lines()
.toMutableList()
.apply {
repeat(2) {
if (size > 1) removeAt(1)
}
}
.joinToString("\n")
}
5 changes: 5 additions & 0 deletions test-kit/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,10 @@ kotlin {
runtimeOnly(libs.bundles.test.jvm.runtime)
}
}
wasmJsMain {
dependencies {
//api(libs.bundles.test.wasmJs)
}
}
}
}
Loading