Skip to content

Commit

Permalink
fix: bump kotlin-wrappers to 781 (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
vlsi authored Jul 25, 2024
1 parent 6a14410 commit b330c49
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 25 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ allprojects {
dependencies {
"commonMainApi"(platform("org.jetbrains.kotlinx:kotlinx-coroutines-bom:1.8.1"))
"commonMainApi"(platform("org.jetbrains.kotlinx:kotlinx-serialization-bom:1.7.1"))
"jsMainImplementation"(enforcedPlatform("org.jetbrains.kotlin-wrappers:kotlin-wrappers-bom:1.0.0-pre.712"))
"jsMainImplementation"(enforcedPlatform("org.jetbrains.kotlin-wrappers:kotlin-wrappers-bom:1.0.0-pre.781"))
if (project.path != ":test-library") {
"jsTestImplementation"(rootProject.projects.testLibrary)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ import js.objects.jso
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.await
import kotlinx.coroutines.launch
import node.buffer.BufferEncoding
import node.fs.StatSimpleOpts
import node.fs.createReadStream
import node.fs.createWriteStream
import node.fs.stat
Expand Down Expand Up @@ -69,7 +67,7 @@ class CacheProxy {
private suspend fun putEntry(id: String, req: IncomingMessage, res: ServerResponse<*>) {
val fileName = path.join(TEMP_DIR, "bc-$id")
try {
req.pipeAndWait(createWriteStream(fileName, undefined.unsafeCast<BufferEncoding>()))
req.pipeAndWait(createWriteStream(fileName))
res.writeHead(200, "OK", undefined.unsafeCast<OutgoingHttpHeaders>())
} finally {
GlobalScope.launch {
Expand All @@ -79,7 +77,7 @@ class CacheProxy {
val cacheId = response.result?.cacheId
?: when {
response.statusCode == 400 -> throw Throwable(
"Cache $fileName size of ${stat(fileName, undefined.unsafeCast<StatSimpleOpts>()).size.toLong() / 1024 / 1024} MB is over the limit, not saving cache"
"Cache $fileName size of ${stat(fileName).size.toLong() / 1024 / 1024} MB is over the limit, not saving cache"
)
else -> throw Throwable(
"Can't reserve cache for id $id, another job might be creating this cache: ${response.error?.message}"
Expand All @@ -106,10 +104,10 @@ class CacheProxy {
res.writeHead(
200, "Ok",
jso<OutgoingHttpHeaders> {
this["content-length"] = stat(fileName, undefined.unsafeCast<StatSimpleOpts>()).size
this["content-length"] = stat(fileName).size
},
)
createReadStream(fileName, undefined.unsafeCast<BufferEncoding>()).pipeAndWait(res)
createReadStream(fileName).pipeAndWait(res)
} finally {
removeFiles(listOf(fileName))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class CacheStorage {
val result = if (parts.size == 1 && parts[0].contents.length == size) {
parts[0].contents
} else {
Buffer.alloc(size, undefined.unsafeCast<String>()).also {
Buffer.alloc(size).also {
for (part in parts) {
part.contents.copy(it, part.start, 0, part.end)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import actions.tool.cache.extractZip
import com.github.burrunan.hashing.hashFiles
import com.github.burrunan.wrappers.nodejs.exists
import js.objects.jso
import js.promise.await
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import node.buffer.BufferEncoding
Expand Down Expand Up @@ -114,7 +113,7 @@ suspend fun findVersionFromWrapper(projectPath: String, enableDistributionSha256
warning("Gradle wrapper configuration is not found at ${path.resolve(gradleWrapperProperties)}.\nWill use the current release Gradle version")
return GradleVersion.Current.findUrl()
}
val propString = readFile(gradleWrapperProperties, undefined.unsafeCast<BufferEncoding>())
val propString = readFile(gradleWrapperProperties, BufferEncoding.utf8)
val props = javaproperties.parseString(propString).run {
getKeys().associateWith { getFirst(it)!! }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,9 @@ import actions.core.ActionFailedException
import actions.core.warning
import com.github.burrunan.wrappers.nodejs.normalizedPath
import com.github.burrunan.wrappers.nodejs.pipeAndWait
import js.promise.await
import kotlinx.serialization.Serializable
import node.WritableStream
import node.buffer.BufferEncoding
import node.crypto.BinaryToTextEncoding
import node.crypto.createHash
import node.fs.StatSimpleOpts
import node.fs.createReadStream
import node.fs.stat
import node.process.process
Expand Down Expand Up @@ -80,7 +76,7 @@ suspend fun hashFilesDetailed(
val files = mutableMapOf<String, FileDetails>()
val overallHash = createHash(algorithm)
for (name in fileNames) {
val statSync = stat(name, undefined.unsafeCast<StatSimpleOpts>())
val statSync = stat(name)
if (statSync.isDirectory()) {
continue
}
Expand All @@ -102,7 +98,7 @@ suspend fun hashFilesDetailed(
else -> {
val hash = createHash(algorithm)
try {
createReadStream(name, undefined.unsafeCast<BufferEncoding>()).pipeAndWait(hash.unsafeCast<WritableStream>(), end = true)
createReadStream(name).pipeAndWait(hash, end = true)
} catch (e: Throwable) {
warning("Unable to hash $name, will ignore the file: ${e.stackTraceToString()}")
continue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@ import actions.core.ActionFailedException
import actions.core.warning
import com.github.burrunan.wrappers.nodejs.normalizedPath
import com.github.burrunan.wrappers.nodejs.pipeAndWait
import js.promise.await
import node.WritableStream
import node.buffer.BufferEncoding
import node.crypto.BinaryToTextEncoding
import node.crypto.createHash
import node.fs.StatSimpleOpts
import node.fs.createReadStream
import node.fs.stat
import node.process.process
Expand All @@ -51,7 +49,7 @@ suspend fun hashFiles(
var totalBytes = 0
var numFiles = 0
for (name in fileNames) {
val statSync = stat(name, undefined.unsafeCast<StatSimpleOpts>())
val statSync = stat(name)
if (statSync.isDirectory()) {
continue
}
Expand All @@ -68,7 +66,7 @@ suspend fun hashFiles(
// Add filename

try {
createReadStream(name, undefined.unsafeCast<BufferEncoding>()).pipeAndWait(hash.unsafeCast<WritableStream>(), end = false)
createReadStream(name).pipeAndWait(hash, end = false)
} catch (e: Throwable) {
warning("Unable to hash $name, will ignore the file: ${e.stackTraceToString()}")
continue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class MetadataFile<T>(name: String, private val serializer: KSerializer<T>, priv
val path = ROOT_FOLDER.normalizedPath
if (!existsSync(path)) {
try {
mkdirSync(path, undefined.unsafeCast<Mode>())
mkdirSync(path)
} catch (ignored: Throwable) {
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package actions.glob

import js.promise.await
import kotlinx.coroutines.launch
import kotlinx.coroutines.supervisorScope
import node.fs.unlink
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@ import node.ReadableStream
import node.WritableStream
import node.buffer.Buffer
import node.buffer.BufferEncoding
import node.events.on
import node.stream.Readable
import node.stream.ReadableEvent
import node.stream.finished

suspend fun <T> ReadableStream.readJson(): T = JSON.parse(readToBuffer().toString(BufferEncoding.utf8))
suspend fun <T> Readable.readJson(): T = JSON.parse(readToBuffer().toString(BufferEncoding.utf8))

suspend fun ReadableStream.readToBuffer(): Buffer {
suspend fun Readable.readToBuffer(): Buffer {
val data = mutableListOf<Buffer>()
on(ReadableEvent.DATA) { chunk: Any ->
on(ReadableEvent.data()) { (chunk: Any?) ->
data += chunk as Buffer
}
finished(this)
Expand Down

0 comments on commit b330c49

Please sign in to comment.