diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8f21b3e4..6462a22e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -4,8 +4,6 @@ on: push: tags: - 'v*' - branches: - - main env: PGP_SEC: ${{ secrets.PGP_SEC }} diff --git a/README.md b/README.md index 05e0678c..3ea8ca1a 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ However, to reduce the scope, ktoml now supports only the following platforms: - mingwx64 - linuxx64 - macosx64 - - js (only for ktoml-core) + - js (only for ktoml-core). Note, that `js(LEGACY)` is [not supported](https://github.com/Kotlin/kotlinx.serialization/issues/1448) Other platforms could be added later on the demand (just create a corresponding issue) or easily built by users on their machines. diff --git a/buildSrc/src/main/kotlin/com/akuleshov7/buildutils/PublishingConfiguration.kt b/buildSrc/src/main/kotlin/com/akuleshov7/buildutils/PublishingConfiguration.kt index 84880752..20fb4284 100644 --- a/buildSrc/src/main/kotlin/com/akuleshov7/buildutils/PublishingConfiguration.kt +++ b/buildSrc/src/main/kotlin/com/akuleshov7/buildutils/PublishingConfiguration.kt @@ -55,7 +55,7 @@ fun Project.configurePublishing() { // https://kotlinlang.org/docs/mpp-publish-lib.html#avoid-duplicate-publications // `configureNexusPublishing` adds sonatype publication tasks inside `afterEvaluate`. - rootProject.afterEvaluate { + afterEvaluate { val publicationsFromMainHost = listOf("jvm", "js", "linuxX64", "kotlinMultiplatform", "metadata") configure { publications.matching { it.name in publicationsFromMainHost }.all { diff --git a/ktoml-core/build.gradle.kts b/ktoml-core/build.gradle.kts index 8bfa7afe..e3853b22 100644 --- a/ktoml-core/build.gradle.kts +++ b/ktoml-core/build.gradle.kts @@ -1,4 +1,5 @@ import com.akuleshov7.buildutils.configurePublishing +import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform.getCurrentOperatingSystem import org.jetbrains.kotlin.gradle.tasks.KotlinCompile import org.jetbrains.kotlin.gradle.targets.jvm.tasks.KotlinJvmTest @@ -9,6 +10,13 @@ plugins { kotlin { explicitApi() + + js(IR) { + browser() + nodejs() + } + + // building jvm task only on windows jvm { compilations.all { kotlinOptions { @@ -17,11 +25,14 @@ kotlin { } } - js(LEGACY) + val os = getCurrentOperatingSystem() - linuxX64() - mingwX64() - macosX64() + when { + os.isWindows -> mingwX64() + os.isLinux -> linuxX64() + os.isMacOsX -> macosX64() + else -> throw GradleException("Unknown operating system $os") + } sourceSets { all { @@ -42,6 +53,12 @@ kotlin { } } + val jsTest by getting { + dependencies { + implementation(kotlin("test-js")) + } + } + val jvmTest by getting { dependsOn(commonTest) dependencies { @@ -55,6 +72,8 @@ kotlin { } } +configurePublishing() + tasks.withType { useJUnitPlatform() } diff --git a/ktoml-core/src/commonMain/kotlin/com/akuleshov7/ktoml/parsers/TomlParser.kt b/ktoml-core/src/commonMain/kotlin/com/akuleshov7/ktoml/parsers/TomlParser.kt index f4f44c02..8a11f8fa 100644 --- a/ktoml-core/src/commonMain/kotlin/com/akuleshov7/ktoml/parsers/TomlParser.kt +++ b/ktoml-core/src/commonMain/kotlin/com/akuleshov7/ktoml/parsers/TomlParser.kt @@ -106,7 +106,10 @@ public inline class TomlParser(private val ktomlConf: KtomlConf) { } } - private fun String.isTableNode() = "\\[(.*?)]".toRegex().matches(this.trim()) + private fun String.isTableNode(): Boolean { + val trimmed = this.trim() + return trimmed.startsWith("[") && trimmed.endsWith("]") + } private fun String.isComment() = this.trim().startsWith("#") diff --git a/ktoml-core/src/commonMain/kotlin/com/akuleshov7/ktoml/parsers/node/TomlNode.kt b/ktoml-core/src/commonMain/kotlin/com/akuleshov7/ktoml/parsers/node/TomlNode.kt index abd81fcf..1742e6e5 100644 --- a/ktoml-core/src/commonMain/kotlin/com/akuleshov7/ktoml/parsers/node/TomlNode.kt +++ b/ktoml-core/src/commonMain/kotlin/com/akuleshov7/ktoml/parsers/node/TomlNode.kt @@ -8,6 +8,7 @@ import com.akuleshov7.ktoml.KtomlConf import com.akuleshov7.ktoml.exceptions.InternalAstException import com.akuleshov7.ktoml.exceptions.TomlParsingException import com.akuleshov7.ktoml.parsers.splitKeyToTokens +import com.akuleshov7.ktoml.parsers.trimBrackets import com.akuleshov7.ktoml.parsers.trimQuotes /** @@ -251,13 +252,7 @@ public class TomlTable( init { // getting the content inside brackets ([a.b] -> a.b) - val sectionFromContent = "\\[(.*?)]" - .toRegex() - .find(content) - ?.groupValues - ?.get(1) - ?.trim() - ?: throw Exception() + val sectionFromContent = content.trim().trimBrackets().trim() if (sectionFromContent.isBlank()) { throw TomlParsingException("Incorrect blank table name: $content", lineNo) diff --git a/ktoml-core/src/commonTest/kotlin/decoder/GeneralDecoderTest.kt b/ktoml-core/src/commonTest/kotlin/decoder/GeneralDecoderTest.kt index 6739dee9..4f5db8d8 100644 --- a/ktoml-core/src/commonTest/kotlin/decoder/GeneralDecoderTest.kt +++ b/ktoml-core/src/commonTest/kotlin/decoder/GeneralDecoderTest.kt @@ -355,13 +355,13 @@ class GeneralDecoderTest { data class MyTest(val table: Table) @Serializable - data class Table(val `1`: Inner, val `2`: Inner) + data class Table(val in1: Inner, val in2: Inner) @Serializable data class Inner( val a: Long, - val `1`: InnerInner, - val `2`: InnerInner + val in1: InnerInner, + val in2: InnerInner ) @Serializable @@ -370,25 +370,25 @@ class GeneralDecoderTest { @Test fun severalTablesOnTheSameLevel() { val test = """|[table] - |[table.1] + |[table.in1] | a = 1 - | [table.1.1] + | [table.in1.in1] | a = 1 - | [table.1.2] + | [table.in1.in2] | a = 1 - |[table.2] + |[table.in2] | a = 1 - | [table.2.1] + | [table.in2.in1] | a = 1 - | [table.2.2] + | [table.in2.in2] | a = 1 """.trimMargin() assertEquals( MyTest( table = Table( - `1` = Inner(a = 1, `1` = InnerInner(a = 1), `2` = InnerInner(a = 1)), - `2` = Inner(a = 1, `1` = InnerInner(a = 1), `2` = InnerInner(a = 1)) + in1 = Inner(a = 1, in1 = InnerInner(a = 1), in2 = InnerInner(a = 1)), + in2 = Inner(a = 1, in1 = InnerInner(a = 1), in2 = InnerInner(a = 1)) ) ), Toml.decodeFromString(test) ) diff --git a/ktoml-file/build.gradle.kts b/ktoml-file/build.gradle.kts index 26ade40e..8f705fb4 100644 --- a/ktoml-file/build.gradle.kts +++ b/ktoml-file/build.gradle.kts @@ -1,3 +1,4 @@ +import com.akuleshov7.buildutils.configurePublishing import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform.getCurrentOperatingSystem import org.jetbrains.kotlin.gradle.targets.jvm.tasks.KotlinJvmTest @@ -78,6 +79,8 @@ kotlin { } } +configurePublishing() + tasks.withType { useJUnitPlatform() }