From 5679862dc69d28e31b37e86ecb1e9b1306bd5337 Mon Sep 17 00:00:00 2001 From: Mike Penz Date: Mon, 5 Aug 2024 13:27:04 +0200 Subject: [PATCH 01/10] - update build setup to also include the `wasm` target - FIX https://github.com/OptimumCode/json-schema-validator/issues/177 - adjust module hierarchy to not split wasm from other source sets as some dependency currently does not offer wasm support --- json-schema-validator/build.gradle.kts | 27 ++++++++++++++++++- .../formats/IdnHostnameFormatValidator.kt | 4 +-- .../schema/internal/hostname/Normalizer.kt | 9 +------ .../internal/hostname/Normalizer.nonWasmJs.kt | 8 ++++++ .../internal/hostname/Normalizer.wasmJs.kt | 6 +++++ test-suites/build.gradle.kts | 3 +++ 6 files changed, 46 insertions(+), 11 deletions(-) create mode 100644 json-schema-validator/src/nonWasmJsMain/kotlin/io/github/optimumcode/json/schema/internal/hostname/Normalizer.nonWasmJs.kt create mode 100644 json-schema-validator/src/wasmJsMain/kotlin/io/github/optimumcode/json/schema/internal/hostname/Normalizer.wasmJs.kt diff --git a/json-schema-validator/build.gradle.kts b/json-schema-validator/build.gradle.kts index c1ed4fea..3545b0a8 100644 --- a/json-schema-validator/build.gradle.kts +++ b/json-schema-validator/build.gradle.kts @@ -145,6 +145,9 @@ kotlin { generateTypeScriptDefinitions() nodejs() } + wasmJs { + nodejs() + } applyDefaultHierarchyTemplate() val macOsTargets = @@ -168,7 +171,7 @@ kotlin { ) sourceSets { - commonMain { + val commonMain by getting { kotlin.srcDirs(generatedSourceDirectory) dependencies { @@ -182,11 +185,33 @@ kotlin { ) { because("simplifies work with unicode codepoints") } + } + } + + val wasmJsMain by getting { + + } + + val nonWasmJsMain by creating { + dependsOn(commonMain) + + dependencies { implementation(libs.normalize.get().toString()) { because("provides normalization required by IDN-hostname format") } } } + + val jvmMain by getting { + dependsOn(nonWasmJsMain) + } + val jsMain by getting { + dependsOn(nonWasmJsMain) + } + val nativeMain by getting { + dependsOn(nonWasmJsMain) + } + commonTest { dependencies { implementation(libs.kotest.assertions.core) diff --git a/json-schema-validator/src/commonMain/kotlin/io/github/optimumcode/json/schema/internal/formats/IdnHostnameFormatValidator.kt b/json-schema-validator/src/commonMain/kotlin/io/github/optimumcode/json/schema/internal/formats/IdnHostnameFormatValidator.kt index 898dcfca..9a881b65 100644 --- a/json-schema-validator/src/commonMain/kotlin/io/github/optimumcode/json/schema/internal/formats/IdnHostnameFormatValidator.kt +++ b/json-schema-validator/src/commonMain/kotlin/io/github/optimumcode/json/schema/internal/formats/IdnHostnameFormatValidator.kt @@ -7,8 +7,8 @@ import io.github.optimumcode.json.schema.FormatValidator import io.github.optimumcode.json.schema.internal.formats.IdnHostnameFormatValidator.BidiLabelType.LTR import io.github.optimumcode.json.schema.internal.formats.IdnHostnameFormatValidator.BidiLabelType.NONE import io.github.optimumcode.json.schema.internal.formats.IdnHostnameFormatValidator.BidiLabelType.RTL -import io.github.optimumcode.json.schema.internal.hostname.Normalizer import io.github.optimumcode.json.schema.internal.hostname.Punycode +import io.github.optimumcode.json.schema.internal.hostname.isNormalized import io.github.optimumcode.json.schema.internal.unicode.CharacterCategory import io.github.optimumcode.json.schema.internal.unicode.CharacterCategory.ENCLOSING_MARK import io.github.optimumcode.json.schema.internal.unicode.CharacterCategory.NONSPACING_MARK @@ -108,7 +108,7 @@ internal object IdnHostnameFormatValidator : AbstractStringFormatValidator() { label } - if (!Normalizer.isNormalized(unicode)) { + if (!isNormalized(unicode)) { return false } diff --git a/json-schema-validator/src/commonMain/kotlin/io/github/optimumcode/json/schema/internal/hostname/Normalizer.kt b/json-schema-validator/src/commonMain/kotlin/io/github/optimumcode/json/schema/internal/hostname/Normalizer.kt index 1f78b1a7..01b5cb9c 100644 --- a/json-schema-validator/src/commonMain/kotlin/io/github/optimumcode/json/schema/internal/hostname/Normalizer.kt +++ b/json-schema-validator/src/commonMain/kotlin/io/github/optimumcode/json/schema/internal/hostname/Normalizer.kt @@ -1,10 +1,3 @@ package io.github.optimumcode.json.schema.internal.hostname -import doist.x.normalize.Form -import doist.x.normalize.normalize - -internal object Normalizer { - fun isNormalized(label: String): Boolean { - return label.normalize(Form.NFC) == label - } -} \ No newline at end of file +public expect fun isNormalized(label: String): Boolean \ No newline at end of file diff --git a/json-schema-validator/src/nonWasmJsMain/kotlin/io/github/optimumcode/json/schema/internal/hostname/Normalizer.nonWasmJs.kt b/json-schema-validator/src/nonWasmJsMain/kotlin/io/github/optimumcode/json/schema/internal/hostname/Normalizer.nonWasmJs.kt new file mode 100644 index 00000000..75201a13 --- /dev/null +++ b/json-schema-validator/src/nonWasmJsMain/kotlin/io/github/optimumcode/json/schema/internal/hostname/Normalizer.nonWasmJs.kt @@ -0,0 +1,8 @@ +package io.github.optimumcode.json.schema.internal.hostname + +import doist.x.normalize.Form +import doist.x.normalize.normalize + +public actual fun isNormalized(label: String): Boolean { + return label.normalize(Form.NFC) == label +} \ No newline at end of file diff --git a/json-schema-validator/src/wasmJsMain/kotlin/io/github/optimumcode/json/schema/internal/hostname/Normalizer.wasmJs.kt b/json-schema-validator/src/wasmJsMain/kotlin/io/github/optimumcode/json/schema/internal/hostname/Normalizer.wasmJs.kt new file mode 100644 index 00000000..c52964be --- /dev/null +++ b/json-schema-validator/src/wasmJsMain/kotlin/io/github/optimumcode/json/schema/internal/hostname/Normalizer.wasmJs.kt @@ -0,0 +1,6 @@ +package io.github.optimumcode.json.schema.internal.hostname + +public actual fun isNormalized(label: String): Boolean { + // depending library does not yet support wasm: https://github.com/OptimumCode/json-schema-validator/issues/177#issuecomment-2268482409 + return true +} \ No newline at end of file diff --git a/test-suites/build.gradle.kts b/test-suites/build.gradle.kts index 55c11e16..b1905da6 100644 --- a/test-suites/build.gradle.kts +++ b/test-suites/build.gradle.kts @@ -27,6 +27,9 @@ kotlin { js(IR) { nodejs() } + wasmJs { + nodejs() + } applyDefaultHierarchyTemplate() val macOsTargets = From a555cbbe2e72a59ed97d2323481a0e0a4e921058 Mon Sep 17 00:00:00 2001 From: Mike Penz Date: Mon, 5 Aug 2024 14:13:57 +0200 Subject: [PATCH 02/10] - update binary compatibility definition --- json-schema-validator/api/json-schema-validator.api | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/json-schema-validator/api/json-schema-validator.api b/json-schema-validator/api/json-schema-validator.api index ac63b4e5..050dde1c 100644 --- a/json-schema-validator/api/json-schema-validator.api +++ b/json-schema-validator/api/json-schema-validator.api @@ -354,3 +354,7 @@ public abstract interface class io/github/optimumcode/json/schema/extension/Exte public abstract fun getSchemaPath ()Lio/github/optimumcode/json/pointer/JsonPointer; } +public final class io/github/optimumcode/json/schema/internal/hostname/Normalizer_nonWasmJsKt { + public static final fun isNormalized (Ljava/lang/String;)Z +} + From ca75b706b544b12a783ed5f11b5c032a53dcc8e8 Mon Sep 17 00:00:00 2001 From: Mike Penz Date: Mon, 5 Aug 2024 14:31:15 +0200 Subject: [PATCH 03/10] - fix check style error --- json-schema-validator/build.gradle.kts | 1 - 1 file changed, 1 deletion(-) diff --git a/json-schema-validator/build.gradle.kts b/json-schema-validator/build.gradle.kts index 3545b0a8..ea3bb88c 100644 --- a/json-schema-validator/build.gradle.kts +++ b/json-schema-validator/build.gradle.kts @@ -189,7 +189,6 @@ kotlin { } val wasmJsMain by getting { - } val nonWasmJsMain by creating { From e7961d6678bd947aac020987c06c0a12d26d0bcc Mon Sep 17 00:00:00 2001 From: Mike Penz Date: Mon, 5 Aug 2024 17:23:23 +0200 Subject: [PATCH 04/10] - mark `isNormalized` as internal API - add experimental annotation for wasm targets - add also browser() to wasm target - update *.api file --- json-schema-validator/api/json-schema-validator.api | 4 ---- json-schema-validator/build.gradle.kts | 5 +++++ .../json/schema/internal/hostname/Normalizer.kt | 2 +- .../json/schema/internal/hostname/Normalizer.nonWasmJs.kt | 2 +- .../json/schema/internal/hostname/Normalizer.wasmJs.kt | 2 +- test-suites/build.gradle.kts | 7 +++++++ 6 files changed, 15 insertions(+), 7 deletions(-) diff --git a/json-schema-validator/api/json-schema-validator.api b/json-schema-validator/api/json-schema-validator.api index 050dde1c..ac63b4e5 100644 --- a/json-schema-validator/api/json-schema-validator.api +++ b/json-schema-validator/api/json-schema-validator.api @@ -354,7 +354,3 @@ public abstract interface class io/github/optimumcode/json/schema/extension/Exte public abstract fun getSchemaPath ()Lio/github/optimumcode/json/pointer/JsonPointer; } -public final class io/github/optimumcode/json/schema/internal/hostname/Normalizer_nonWasmJsKt { - public static final fun isNormalized (Ljava/lang/String;)Z -} - diff --git a/json-schema-validator/build.gradle.kts b/json-schema-validator/build.gradle.kts index ea3bb88c..ff1eaa9a 100644 --- a/json-schema-validator/build.gradle.kts +++ b/json-schema-validator/build.gradle.kts @@ -1,7 +1,10 @@ +@file:OptIn(ExperimentalWasmDsl::class) + import io.gitlab.arturbosch.detekt.Detekt import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi import org.jetbrains.kotlin.gradle.plugin.KotlinTarget import org.jetbrains.kotlin.gradle.plugin.KotlinTargetWithTests +import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl import org.jlleitschuh.gradle.ktlint.reporter.ReporterType import java.util.Locale @@ -146,8 +149,10 @@ kotlin { nodejs() } wasmJs { + browser() nodejs() } + applyDefaultHierarchyTemplate() val macOsTargets = diff --git a/json-schema-validator/src/commonMain/kotlin/io/github/optimumcode/json/schema/internal/hostname/Normalizer.kt b/json-schema-validator/src/commonMain/kotlin/io/github/optimumcode/json/schema/internal/hostname/Normalizer.kt index 01b5cb9c..cef03df2 100644 --- a/json-schema-validator/src/commonMain/kotlin/io/github/optimumcode/json/schema/internal/hostname/Normalizer.kt +++ b/json-schema-validator/src/commonMain/kotlin/io/github/optimumcode/json/schema/internal/hostname/Normalizer.kt @@ -1,3 +1,3 @@ package io.github.optimumcode.json.schema.internal.hostname -public expect fun isNormalized(label: String): Boolean \ No newline at end of file +internal expect fun isNormalized(label: String): Boolean \ No newline at end of file diff --git a/json-schema-validator/src/nonWasmJsMain/kotlin/io/github/optimumcode/json/schema/internal/hostname/Normalizer.nonWasmJs.kt b/json-schema-validator/src/nonWasmJsMain/kotlin/io/github/optimumcode/json/schema/internal/hostname/Normalizer.nonWasmJs.kt index 75201a13..a63678dc 100644 --- a/json-schema-validator/src/nonWasmJsMain/kotlin/io/github/optimumcode/json/schema/internal/hostname/Normalizer.nonWasmJs.kt +++ b/json-schema-validator/src/nonWasmJsMain/kotlin/io/github/optimumcode/json/schema/internal/hostname/Normalizer.nonWasmJs.kt @@ -3,6 +3,6 @@ package io.github.optimumcode.json.schema.internal.hostname import doist.x.normalize.Form import doist.x.normalize.normalize -public actual fun isNormalized(label: String): Boolean { +internal actual fun isNormalized(label: String): Boolean { return label.normalize(Form.NFC) == label } \ No newline at end of file diff --git a/json-schema-validator/src/wasmJsMain/kotlin/io/github/optimumcode/json/schema/internal/hostname/Normalizer.wasmJs.kt b/json-schema-validator/src/wasmJsMain/kotlin/io/github/optimumcode/json/schema/internal/hostname/Normalizer.wasmJs.kt index c52964be..9ce3d667 100644 --- a/json-schema-validator/src/wasmJsMain/kotlin/io/github/optimumcode/json/schema/internal/hostname/Normalizer.wasmJs.kt +++ b/json-schema-validator/src/wasmJsMain/kotlin/io/github/optimumcode/json/schema/internal/hostname/Normalizer.wasmJs.kt @@ -1,6 +1,6 @@ package io.github.optimumcode.json.schema.internal.hostname -public actual fun isNormalized(label: String): Boolean { +internal actual fun isNormalized(label: String): Boolean { // depending library does not yet support wasm: https://github.com/OptimumCode/json-schema-validator/issues/177#issuecomment-2268482409 return true } \ No newline at end of file diff --git a/test-suites/build.gradle.kts b/test-suites/build.gradle.kts index b1905da6..42664c18 100644 --- a/test-suites/build.gradle.kts +++ b/test-suites/build.gradle.kts @@ -1,6 +1,9 @@ +@file:OptIn(ExperimentalWasmDsl::class) + import io.gitlab.arturbosch.detekt.Detekt import org.jetbrains.kotlin.gradle.plugin.KotlinTarget import org.jetbrains.kotlin.gradle.plugin.KotlinTargetWithTests +import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeSimulatorTest import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeTest @@ -69,6 +72,10 @@ kotlin { implementation(libs.okio.nodefilesystem) } } + wasmJsTest { + dependencies { + } + } jvmTest { dependencies { implementation(libs.kotest.runner.junit5) From 3b7e22cbc57ec7928bdf6bfb99658eabbf475af3 Mon Sep 17 00:00:00 2001 From: Oleg Smirnov Date: Mon, 5 Aug 2024 20:03:10 +0400 Subject: [PATCH 05/10] Add normalization support for wasmJs --- .../json/schema/internal/hostname/Normalizer.wasmJs.kt | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/json-schema-validator/src/wasmJsMain/kotlin/io/github/optimumcode/json/schema/internal/hostname/Normalizer.wasmJs.kt b/json-schema-validator/src/wasmJsMain/kotlin/io/github/optimumcode/json/schema/internal/hostname/Normalizer.wasmJs.kt index 9ce3d667..4a28b4f0 100644 --- a/json-schema-validator/src/wasmJsMain/kotlin/io/github/optimumcode/json/schema/internal/hostname/Normalizer.wasmJs.kt +++ b/json-schema-validator/src/wasmJsMain/kotlin/io/github/optimumcode/json/schema/internal/hostname/Normalizer.wasmJs.kt @@ -1,6 +1,3 @@ package io.github.optimumcode.json.schema.internal.hostname -internal actual fun isNormalized(label: String): Boolean { - // depending library does not yet support wasm: https://github.com/OptimumCode/json-schema-validator/issues/177#issuecomment-2268482409 - return true -} \ No newline at end of file +internal actual fun isNormalized(label: String): Boolean = js("label.normalize('NFC') === label") \ No newline at end of file From e767891cf995962aead4753c3c5cdd9f281f381c Mon Sep 17 00:00:00 2001 From: Oleg Smirnov Date: Mon, 5 Aug 2024 20:32:11 +0400 Subject: [PATCH 06/10] Execute wasm tests on linux runners --- json-schema-validator/build.gradle.kts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/json-schema-validator/build.gradle.kts b/json-schema-validator/build.gradle.kts index ff1eaa9a..2fc643b9 100644 --- a/json-schema-validator/build.gradle.kts +++ b/json-schema-validator/build.gradle.kts @@ -149,6 +149,8 @@ kotlin { nodejs() } wasmJs { + // The wasmJsBrowserTest prints all executed tests as one unformatted string + // Have not found a way to suppress printing all this into console browser() nodejs() } @@ -193,8 +195,7 @@ kotlin { } } - val wasmJsMain by getting { - } + val wasmJsMain by getting val nonWasmJsMain by creating { dependsOn(commonMain) @@ -282,6 +283,7 @@ kotlin { dependsOnTargetTests(linuxTargets) dependsOn(tasks.getByName("jvmTest")) dependsOn(tasks.getByName("jsTest")) + dependsOn(tasks.getByName("wasmJsTest")) } } } From 828d01ab3c27a0d428be0d42d3847f583afee9d3 Mon Sep 17 00:00:00 2001 From: Oleg Smirnov Date: Mon, 5 Aug 2024 20:49:12 +0400 Subject: [PATCH 07/10] Disable wasmJs in test-suites project due to lack of support in okio --- test-suites/build.gradle.kts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test-suites/build.gradle.kts b/test-suites/build.gradle.kts index 42664c18..63db51c1 100644 --- a/test-suites/build.gradle.kts +++ b/test-suites/build.gradle.kts @@ -30,9 +30,7 @@ kotlin { js(IR) { nodejs() } - wasmJs { - nodejs() - } + // wasmJs target is not added because the okio does not provide a dependency to use FileSystem API in wasmJs target applyDefaultHierarchyTemplate() val macOsTargets = From 968f067d13eb456e80768a6ba2f8cc940681a630 Mon Sep 17 00:00:00 2001 From: Oleg Smirnov Date: Mon, 5 Aug 2024 20:54:43 +0400 Subject: [PATCH 08/10] Remove remaning configuration for wasmJs from test-suites project --- test-suites/build.gradle.kts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/test-suites/build.gradle.kts b/test-suites/build.gradle.kts index 63db51c1..fe08aabf 100644 --- a/test-suites/build.gradle.kts +++ b/test-suites/build.gradle.kts @@ -70,10 +70,6 @@ kotlin { implementation(libs.okio.nodefilesystem) } } - wasmJsTest { - dependencies { - } - } jvmTest { dependencies { implementation(libs.kotest.runner.junit5) From a6d697df010439a38cddb502b982d9ffd7262aac Mon Sep 17 00:00:00 2001 From: Oleg Smirnov Date: Mon, 5 Aug 2024 20:56:55 +0400 Subject: [PATCH 09/10] Remove redundant imports in test-suites project --- test-suites/build.gradle.kts | 3 --- 1 file changed, 3 deletions(-) diff --git a/test-suites/build.gradle.kts b/test-suites/build.gradle.kts index fe08aabf..b81a624c 100644 --- a/test-suites/build.gradle.kts +++ b/test-suites/build.gradle.kts @@ -1,9 +1,6 @@ -@file:OptIn(ExperimentalWasmDsl::class) - import io.gitlab.arturbosch.detekt.Detekt import org.jetbrains.kotlin.gradle.plugin.KotlinTarget import org.jetbrains.kotlin.gradle.plugin.KotlinTargetWithTests -import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeSimulatorTest import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeTest From eb39883a770d9f00d6bfa900b66496b85b3a6ad7 Mon Sep 17 00:00:00 2001 From: Mike Penz Date: Mon, 5 Aug 2024 20:56:56 +0200 Subject: [PATCH 10/10] - introduce `wasmJs` target to the supported targets list --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 5ba6b397..322ebc42 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,7 @@ from [kotlinx.serialization-json](https://github.com/Kotlin/kotlinx.serializatio |-------------------| | jvm | | js | +| wasmJs | | macosX64 | | macosArm64 | | iosArm64 |