Skip to content
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
31 changes: 17 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -657,40 +657,43 @@ To prevent this error, you should build FFI file with a custom Gradle Task.
`{rootProject}/build.gradle.kts` ([sample build.gradle.kts is here](build.gradle.kts))

```kotlin
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsEnvSpec
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
import org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinNpmInstallTask

...
plugins.withType<NodeJsRootPlugin> {
extensions.configure<NodeJsRootExtension> {
extensions.configure<NodeJsEnvSpec> {
// Choose any version you want to use from https://nodejs.org/en/download/releases/
nodeVersion = "20.18.2"
version = "22.0.0"
val installBetterSqlite3 by tasks.registering(Exec::class) {
val nodeExtension = this@configure
val nodeEnv = nodeExtension.requireConfigured()
val node = nodeEnv.nodeExecutable.replace(File.separator, "/")
val nodeDir = nodeEnv.nodeDir.path.replace(File.separator, "/")
val nodeBinDir = nodeEnv.nodeBinDir.path.replace(File.separator, "/")
val envSpec = this@configure
val node = envSpec.executable.get().replace(File.separator, "/")
val nodeDir = if (OperatingSystem.current().isWindows) {
File(node).parent.replace(File.separator, "/")
} else {
File(node).parentFile.parent
}
val nodeBinDir = File(node).parent.replace(File.separator, "/")
val npmCli = if (OperatingSystem.current().isWindows) {
"$nodeDir/node_modules/npm/bin/npm-cli.js"
} else {
"$nodeDir/lib/node_modules/npm/bin/npm-cli.js"
}
val npm = "\"$node\" \"$npmCli\""
val betterSqlite3 = buildDir.resolve("js/node_modules/better-sqlite3")
val betterSqlite3 = layout.buildDirectory.dir("js/node_modules/better-sqlite3")
dependsOn(tasks.withType<KotlinNpmInstallTask>())
inputs.files(betterSqlite3.resolve("package.json"))
inputs.property("node-version", nodeVersion)
outputs.files(betterSqlite3.resolve("build/Release/better_sqlite3.node"))
inputs.files(betterSqlite3.get().file("package.json"))
inputs.property("node-version", envSpec.version)
outputs.files(betterSqlite3.get().file("build/Release/better_sqlite3.node"))
outputs.cacheIf { true }
workingDir = betterSqlite3
workingDir = betterSqlite3.get().asFile
commandLine = if (OperatingSystem.current().isWindows) {
listOf(
"sh",
"-c",
// use pwd command to convert C:/... -> /c/...
"PATH=\$(cd $nodeBinDir;pwd):\$PATH $npm run install --verbose"
"PATH=\$(cd ${nodeBinDir};pwd):\$PATH $npm run install --verbose"
)
} else {
listOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,9 @@ fun Project.configureMultiplatformLibrary() {
pluginManager.withPlugin("com.android.library") {
// Android AAR
androidTarget {
publishAllLibraryVariants()
publishLibraryVariants("release", "debug")
}
}
targetHierarchy.default()
// Java jar
jvm()
// iOS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ class MultiplatformLibraryPlugin: Plugin<Project> {
with(target) {
with(pluginManager) {
apply("org.jetbrains.kotlin.multiplatform")
apply(libs.pluginId("kotest-multiplatform"))
}
configureMultiplatformLibrary()
}
Expand Down
36 changes: 19 additions & 17 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import com.android.build.gradle.BaseExtension
import org.gradle.internal.os.OperatingSystem
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsEnvSpec
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
import org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinNpmInstallTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
alias(libs.plugins.kotlin.multiplatform) apply false
alias(libs.plugins.kotlin.jvm) apply false
alias(libs.plugins.android.application) apply false
alias(libs.plugins.android.library) apply false
alias(libs.plugins.kotlinx.serialization) apply false
alias(libs.plugins.kotest.multiplatform) apply false
alias(libs.plugins.ksp) apply false
alias(libs.plugins.kotest) apply false
alias(libs.plugins.buildlogic.multiplatform.library) apply false
alias(libs.plugins.buildlogic.android.application) apply false
alias(libs.plugins.buildlogic.android.library) apply false
Expand Down Expand Up @@ -128,33 +127,36 @@ subprojects {
}

plugins.withType<NodeJsRootPlugin> {
extensions.configure<NodeJsRootExtension> {
nodeVersion = "20.18.2"
extensions.configure<NodeJsEnvSpec> {
version = "22.0.0"
val installBetterSqlite3 by tasks.registering(Exec::class) {
val nodeExtension = this@configure
val nodeEnv = nodeExtension.requireConfigured()
val node = nodeEnv.nodeExecutable.replace(File.separator, "/")
val nodeDir = nodeEnv.dir.path.replace(File.separator, "/")
val nodeBinDir = nodeEnv.nodeBinDir.path.replace(File.separator, "/")
val envSpec = this@configure
val node = envSpec.executable.get().replace(File.separator, "/")
val nodeDir = if (OperatingSystem.current().isWindows) {
File(node).parent.replace(File.separator, "/")
} else {
File(node).parentFile.parent
}
val nodeBinDir = File(node).parent.replace(File.separator, "/")
val npmCli = if (OperatingSystem.current().isWindows) {
"$nodeDir/node_modules/npm/bin/npm-cli.js"
} else {
"$nodeDir/lib/node_modules/npm/bin/npm-cli.js"
}
val npm = "\"$node\" \"$npmCli\""
val betterSqlite3 = buildDir.resolve("js/node_modules/better-sqlite3")
val betterSqlite3 = layout.buildDirectory.dir("js/node_modules/better-sqlite3")
dependsOn(tasks.withType<KotlinNpmInstallTask>())
inputs.files(betterSqlite3.resolve("package.json"))
inputs.property("node-version", nodeVersion)
outputs.files(betterSqlite3.resolve("build/Release/better_sqlite3.node"))
inputs.files(betterSqlite3.get().file("package.json"))
inputs.property("node-version", envSpec.version)
outputs.files(betterSqlite3.get().file("build/Release/better_sqlite3.node"))
outputs.cacheIf { true }
workingDir = betterSqlite3
workingDir = betterSqlite3.get().asFile
commandLine = if (OperatingSystem.current().isWindows) {
listOf(
"sh",
"-c",
// pwd で C:/... -> /c/... 変換
"PATH=\$(cd $nodeBinDir;pwd):\$PATH $npm run install --verbose"
"PATH=\$(cd ${nodeBinDir};pwd):\$PATH $npm run install --verbose"
)
} else {
listOf(
Expand Down
9 changes: 5 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[versions]
kottage = "1.8.0"
kotlin = "2.1.20"
kotlin = "2.2.0"
kotlinx-coroutines = "1.10.1"
kotest = "6.0.0.M1"
kotest = "6.0.3"
gradle-android = "8.13.0"
gradle-android-compile-sdk = "36"
gradle-android-target-sdk = "36"
gradle-android-min-sdk = "21"
gradle-android-min-sdk = "26"
sqldelight = "2.1.0"
junit5-android-test = "1.9.0"

Expand Down Expand Up @@ -63,7 +63,8 @@ compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "
kotlinx-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
android-application = { id = "com.android.application", version.ref = "gradle-android" }
android-library = { id = "com.android.library", version.ref = "gradle-android" }
kotest-multiplatform = { id = "io.kotest.multiplatform", version.ref = "kotest" }
ksp = { id = "com.google.devtools.ksp", version = "2.2.0-2.0.2" }
kotest = { id = "io.kotest", version.ref = "kotest" }
sqldelight = { id = "app.cash.sqldelight", version.ref = "sqldelight" }
buildlogic-android-application = { id = "build-logic.android.application" }
buildlogic-android-library = { id = "build-logic.android.library" }
Expand Down
13 changes: 4 additions & 9 deletions kotlin-js-store/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -532,10 +532,10 @@ batch@0.6.1:
resolved "https://registry.yarnpkg.com/batch/-/batch-0.6.1.tgz#dc34314f4e679318093fc760272525f94bf25c16"
integrity sha512-x+VAiMRL6UPkx+kudNvxTl6hB2XNNCG2r+7wixVfIYwu/2HKRXimwQyaumLjMveWvT2Hkd/cAJw+QBMfJ/EKVw==

better-sqlite3@9.2.2:
version "9.2.2"
resolved "https://registry.yarnpkg.com/better-sqlite3/-/better-sqlite3-9.2.2.tgz#3ce1ed24f327ed8c9b0c39b825cdc2341aeb249f"
integrity sha512-qwjWB46il0lsDkeB4rSRI96HyDQr8sxeu1MkBVLMrwusq1KRu4Bpt1TMI+8zIJkDUtZ3umjAkaEjIlokZKWCQw==
better-sqlite3@12.4.1:
version "12.4.1"
resolved "https://registry.yarnpkg.com/better-sqlite3/-/better-sqlite3-12.4.1.tgz#f78df6c80530d1a0b750b538033e6199b7d30d26"
integrity sha512-3yVdyZhklTiNrtg+4WqHpJpFDd+WHTg2oM7UcR80GqL05AOV0xEJzc6qNvFYoEtE+hRp1n9MpN6/+4yhlGkDXQ==
dependencies:
bindings "^1.5.0"
prebuild-install "^7.1.1"
Expand Down Expand Up @@ -2796,11 +2796,6 @@ type-is@~1.6.18:
media-typer "0.3.0"
mime-types "~2.1.24"

typescript@5.5.4:
version "5.5.4"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.5.4.tgz#d9852d6c82bad2d2eda4fd74a5762a8f5909e9ba"
integrity sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q==

ua-parser-js@^0.7.30:
version "0.7.31"
resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.31.tgz#649a656b191dffab4f21d5e053e27ca17cbff5c6"
Expand Down
5 changes: 4 additions & 1 deletion kottage/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ plugins {
alias(libs.plugins.kotlinx.serialization)
alias(libs.plugins.dokka)
alias(libs.plugins.android.junit5)
alias(libs.plugins.ksp)
alias(libs.plugins.kotest)
}

android {
Expand Down Expand Up @@ -81,6 +83,7 @@ kotlin {
linkerOpts("-lrpcrt4", "-LC:/msys64/mingw64/lib", "-lsqlite3")
}
}
applyDefaultHierarchyTemplate()
sourceSets {
commonMain {
dependencies {
Expand Down Expand Up @@ -133,7 +136,7 @@ kotlin {
implementation(devNpm("karma-safarinative-launcher", "1.1.0"))
}
}
val nativeMain by getting {
nativeMain {
dependsOn(sqliteMain)
}
}
Expand Down
2 changes: 2 additions & 0 deletions kottage/core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ plugins {
alias(libs.plugins.buildlogic.multiplatform.library)
alias(libs.plugins.buildlogic.android.library)
alias(libs.plugins.kotlinx.serialization)
alias(libs.plugins.ksp)
alias(libs.plugins.kotest)
}

android {
Expand Down
2 changes: 2 additions & 0 deletions kottage/core/test/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
plugins {
alias(libs.plugins.buildlogic.multiplatform.library)
alias(libs.plugins.ksp)
alias(libs.plugins.kotest)
}

kotlin {
Expand Down
3 changes: 2 additions & 1 deletion kottage/data/indexeddb/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
alias(libs.plugins.kotlin.multiplatform)
alias(libs.plugins.kotest.multiplatform)
alias(libs.plugins.ksp)
alias(libs.plugins.kotest)
}

kotlin {
Expand Down
9 changes: 6 additions & 3 deletions kottage/data/sqlite/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ plugins {
alias(libs.plugins.buildlogic.multiplatform.library)
alias(libs.plugins.buildlogic.android.library)
alias(libs.plugins.sqldelight)
alias(libs.plugins.ksp)
alias(libs.plugins.kotest)
}

sqldelight {
Expand All @@ -29,6 +31,7 @@ kotlin {
linkerOpts("-LC:/msys64/mingw64/lib", "-lsqlite3")
}
}
applyDefaultHierarchyTemplate()
sourceSets {
commonMain {
dependencies {
Expand All @@ -51,15 +54,15 @@ kotlin {
implementation(libs.sqldelight.driver.jvm)
}
}
val nativeMain by getting {
nativeMain {
dependencies {
implementation(libs.sqldelight.driver.native)
}
}
val jsMain by getting {
dependencies {
implementation(npm("better-sqlite3", "9.2.2"))
//implementation(npm("@types/better-sqlite3", "9.2.2", generateExternals = true))
implementation(npm("better-sqlite3", "12.4.1"))
//implementation(npm("@types/better-sqlite3", "12.4.1", generateExternals = true))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package io.github.irgaly.kottage
import androidx.test.platform.app.InstrumentationRegistry
import io.github.irgaly.kottage.platform.contextOf
import io.github.irgaly.kottage.test.KottageSpec
import io.kotest.common.KotestInternal
import io.kotest.core.spec.Spec
import io.kotest.core.test.TestResult
import io.kotest.engine.TestEngineLauncher
import io.kotest.engine.listener.CollectingTestEngineListener
import io.kotest.engine.test.TestResult
import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test
Expand Down Expand Up @@ -46,23 +47,24 @@ class AndroidTest {
executeTest(KottageTest::class)
}

@OptIn(KotestInternal::class)
private fun<T: Spec> executeTest(targetClass: KClass<T>) {
val listener = CollectingTestEngineListener()
TestEngineLauncher(listener).withClasses(targetClass).launch()
TestEngineLauncher()
.withListener(listener)
.withClasses(targetClass).launch()
listener.tests.map { entry ->
{
val testCase = entry.key
val descriptor = testCase.descriptor.chain().joinToString(" > ") {
it.id.value
}
val descriptor = testCase.descriptor.path().value
val cause = when (val value = entry.value) {
is TestResult.Error -> value.cause
is TestResult.Failure -> value.cause
else -> null
}
assertFalse(entry.value.isErrorOrFailure) {
"""$descriptor
|${cause?.stackTraceToString()}""".trimMargin()
|${cause?.stackTraceToString()}""".trimMargin()
}
}
}.let {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.irgaly.kottage
package io.kotest.provided

import io.kotest.core.config.AbstractProjectConfig
import kotlin.time.Duration
Expand All @@ -9,7 +9,7 @@ import kotlin.time.Duration.Companion.seconds
* Kotest Config
*/
@Suppress("unused")
object ProjectConfig: AbstractProjectConfig() {
class ProjectConfig : AbstractProjectConfig() {
override val timeout: Duration = 10.minutes
override val invocationTimeout: Long = 30.seconds.inWholeMilliseconds
}
override val invocationTimeout: Duration = 30.seconds
}
2 changes: 1 addition & 1 deletion renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
{
"groupName": "Kotlin, KSP",
"matchPackageNames": [
"com.google.devtools.ksp",
"com.google.devtools.ksp:com.google.devtools.ksp.gradle.plugin",
"org.jetbrains.kotlin:*",
"org.jetbrains.kotlin.*"
],
Expand Down
2 changes: 1 addition & 1 deletion sample/android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ android {
defaultConfig {
applicationId = "io.github.irgaly.kottage.sample"
versionName = libs.versions.kottage.get()
minSdk = 21
minSdk = 26
}
}

Expand Down
Loading