From 24b6eb12125306db6b9d915b1fde5e0e7eb6777c Mon Sep 17 00:00:00 2001 From: Elie G Date: Mon, 4 Nov 2024 10:23:26 +0200 Subject: [PATCH] Resolved issues #2031 and #2024 by integrating the benasher44/uuid library to generate UUIDs for WebAssembly targets. --- projects/core/koin-core/build.gradle.kts | 3 +++ .../src/commonMain/kotlin/org/koin/mp/KoinPlatformTools.kt | 2 +- .../src/jsMain/kotlin/org/koin/mp/KoinPlatformTools.js.kt | 7 +++++++ .../jvmMain/kotlin/org/koin/mp/KoinPlatformTools.jvm.kt | 7 +++++++ .../kotlin/org/koin/mp/KoinPlatformTools.native.kt | 7 +++++++ .../kotlin/org/koin/mp/KoinPlatformTools.wasmJs.kt | 5 +++++ projects/gradle/libs.versions.toml | 2 ++ 7 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 projects/core/koin-core/src/jsMain/kotlin/org/koin/mp/KoinPlatformTools.js.kt create mode 100644 projects/core/koin-core/src/jvmMain/kotlin/org/koin/mp/KoinPlatformTools.jvm.kt create mode 100644 projects/core/koin-core/src/nativeMain/kotlin/org/koin/mp/KoinPlatformTools.native.kt create mode 100644 projects/core/koin-core/src/wasmJsMain/kotlin/org/koin/mp/KoinPlatformTools.wasmJs.kt diff --git a/projects/core/koin-core/build.gradle.kts b/projects/core/koin-core/build.gradle.kts index 260b1568e..3a5a76889 100644 --- a/projects/core/koin-core/build.gradle.kts +++ b/projects/core/koin-core/build.gradle.kts @@ -50,6 +50,9 @@ kotlin { implementation(libs.kotlin.test) implementation(libs.test.coroutines) } + wasmJsMain.dependencies { + implementation(libs.uuid) + } } } diff --git a/projects/core/koin-core/src/commonMain/kotlin/org/koin/mp/KoinPlatformTools.kt b/projects/core/koin-core/src/commonMain/kotlin/org/koin/mp/KoinPlatformTools.kt index d8b4e36ac..5092d8bc5 100644 --- a/projects/core/koin-core/src/commonMain/kotlin/org/koin/mp/KoinPlatformTools.kt +++ b/projects/core/koin-core/src/commonMain/kotlin/org/koin/mp/KoinPlatformTools.kt @@ -36,5 +36,5 @@ expect object KoinPlatformTools { fun KoinPlatformTools.getKClassDefaultName(kClass: KClass<*>) : String = "KClass@${kClass.hashCode()}" @OptIn(ExperimentalUuidApi::class) -fun KoinPlatformTools.generateId() : String = Uuid.random().toString() +expect fun KoinPlatformTools.generateId() : String diff --git a/projects/core/koin-core/src/jsMain/kotlin/org/koin/mp/KoinPlatformTools.js.kt b/projects/core/koin-core/src/jsMain/kotlin/org/koin/mp/KoinPlatformTools.js.kt new file mode 100644 index 000000000..5cd37091d --- /dev/null +++ b/projects/core/koin-core/src/jsMain/kotlin/org/koin/mp/KoinPlatformTools.js.kt @@ -0,0 +1,7 @@ +package org.koin.mp + +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid + +@OptIn(ExperimentalUuidApi::class) +actual fun KoinPlatformTools.generateId(): String = Uuid.random().toString() \ No newline at end of file diff --git a/projects/core/koin-core/src/jvmMain/kotlin/org/koin/mp/KoinPlatformTools.jvm.kt b/projects/core/koin-core/src/jvmMain/kotlin/org/koin/mp/KoinPlatformTools.jvm.kt new file mode 100644 index 000000000..5cd37091d --- /dev/null +++ b/projects/core/koin-core/src/jvmMain/kotlin/org/koin/mp/KoinPlatformTools.jvm.kt @@ -0,0 +1,7 @@ +package org.koin.mp + +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid + +@OptIn(ExperimentalUuidApi::class) +actual fun KoinPlatformTools.generateId(): String = Uuid.random().toString() \ No newline at end of file diff --git a/projects/core/koin-core/src/nativeMain/kotlin/org/koin/mp/KoinPlatformTools.native.kt b/projects/core/koin-core/src/nativeMain/kotlin/org/koin/mp/KoinPlatformTools.native.kt new file mode 100644 index 000000000..5cd37091d --- /dev/null +++ b/projects/core/koin-core/src/nativeMain/kotlin/org/koin/mp/KoinPlatformTools.native.kt @@ -0,0 +1,7 @@ +package org.koin.mp + +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid + +@OptIn(ExperimentalUuidApi::class) +actual fun KoinPlatformTools.generateId(): String = Uuid.random().toString() \ No newline at end of file diff --git a/projects/core/koin-core/src/wasmJsMain/kotlin/org/koin/mp/KoinPlatformTools.wasmJs.kt b/projects/core/koin-core/src/wasmJsMain/kotlin/org/koin/mp/KoinPlatformTools.wasmJs.kt new file mode 100644 index 000000000..57e4ad4c5 --- /dev/null +++ b/projects/core/koin-core/src/wasmJsMain/kotlin/org/koin/mp/KoinPlatformTools.wasmJs.kt @@ -0,0 +1,5 @@ +package org.koin.mp + +import com.benasher44.uuid.uuid4 + +actual fun KoinPlatformTools.generateId(): String = uuid4().toString() \ No newline at end of file diff --git a/projects/gradle/libs.versions.toml b/projects/gradle/libs.versions.toml index db8b777bb..df13750dc 100644 --- a/projects/gradle/libs.versions.toml +++ b/projects/gradle/libs.versions.toml @@ -37,6 +37,7 @@ mockk = "1.13.2" # Ktor ktor = "2.3.12" slf4j = "2.0.13" +uuidVersion = "0.8.4" [libraries] # Core @@ -79,6 +80,7 @@ jb-bundle = { module = "org.jetbrains.androidx.core:core-bundle", version.ref = jb-savedstate = { module = "org.jetbrains.androidx.savedstate:savedstate", version.ref = "jbSavedState" } jb-composeNavigation = { module = "org.jetbrains.androidx.navigation:navigation-compose", version.ref = "composeNavigation" } jb-navigation = { module = "org.jetbrains.androidx.navigation:navigation-common", version.ref = "composeNavigation" } +uuid = { module = "com.benasher44:uuid", version.ref = "uuidVersion" } [plugins] kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }