diff --git a/fluxo-kmp-conf/src/main/kotlin/SetupKotlinJs.kt b/fluxo-kmp-conf/src/main/kotlin/SetupKotlinJs.kt index 4adcd6ed..b21eab76 100644 --- a/fluxo-kmp-conf/src/main/kotlin/SetupKotlinJs.kt +++ b/fluxo-kmp-conf/src/main/kotlin/SetupKotlinJs.kt @@ -1,20 +1,29 @@ import fluxo.conf.dsl.container.KotlinTargetContainer -import org.gradle.api.Action +import org.jetbrains.kotlin.gradle.plugin.KotlinTarget import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsSubTargetDsl import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsTargetDsl +import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinTargetWithNodeJsDsl import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinWasmJsTargetDsl -internal val DEFAULT_COMMON_JS_CONFIGURATION: KotlinTargetContainer.() -> Unit = +internal val DEFAULT_COMMON_JS_CONFIGURATION: KotlinTargetContainer.() -> Unit = { target { - defaults() + if (this is KotlinJsTargetDsl) { + defaults() + } else if (this is KotlinTargetWithNodeJsDsl) { + nodejs { + testTimeout(seconds = TEST_TIMEOUT) + } + } } } public fun KotlinJsTargetDsl.defaults() { + // set up browser & nodejs environment + test timeouts testTimeout() + // Apply Binaryen optimizer to the WASM target if (this is KotlinWasmJsTargetDsl) { applyBinaryen() } @@ -28,6 +37,11 @@ public fun KotlinJsTargetDsl.defaults() { } } + try { + useEsModules() + } catch (_: Error) { + } + // Generate TypeScript declaration files // https://kotlinlang.org/docs/js-ir-compiler.html#preview-generation-of-typescript-declaration-files-d-ts binaries.executable() @@ -50,11 +64,9 @@ public fun KotlinJsTargetDsl.testTimeout(seconds: Int = TEST_TIMEOUT) { public fun KotlinJsSubTargetDsl.testTimeout(seconds: Int = TEST_TIMEOUT) { require(seconds > 0) { "Timeout seconds must be greater than 0." } - testTask( - Action { - useMocha { timeout = "${seconds}s" } - }, - ) + testTask { + useMocha { timeout = "${seconds}s" } + } } /** diff --git a/fluxo-kmp-conf/src/main/kotlin/fluxo/conf/dsl/container/target/WasmTarget.kt b/fluxo-kmp-conf/src/main/kotlin/fluxo/conf/dsl/container/target/WasmTarget.kt index b4a9c9e2..d8d0fb3e 100644 --- a/fluxo-kmp-conf/src/main/kotlin/fluxo/conf/dsl/container/target/WasmTarget.kt +++ b/fluxo-kmp-conf/src/main/kotlin/fluxo/conf/dsl/container/target/WasmTarget.kt @@ -1,8 +1,7 @@ package fluxo.conf.dsl.container.target -import DEFAULT_COMMON_JS_CONFIGURATION +import DEFAULT_COMMON_JS_CONFIGURATION as DEFAULT_CONF import fluxo.conf.dsl.container.KotlinTargetContainer -import fluxo.conf.impl.EMPTY_FUN import org.jetbrains.kotlin.gradle.dsl.KotlinTargetContainerWithWasmPresetFunctions import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinWasmJsTargetDsl @@ -23,7 +22,7 @@ public interface WasmTarget : KotlinTargetContainer @Suppress("NEWER_VERSION_IN_SINCE_KOTLIN") public fun wasmJs( targetName: String = "wasmJs", - action: WasmTarget.() -> Unit = DEFAULT_COMMON_JS_CONFIGURATION, + action: WasmTarget.() -> Unit = DEFAULT_CONF, ) /** @@ -35,7 +34,7 @@ public interface WasmTarget : KotlinTargetContainer @Suppress("NEWER_VERSION_IN_SINCE_KOTLIN") public fun wasmWasi( targetName: String = "wasmWasi", - action: WasmTarget.() -> Unit = EMPTY_FUN, + action: WasmTarget.() -> Unit = DEFAULT_CONF, ) } } diff --git a/fluxo-kmp-conf/src/main/kotlin/fluxo/conf/impl/kotlin/SetupKotlin.kt b/fluxo-kmp-conf/src/main/kotlin/fluxo/conf/impl/kotlin/SetupKotlin.kt index 35e96b4c..a59c2701 100644 --- a/fluxo-kmp-conf/src/main/kotlin/fluxo/conf/impl/kotlin/SetupKotlin.kt +++ b/fluxo-kmp-conf/src/main/kotlin/fluxo/conf/impl/kotlin/SetupKotlin.kt @@ -150,31 +150,36 @@ internal fun configureKotlinMultiplatform( } val project = configuration.project - configuration.context.loadAndApplyPluginIfNotApplied(id = KMP_PLUGIN_ID, project = project) + val context = configuration.context + context.loadAndApplyPluginIfNotApplied(id = KMP_PLUGIN_ID, project = project) // Add all plugins first, for configuring in next steps. val pluginManager = project.pluginManager val containerList = containers.toMutableList() containerList.iterator().let { iter -> for (container in iter) { - (container as? ContainerImpl)?.let { c -> - try { - c.applyPluginsWith(pluginManager) - } catch (e: Throwable) { - iter.remove() - - var msg = e.toString() - msg = when { - // Special case for Android plugin. - @Suppress("InstanceOfCheckForException") - e is UnknownPluginException && "com.android." in msg -> - ANDROID_PLUGIN_NOT_IN_CLASSPATH_ERROR - - else -> - "Couldn't apply ${c.name} container due to: $msg" + val c = container as? ContainerImpl ?: continue + try { + c.applyPluginsWith(pluginManager) + } catch (e: Throwable) { + iter.remove() + + var logException = true + var msg = e.toString() + msg = when { + // Special case for Android plugin. + @Suppress("InstanceOfCheckForException") + e is UnknownPluginException && "com.android." in msg -> { + logException = context.isMaxDebug + ANDROID_PLUGIN_NOT_IN_CLASSPATH_ERROR } - project.logger.e(msg, e) + + else -> + "Couldn't apply ${c.name} container due to: $msg" } + + val ex = if (logException) e else null + project.logger.e(msg, ex) } } } diff --git a/fluxo-kmp-conf/src/main/kotlin/fluxo/conf/impl/kotlin/SetupKotlinDependencies.kt b/fluxo-kmp-conf/src/main/kotlin/fluxo/conf/impl/kotlin/SetupKotlinDependencies.kt index ae81f2a8..36eda195 100644 --- a/fluxo-kmp-conf/src/main/kotlin/fluxo/conf/impl/kotlin/SetupKotlinDependencies.kt +++ b/fluxo-kmp-conf/src/main/kotlin/fluxo/conf/impl/kotlin/SetupKotlinDependencies.kt @@ -170,7 +170,8 @@ internal fun KotlinMultiplatformExtension.setupMultiplatformDependencies( try { constraints.implementation(it) } catch (e: Throwable) { - project.logger.w("Failed to add constraint for $it: $e", e) + val ex = if (context.isMaxDebug) e else null + project.logger.w("Failed to add constraint for $it: $e", ex) } }