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 | diff --git a/json-schema-validator/build.gradle.kts b/json-schema-validator/build.gradle.kts index c1ed4fea..2fc643b9 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 @@ -145,6 +148,13 @@ kotlin { generateTypeScriptDefinitions() 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() + } + applyDefaultHierarchyTemplate() val macOsTargets = @@ -168,7 +178,7 @@ kotlin { ) sourceSets { - commonMain { + val commonMain by getting { kotlin.srcDirs(generatedSourceDirectory) dependencies { @@ -182,11 +192,31 @@ 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) @@ -253,6 +283,7 @@ kotlin { dependsOnTargetTests(linuxTargets) dependsOn(tasks.getByName("jvmTest")) dependsOn(tasks.getByName("jsTest")) + dependsOn(tasks.getByName("wasmJsTest")) } } } 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..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,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 +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 new file mode 100644 index 00000000..a63678dc --- /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 + +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 new file mode 100644 index 00000000..4a28b4f0 --- /dev/null +++ b/json-schema-validator/src/wasmJsMain/kotlin/io/github/optimumcode/json/schema/internal/hostname/Normalizer.wasmJs.kt @@ -0,0 +1,3 @@ +package io.github.optimumcode.json.schema.internal.hostname + +internal actual fun isNormalized(label: String): Boolean = js("label.normalize('NFC') === label") \ No newline at end of file diff --git a/test-suites/build.gradle.kts b/test-suites/build.gradle.kts index 55c11e16..b81a624c 100644 --- a/test-suites/build.gradle.kts +++ b/test-suites/build.gradle.kts @@ -27,6 +27,7 @@ kotlin { js(IR) { nodejs() } + // wasmJs target is not added because the okio does not provide a dependency to use FileSystem API in wasmJs target applyDefaultHierarchyTemplate() val macOsTargets =