diff --git a/projects/core/koin-core/build.gradle.kts b/projects/core/koin-core/build.gradle.kts index 4baf6e50a..8915853e2 100644 --- a/projects/core/koin-core/build.gradle.kts +++ b/projects/core/koin-core/build.gradle.kts @@ -1,3 +1,4 @@ +import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { @@ -15,6 +16,11 @@ kotlin { binaries.executable() } + wasmJs { + binaries.executable() + nodejs() + } + iosX64() iosArm64() iosSimulatorArm64() @@ -47,5 +53,12 @@ tasks.withType().all { jvmTarget = "1.8" } } +rootProject.the().apply { + nodeVersion = "21.0.0-v8-canary202309143a48826a08" + nodeDownloadBaseUrl = "https://nodejs.org/download/v8-canary" +} +tasks.withType().configureEach { + args.add("--ignore-engines") +} apply(from = file("../../gradle/publish.gradle.kts")) diff --git a/projects/core/koin-core/src/wasmJsMain/kotlin/org/koin/core/context/GlobalContext.kt b/projects/core/koin-core/src/wasmJsMain/kotlin/org/koin/core/context/GlobalContext.kt new file mode 100644 index 000000000..68e5767a5 --- /dev/null +++ b/projects/core/koin-core/src/wasmJsMain/kotlin/org/koin/core/context/GlobalContext.kt @@ -0,0 +1,78 @@ +/* + * Copyright 2017-Present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.koin.core.context + +import org.koin.core.Koin +import org.koin.core.KoinApplication +import org.koin.core.error.ApplicationAlreadyStartedException +import org.koin.core.module.Module +import org.koin.dsl.KoinAppDeclaration + +/** + * Global context - current Koin Application available globally + * + * Support to help inject automatically instances once KoinApp has been started + * + * @author Arnaud Giuliani + */ +object GlobalContext : KoinContext { + + private var _koin: Koin? = null + + override fun get(): Koin = _koin ?: error("KoinApplication has not been started") + + override fun getOrNull(): Koin? = _koin + + private fun register(koinApplication: KoinApplication) { + if (_koin != null) { + throw ApplicationAlreadyStartedException("A Koin Application has already been started") + } + _koin = koinApplication.koin + } + + override fun stopKoin() { + _koin?.close() + _koin = null + } + + override fun startKoin(koinApplication: KoinApplication): KoinApplication { + register(koinApplication) + return koinApplication + } + + override fun startKoin(appDeclaration: KoinAppDeclaration): KoinApplication { + val koinApplication = KoinApplication.init() + register(koinApplication) + appDeclaration(koinApplication) + return koinApplication + } + + override fun loadKoinModules(module: Module,createEagerInstances : Boolean) { + get().loadModules(listOf(module), createEagerInstances = createEagerInstances) + } + + override fun loadKoinModules(modules: List, createEagerInstances : Boolean) { + get().loadModules(modules, createEagerInstances = createEagerInstances) + } + + override fun unloadKoinModules(module: Module) { + get().unloadModules(listOf(module)) + } + + override fun unloadKoinModules(modules: List) { + get().unloadModules(modules) + } +} diff --git a/projects/core/koin-core/src/wasmJsMain/kotlin/org/koin/core/logger/PrintLogger.kt b/projects/core/koin-core/src/wasmJsMain/kotlin/org/koin/core/logger/PrintLogger.kt new file mode 100644 index 000000000..ad2e0ea09 --- /dev/null +++ b/projects/core/koin-core/src/wasmJsMain/kotlin/org/koin/core/logger/PrintLogger.kt @@ -0,0 +1,27 @@ +/* + * Copyright 2017-Present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.koin.core.logger + +/** + * Logger that print on system.out + * @author - Arnaud GIULIANI + */ +class PrintLogger(level: Level = Level.INFO) : Logger(level) { + + override fun display(level: Level, msg: MESSAGE) { + println("[$level] $KOIN_TAG $msg") + } +} diff --git a/projects/core/koin-core/src/wasmJsMain/kotlin/org/koin/mp/PlatformTimeTools.kt b/projects/core/koin-core/src/wasmJsMain/kotlin/org/koin/mp/PlatformTimeTools.kt new file mode 100644 index 000000000..448586cfa --- /dev/null +++ b/projects/core/koin-core/src/wasmJsMain/kotlin/org/koin/mp/PlatformTimeTools.kt @@ -0,0 +1,9 @@ +package org.koin.mp + +import kotlin.time.TimeSource + +actual object KoinPlatformTimeTools { + actual fun getTimeInNanoSeconds(): Long { + return TimeSource.Monotonic.markNow().elapsedNow().inWholeNanoseconds + } +} diff --git a/projects/core/koin-core/src/wasmJsMain/kotlin/org/koin/mp/PlatformTools.kt b/projects/core/koin-core/src/wasmJsMain/kotlin/org/koin/mp/PlatformTools.kt new file mode 100644 index 000000000..3612f0a69 --- /dev/null +++ b/projects/core/koin-core/src/wasmJsMain/kotlin/org/koin/mp/PlatformTools.kt @@ -0,0 +1,59 @@ +/* + * Copyright 2017-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.koin.mp + +import co.touchlab.stately.concurrency.ThreadLocalRef +import org.koin.core.context.GlobalContext +import org.koin.core.context.KoinContext +import org.koin.core.logger.* +import kotlin.random.Random +import kotlin.reflect.KClass + +// actual object PlatformTools { +// actual fun getClassName(kClass: KClass<*>): String { +// return kClass.simpleName ?: "KClass@${hashCode()}" +// } +// +// actual fun printStackTrace(throwable: Throwable) { +// throwable.printStackTrace() +// } +// +// actual fun stackTrace(): List = Exception().toString().split("\n") +// +// actual fun printLog(level: Level, msg: MESSAGE) { +// println("[$level] $KOIN_TAG $msg") +// } +// } +// internal actual fun Any.ensureNeverFrozen() {} +// internal actual fun mpsynchronized(lock: Any, block: () -> R): R = block() + +actual object KoinPlatformTools { + actual fun getStackTrace(e: Exception): String = e.toString() + Exception().toString().split("\n") + actual fun getClassName(kClass: KClass<*>): String = kClass.simpleName ?: "KClass@${kClass.hashCode()}" + + // TODO Better Id generation? + actual fun generateId(): String = Random.nextDouble().hashCode().toString() + actual fun defaultLazyMode(): LazyThreadSafetyMode = LazyThreadSafetyMode.NONE + actual fun defaultLogger(level: Level): Logger = PrintLogger(level) + actual fun defaultContext(): KoinContext = GlobalContext + actual fun synchronized(lock: Lockable, block: () -> R) = block() + actual fun safeHashMap(): MutableMap = HashMap() +} + +actual typealias Lockable = Any + +actual typealias ThreadLocal = ThreadLocalRef \ No newline at end of file diff --git a/projects/core/koin-test/build.gradle.kts b/projects/core/koin-test/build.gradle.kts index b92e7008b..743eb5bd0 100644 --- a/projects/core/koin-test/build.gradle.kts +++ b/projects/core/koin-test/build.gradle.kts @@ -1,3 +1,4 @@ +import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { @@ -14,6 +15,10 @@ kotlin { browser() binaries.executable() } + wasmJs { + binaries.executable() + nodejs() + } iosX64() iosArm64() @@ -47,5 +52,13 @@ tasks.withType().all { jvmTarget = "1.8" } } +rootProject.the().apply { + nodeVersion = "21.0.0-v8-canary202309143a48826a08" + nodeDownloadBaseUrl = "https://nodejs.org/download/v8-canary" +} + +tasks.withType().configureEach { + args.add("--ignore-engines") +} apply(from = file("../../gradle/publish.gradle.kts")) diff --git a/projects/gradle.properties b/projects/gradle.properties index 94ebe34d5..5eaf0982b 100644 --- a/projects/gradle.properties +++ b/projects/gradle.properties @@ -7,9 +7,9 @@ org.gradle.parallel=true #Kotlin kotlin.code.style=official #Koin -koinVersion=3.6.0-alpha1 +koinVersion=3.6.0-wasm1 #Compose -composeCompiler=1.5.7 +composeCompiler=1.5.5 #Android android.useAndroidX=true androidMinSDK=14 diff --git a/projects/gradle/libs.versions.toml b/projects/gradle/libs.versions.toml index 00036c9b5..908edbe43 100644 --- a/projects/gradle/libs.versions.toml +++ b/projects/gradle/libs.versions.toml @@ -3,7 +3,7 @@ # /!\ Koin in gradle.properties /!\ # Core -kotlin = "1.9.21" +kotlin = "1.9.20" binaryValidator = "0.13.2" publish = "2.0.0-rc-1" coroutines = "1.7.3" # "1.8.0-RC2" for wasm @@ -19,7 +19,7 @@ androidx-workmanager = "2.8.1" androidx-navigation = "2.7.5" # Compose # /!\ Compose compiler in gradle.properties /!\ -composeJB = "1.5.11" +composeJB = "1.5.10" composeJetpackRuntime = "1.5.4" composeJetpackViewmodel = "2.6.2" # Test