From b330c496a960f3ede5ab212aad2649a225728800 Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Thu, 25 Jul 2024 07:55:14 +0300 Subject: [PATCH] fix: bump kotlin-wrappers to 781 (#82) --- build.gradle.kts | 2 +- .../com/github/burrunan/gradle/proxy/CacheProxy.kt | 10 ++++------ .../com/github/burrunan/gradle/cache/CacheStorage.kt | 2 +- .../com/github/burrunan/launcher/GradleInstaller.kt | 3 +-- .../kotlin/com/github/burrunan/hashing/HashDetails.kt | 8 ++------ .../kotlin/com/github/burrunan/hashing/hashFiles.kt | 6 ++---- .../com/github/burrunan/gradle/cache/MetadataFile.kt | 2 +- .../src/jsMain/kotlin/actions/glob/removeFiles.kt | 1 - .../burrunan/wrappers/nodejs/StreamExtensions.kt | 8 +++++--- 9 files changed, 17 insertions(+), 25 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 6803315..4a2f05f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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) } diff --git a/cache-proxy/src/jsMain/kotlin/com/github/burrunan/gradle/proxy/CacheProxy.kt b/cache-proxy/src/jsMain/kotlin/com/github/burrunan/gradle/proxy/CacheProxy.kt index 9e7f0d6..4be99cb 100644 --- a/cache-proxy/src/jsMain/kotlin/com/github/burrunan/gradle/proxy/CacheProxy.kt +++ b/cache-proxy/src/jsMain/kotlin/com/github/burrunan/gradle/proxy/CacheProxy.kt @@ -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 @@ -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())) + req.pipeAndWait(createWriteStream(fileName)) res.writeHead(200, "OK", undefined.unsafeCast()) } finally { GlobalScope.launch { @@ -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()).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}" @@ -106,10 +104,10 @@ class CacheProxy { res.writeHead( 200, "Ok", jso { - this["content-length"] = stat(fileName, undefined.unsafeCast()).size + this["content-length"] = stat(fileName).size }, ) - createReadStream(fileName, undefined.unsafeCast()).pipeAndWait(res) + createReadStream(fileName).pipeAndWait(res) } finally { removeFiles(listOf(fileName)) } diff --git a/cache-service-mock/src/jsMain/kotlin/com/github/burrunan/gradle/cache/CacheStorage.kt b/cache-service-mock/src/jsMain/kotlin/com/github/burrunan/gradle/cache/CacheStorage.kt index 78bbad8..fc97a56 100644 --- a/cache-service-mock/src/jsMain/kotlin/com/github/burrunan/gradle/cache/CacheStorage.kt +++ b/cache-service-mock/src/jsMain/kotlin/com/github/burrunan/gradle/cache/CacheStorage.kt @@ -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()).also { + Buffer.alloc(size).also { for (part in parts) { part.contents.copy(it, part.start, 0, part.end) } diff --git a/gradle-launcher/src/jsMain/kotlin/com/github/burrunan/launcher/GradleInstaller.kt b/gradle-launcher/src/jsMain/kotlin/com/github/burrunan/launcher/GradleInstaller.kt index 9ca4d7a..8352e64 100644 --- a/gradle-launcher/src/jsMain/kotlin/com/github/burrunan/launcher/GradleInstaller.kt +++ b/gradle-launcher/src/jsMain/kotlin/com/github/burrunan/launcher/GradleInstaller.kt @@ -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 @@ -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()) + val propString = readFile(gradleWrapperProperties, BufferEncoding.utf8) val props = javaproperties.parseString(propString).run { getKeys().associateWith { getFirst(it)!! } } diff --git a/hashing/src/jsMain/kotlin/com/github/burrunan/hashing/HashDetails.kt b/hashing/src/jsMain/kotlin/com/github/burrunan/hashing/HashDetails.kt index ebf5c11..ceacfc8 100644 --- a/hashing/src/jsMain/kotlin/com/github/burrunan/hashing/HashDetails.kt +++ b/hashing/src/jsMain/kotlin/com/github/burrunan/hashing/HashDetails.kt @@ -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 @@ -80,7 +76,7 @@ suspend fun hashFilesDetailed( val files = mutableMapOf() val overallHash = createHash(algorithm) for (name in fileNames) { - val statSync = stat(name, undefined.unsafeCast()) + val statSync = stat(name) if (statSync.isDirectory()) { continue } @@ -102,7 +98,7 @@ suspend fun hashFilesDetailed( else -> { val hash = createHash(algorithm) try { - createReadStream(name, undefined.unsafeCast()).pipeAndWait(hash.unsafeCast(), end = true) + createReadStream(name).pipeAndWait(hash, end = true) } catch (e: Throwable) { warning("Unable to hash $name, will ignore the file: ${e.stackTraceToString()}") continue diff --git a/hashing/src/jsMain/kotlin/com/github/burrunan/hashing/hashFiles.kt b/hashing/src/jsMain/kotlin/com/github/burrunan/hashing/hashFiles.kt index 3b71535..b5df85b 100644 --- a/hashing/src/jsMain/kotlin/com/github/burrunan/hashing/hashFiles.kt +++ b/hashing/src/jsMain/kotlin/com/github/burrunan/hashing/hashFiles.kt @@ -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 @@ -51,7 +49,7 @@ suspend fun hashFiles( var totalBytes = 0 var numFiles = 0 for (name in fileNames) { - val statSync = stat(name, undefined.unsafeCast()) + val statSync = stat(name) if (statSync.isDirectory()) { continue } @@ -68,7 +66,7 @@ suspend fun hashFiles( // Add filename try { - createReadStream(name, undefined.unsafeCast()).pipeAndWait(hash.unsafeCast(), end = false) + createReadStream(name).pipeAndWait(hash, end = false) } catch (e: Throwable) { warning("Unable to hash $name, will ignore the file: ${e.stackTraceToString()}") continue diff --git a/layered-cache/src/jsMain/kotlin/com/github/burrunan/gradle/cache/MetadataFile.kt b/layered-cache/src/jsMain/kotlin/com/github/burrunan/gradle/cache/MetadataFile.kt index 3c75af7..7717d18 100644 --- a/layered-cache/src/jsMain/kotlin/com/github/burrunan/gradle/cache/MetadataFile.kt +++ b/layered-cache/src/jsMain/kotlin/com/github/burrunan/gradle/cache/MetadataFile.kt @@ -33,7 +33,7 @@ class MetadataFile(name: String, private val serializer: KSerializer, priv val path = ROOT_FOLDER.normalizedPath if (!existsSync(path)) { try { - mkdirSync(path, undefined.unsafeCast()) + mkdirSync(path) } catch (ignored: Throwable) { } } diff --git a/wrappers/actions-toolkit/src/jsMain/kotlin/actions/glob/removeFiles.kt b/wrappers/actions-toolkit/src/jsMain/kotlin/actions/glob/removeFiles.kt index 1160064..28e8a22 100644 --- a/wrappers/actions-toolkit/src/jsMain/kotlin/actions/glob/removeFiles.kt +++ b/wrappers/actions-toolkit/src/jsMain/kotlin/actions/glob/removeFiles.kt @@ -16,7 +16,6 @@ package actions.glob -import js.promise.await import kotlinx.coroutines.launch import kotlinx.coroutines.supervisorScope import node.fs.unlink diff --git a/wrappers/nodejs/src/jsMain/kotlin/com/github/burrunan/wrappers/nodejs/StreamExtensions.kt b/wrappers/nodejs/src/jsMain/kotlin/com/github/burrunan/wrappers/nodejs/StreamExtensions.kt index 12acdba..afed35a 100644 --- a/wrappers/nodejs/src/jsMain/kotlin/com/github/burrunan/wrappers/nodejs/StreamExtensions.kt +++ b/wrappers/nodejs/src/jsMain/kotlin/com/github/burrunan/wrappers/nodejs/StreamExtensions.kt @@ -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 ReadableStream.readJson(): T = JSON.parse(readToBuffer().toString(BufferEncoding.utf8)) +suspend fun Readable.readJson(): T = JSON.parse(readToBuffer().toString(BufferEncoding.utf8)) -suspend fun ReadableStream.readToBuffer(): Buffer { +suspend fun Readable.readToBuffer(): Buffer { val data = mutableListOf() - on(ReadableEvent.DATA) { chunk: Any -> + on(ReadableEvent.data()) { (chunk: Any?) -> data += chunk as Buffer } finished(this)