Skip to content

Commit e1770b3

Browse files
authored
Support wasm target (#178)
1 parent f304cad commit e1770b3

File tree

7 files changed

+48
-11
lines changed

7 files changed

+48
-11
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ from [kotlinx.serialization-json](https://github.com/Kotlin/kotlinx.serializatio
2525
|-------------------|
2626
| jvm |
2727
| js |
28+
| wasmJs |
2829
| macosX64 |
2930
| macosArm64 |
3031
| iosArm64 |

json-schema-validator/build.gradle.kts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
@file:OptIn(ExperimentalWasmDsl::class)
2+
13
import io.gitlab.arturbosch.detekt.Detekt
24
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
35
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
46
import org.jetbrains.kotlin.gradle.plugin.KotlinTargetWithTests
7+
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
58
import org.jlleitschuh.gradle.ktlint.reporter.ReporterType
69
import java.util.Locale
710

@@ -145,6 +148,13 @@ kotlin {
145148
generateTypeScriptDefinitions()
146149
nodejs()
147150
}
151+
wasmJs {
152+
// The wasmJsBrowserTest prints all executed tests as one unformatted string
153+
// Have not found a way to suppress printing all this into console
154+
browser()
155+
nodejs()
156+
}
157+
148158
applyDefaultHierarchyTemplate()
149159

150160
val macOsTargets =
@@ -168,7 +178,7 @@ kotlin {
168178
)
169179

170180
sourceSets {
171-
commonMain {
181+
val commonMain by getting {
172182
kotlin.srcDirs(generatedSourceDirectory)
173183

174184
dependencies {
@@ -182,11 +192,31 @@ kotlin {
182192
) {
183193
because("simplifies work with unicode codepoints")
184194
}
195+
}
196+
}
197+
198+
val wasmJsMain by getting
199+
200+
val nonWasmJsMain by creating {
201+
dependsOn(commonMain)
202+
203+
dependencies {
185204
implementation(libs.normalize.get().toString()) {
186205
because("provides normalization required by IDN-hostname format")
187206
}
188207
}
189208
}
209+
210+
val jvmMain by getting {
211+
dependsOn(nonWasmJsMain)
212+
}
213+
val jsMain by getting {
214+
dependsOn(nonWasmJsMain)
215+
}
216+
val nativeMain by getting {
217+
dependsOn(nonWasmJsMain)
218+
}
219+
190220
commonTest {
191221
dependencies {
192222
implementation(libs.kotest.assertions.core)
@@ -253,6 +283,7 @@ kotlin {
253283
dependsOnTargetTests(linuxTargets)
254284
dependsOn(tasks.getByName("jvmTest"))
255285
dependsOn(tasks.getByName("jsTest"))
286+
dependsOn(tasks.getByName("wasmJsTest"))
256287
}
257288
}
258289
}

json-schema-validator/src/commonMain/kotlin/io/github/optimumcode/json/schema/internal/formats/IdnHostnameFormatValidator.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import io.github.optimumcode.json.schema.FormatValidator
77
import io.github.optimumcode.json.schema.internal.formats.IdnHostnameFormatValidator.BidiLabelType.LTR
88
import io.github.optimumcode.json.schema.internal.formats.IdnHostnameFormatValidator.BidiLabelType.NONE
99
import io.github.optimumcode.json.schema.internal.formats.IdnHostnameFormatValidator.BidiLabelType.RTL
10-
import io.github.optimumcode.json.schema.internal.hostname.Normalizer
1110
import io.github.optimumcode.json.schema.internal.hostname.Punycode
11+
import io.github.optimumcode.json.schema.internal.hostname.isNormalized
1212
import io.github.optimumcode.json.schema.internal.unicode.CharacterCategory
1313
import io.github.optimumcode.json.schema.internal.unicode.CharacterCategory.ENCLOSING_MARK
1414
import io.github.optimumcode.json.schema.internal.unicode.CharacterCategory.NONSPACING_MARK
@@ -108,7 +108,7 @@ internal object IdnHostnameFormatValidator : AbstractStringFormatValidator() {
108108
label
109109
}
110110

111-
if (!Normalizer.isNormalized(unicode)) {
111+
if (!isNormalized(unicode)) {
112112
return false
113113
}
114114

Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
11
package io.github.optimumcode.json.schema.internal.hostname
22

3-
import doist.x.normalize.Form
4-
import doist.x.normalize.normalize
5-
6-
internal object Normalizer {
7-
fun isNormalized(label: String): Boolean {
8-
return label.normalize(Form.NFC) == label
9-
}
10-
}
3+
internal expect fun isNormalized(label: String): Boolean
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package io.github.optimumcode.json.schema.internal.hostname
2+
3+
import doist.x.normalize.Form
4+
import doist.x.normalize.normalize
5+
6+
internal actual fun isNormalized(label: String): Boolean {
7+
return label.normalize(Form.NFC) == label
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package io.github.optimumcode.json.schema.internal.hostname
2+
3+
internal actual fun isNormalized(label: String): Boolean = js("label.normalize('NFC') === label")

test-suites/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ kotlin {
2727
js(IR) {
2828
nodejs()
2929
}
30+
// wasmJs target is not added because the okio does not provide a dependency to use FileSystem API in wasmJs target
3031
applyDefaultHierarchyTemplate()
3132

3233
val macOsTargets =

0 commit comments

Comments
 (0)