Skip to content

Commit

Permalink
fix(build/jsBrowserProductionLibraryDistribution): add workaround rem…
Browse files Browse the repository at this point in the history
…oving broken atomicfu-js js-exports from cognito-idp.d.ts
  • Loading branch information
Marcel Kesselring authored and Marcel Kesselring committed Oct 19, 2021
1 parent b4bc3f6 commit dbc04eb
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
37 changes: 37 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,43 @@ tasks {
)
}
}

/**
* Ugly atomicfu export hack: Coroutines core needs atomicfu-js, which generates broken d.ts entries. Excluding
* atomicfu-js breaks the ktor client and filtering d.ts types in the IR compile is currently not possible... so let's
* just rip it out after the fact
*
* The build/js/packages/cognito-idp/kotlin/cognito-idp.d.ts file should now be without errors and usable from typescript
*/
val cleanTypescriptTypes by creating {
fun MutableList<String>.removeFromTill(from: String, till: String) {
val fromIndex = indexOfFirst { it == from }
val tillIndex = indexOfFirst { it == till }
if (fromIndex == -1 || tillIndex == -1) {
println("looks like from='$from' till='$till' already scraped")
return
}
println("removeFromTill from='$from' till='$till' fromIndex=$fromIndex")
println("removeFromTill from='$from' till='$till' tillIndex=$tillIndex")
(fromIndex..tillIndex).forEach {
removeAt(fromIndex)
}
}

val dTsFile = file("$buildDir/js/packages/cognito-idp/kotlin/cognito-idp.d.ts")
inputs.file(dTsFile)
outputs.file(dTsFile)

doLast {
val dTs = dTsFile.readLines().toMutableList()
dTs.removeFromTill("export namespace kotlinx.atomicfu {", "}")
dTs.removeFromTill("export namespace io.ktor.util {", "}")
dTsFile.writeText(dTs.joinToString("\n"))
}
}
val jsBrowserProductionLibraryDistribution by existing {
finalizedBy(cleanTypescriptTypes)
}
}

val ossrhUsername: String? by project
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/java/Libs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ object Versions {
const val gradle = "7.0.0"
const val kotlin = "1.5.30"
const val npmPublish = "2.0.3"
const val definitions = "4.12.4"
const val definitions = "4.40.0"
const val coroutines = "1.5.1-native-mt"
const val serialization = "1.2.2"
const val ktor = "1.6.3"
Expand Down
2 changes: 1 addition & 1 deletion src/iosMain/kotlin/com/liftric/cognito/idp/jwt/Base64.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal actual class Base64 {
encoded64 = encoded64.padEnd(input.count() + (4 - remainder), '=')
}
return NSData.create(encoded64, 0)?.let {
(NSString.create(it, NSUTF8StringEncoding) as String?)
NSString.create(it, NSUTF8StringEncoding)
}?: run {
null
}
Expand Down

0 comments on commit dbc04eb

Please sign in to comment.