From 509832d26d3b93548bf17ca95d8b86dc30c91375 Mon Sep 17 00:00:00 2001 From: Lazzexus Date: Mon, 12 Oct 2026 15:40:33 +0200 Subject: [PATCH] Fix kxs-ts-gen-core dependency resolution and unblocked compile bugs The version catalog pointed kxs-ts-gen-core at a JitPack coordinate (com.github.adamko-dev.kotlinx-serialization-typescript-generator) that no longer serves real artifacts there, despite JitPack's build-status API still reporting it as built. The library is properly published to Maven Central under dev.adamko.kxstsgen - a commented-out line with that exact coordinate was already sitting in the catalog. Swapping to it fixes dependency resolution for every module depending on versions-platform (which previously blocked any Gradle task touching events-library, including all of its tests). That unblocked two more pre-existing, unrelated bugs that had never been caught because this module never previously compiled: - LuaJsonList : List by list triggered a longstanding Kotlin compiler bug (KT-3546, "accidental override" on generic toArray) specific to delegating java.util.List via `by`. Replaced with a hand-written Collection implementation (no delegation codegen, no bug), which still satisfies Kotest's forOne/forAll inspectors - the only thing any code actually needs from it. - The kxs-ts-gen Kotlin->TypeScript generator (kt2ts2.kt) still emitted the pre-2.0 bare `uint`/`int` names and no import statement, since it predates typed-factorio's move to virtual modules. Updated its primitive-type mappings to uint32/int32 and added the "factorio:runtime" import to its generated header, so the regenerated schema matches what the rest of events-mod now expects. Verified via real Gradle tasks (not just manual tooling): events-library compiles and all tests pass; events-mod's full build - Kotlin schema generation, npm install, tstl compile, and info.json generation (with factorio_version "2.0" and the space-exploration/Krastorio2 optional dependencies) - succeeds end-to-end. Co-Authored-By: Claude Sonnet 5 --- gradle/libs.versions.toml | 4 ++-- .../dev/adamko/kafkatorio/library/json.kt | 19 ++++++++++++++++--- .../dev/adamko/kafkatorio/schema/kt2ts2.kt | 6 ++++-- .../typescript/generated/kafkatorio-schema.ts | 6 +++--- 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 9ca63de..9ed2401 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -114,8 +114,8 @@ kotlinxSerialization-jsonOkio = { group = "org.jetbrains.kotlinx", name = "kot kotlinxSerialization-charleskornKaml = { group = "com.charleskorn.kaml", name = "kaml", version.ref = "kxs-charleskornKaml" } kotlinxSerialization-mamoeYamlkt = { group = "net.mamoe.yamlkt", name = "yamlkt", version.ref = "kxs-mamoeYamlkt" } -#kxs-kxsTsGen = { group = "dev.adamko.kxstsgen", name = "kxs-ts-gen-core", version.ref = "kxs-kxsTsGen" } -kotlinxSerialization-kxsTsGen = { group = "com.github.adamko-dev.kotlinx-serialization-typescript-generator", name = "kxs-ts-gen-core", version.ref = "kxs-kxsTsGen" } +kotlinxSerialization-kxsTsGen = { group = "dev.adamko.kxstsgen", name = "kxs-ts-gen-core", version.ref = "kxs-kxsTsGen" } +#kotlinxSerialization-kxsTsGen = { group = "com.github.adamko-dev.kotlinx-serialization-typescript-generator", name = "kxs-ts-gen-core", version.ref = "kxs-kxsTsGen" } kotlinx-coroutines-bom = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-bom", version.ref = "kotlinx-coroutines" } diff --git a/modules/events-library/src/commonMain/kotlin/dev/adamko/kafkatorio/library/json.kt b/modules/events-library/src/commonMain/kotlin/dev/adamko/kafkatorio/library/json.kt index 33bdffc..af49f3d 100644 --- a/modules/events-library/src/commonMain/kotlin/dev/adamko/kafkatorio/library/json.kt +++ b/modules/events-library/src/commonMain/kotlin/dev/adamko/kafkatorio/library/json.kt @@ -25,10 +25,23 @@ val jsonMapperKafkatorio = Json { } -/** @see LuaJsonListSerializer */ +/** + * Implements [Collection] by hand, rather than via delegation (`by list`), because delegation + * triggers a longstanding Kotlin compiler bug ("accidental override") on the generic `toArray` + * method - see [KT-3546](https://youtrack.jetbrains.com/issue/KT-3546). A hand-written + * implementation doesn't hit that bug, since it's specific to the delegation codegen path. + * + * @see LuaJsonListSerializer + */ @Serializable(with = LuaJsonListSerializer::class) @JvmInline -value class LuaJsonList(private val list: List) : List by list +value class LuaJsonList(val list: List) : Collection { + override val size: Int get() = list.size + override fun isEmpty(): Boolean = list.isEmpty() + override fun contains(element: T): Boolean = list.contains(element) + override fun containsAll(elements: Collection): Boolean = list.containsAll(elements) + override fun iterator(): Iterator = list.iterator() +} /** @@ -68,7 +81,7 @@ class LuaJsonListSerializer( } override fun serialize(encoder: Encoder, value: LuaJsonList) { - encoder.encodeSerializableValue(listSerializer, value) + encoder.encodeSerializableValue(listSerializer, value.list) } companion object { diff --git a/modules/events-library/src/jvmMain/kotlin/dev/adamko/kafkatorio/schema/kt2ts2.kt b/modules/events-library/src/jvmMain/kotlin/dev/adamko/kafkatorio/schema/kt2ts2.kt index 903bc78..b421bea 100644 --- a/modules/events-library/src/jvmMain/kotlin/dev/adamko/kafkatorio/schema/kt2ts2.kt +++ b/modules/events-library/src/jvmMain/kotlin/dev/adamko/kafkatorio/schema/kt2ts2.kt @@ -42,9 +42,9 @@ fun main(args: Array) { //@formatter:off Float .serializer().descriptor to TsTypeAlias(TsElementId("kotlin.Float" ), TsTypeRef.Literal(TsLiteral.Custom("float" ), false)), Double.serializer().descriptor to TsTypeAlias(TsElementId("kotlin.Double"), TsTypeRef.Literal(TsLiteral.Custom("double"), false)), - Int .serializer().descriptor to TsTypeAlias(TsElementId("kotlin.Int" ), TsTypeRef.Literal(TsLiteral.Custom("int" ), false)), + Int .serializer().descriptor to TsTypeAlias(TsElementId("kotlin.Int" ), TsTypeRef.Literal(TsLiteral.Custom("int32" ), false)), Byte .serializer().descriptor to TsTypeAlias(TsElementId("kotlin.Byte" ), TsTypeRef.Literal(TsLiteral.Custom("int8" ), false)), - UInt .serializer().descriptor to TsTypeAlias(TsElementId("kotlin.UInt" ), TsTypeRef.Literal(TsLiteral.Custom("uint" ), false)), + UInt .serializer().descriptor to TsTypeAlias(TsElementId("kotlin.UInt" ), TsTypeRef.Literal(TsLiteral.Custom("uint32" ), false)), UByte .serializer().descriptor to TsTypeAlias(TsElementId("kotlin.UByte" ), TsTypeRef.Literal(TsLiteral.Custom("uint8" ), false)), UShort.serializer().descriptor to TsTypeAlias(TsElementId("kotlin.UShort"), TsTypeRef.Literal(TsLiteral.Custom("uint16"), false)), ULong .serializer().descriptor to TsTypeAlias(TsElementId("kotlin.ULong" ), TsTypeRef.Literal(TsLiteral.Custom("uint64"), false)), @@ -78,6 +78,8 @@ fun main(args: Array) { val kt2tsHeader = """ |// Generated by kxs-ts-gen - do not edit this file manually | + |import {double, float, int32, int8, PlayerIndex, SurfaceIndex, uint32, uint8, UnitNumber} from "factorio:runtime" + | """.trimMargin() diff --git a/modules/events-mod/src/main/typescript/generated/kafkatorio-schema.ts b/modules/events-mod/src/main/typescript/generated/kafkatorio-schema.ts index 92657bc..c26833e 100644 --- a/modules/events-mod/src/main/typescript/generated/kafkatorio-schema.ts +++ b/modules/events-mod/src/main/typescript/generated/kafkatorio-schema.ts @@ -1,6 +1,6 @@ // Generated by kxs-ts-gen - do not edit this file manually -import {double, float, int32 as int, int8, PlayerIndex, SurfaceIndex, uint32 as uint, uint8, UnitNumber} from "factorio:runtime" +import {double, float, int32, int8, PlayerIndex, SurfaceIndex, uint32, uint8, UnitNumber} from "factorio:runtime" export interface KafkatorioPacket { modVersion: string; @@ -145,7 +145,7 @@ export namespace KafkatorioPacketData { } } -export type UInt = uint; +export type UInt = uint32; export interface ConfigurationUpdateGameData { oldVersion?: string | null; @@ -212,7 +212,7 @@ export type Colour = [ alpha: Float, ]; -export type Int = int; +export type Int = int32; export interface ConfigurationUpdateModData { modName: string;