Skip to content

Commit

Permalink
Replace kotlin-extensions and kotlinx-nodejs by kotlin-wrappers
Browse files Browse the repository at this point in the history
  • Loading branch information
Vampire committed Feb 16, 2023
1 parent 2238c92 commit a1aeb4c
Show file tree
Hide file tree
Showing 10 changed files with 155 additions and 160 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ val libs = the<LibrariesForLibs>()

dependencies {
implementation(libs.kotlinx.coroutines.core)
implementation(libs.kotlin.extensions)
implementation(libs.kotlinx.nodejs)
implementation(platform(libs.kotlin.wrappers.bom))
implementation(libs.kotlin.wrapper.js)
implementation(libs.kotlin.wrapper.node)
implementation(npm(libs.build.vercel.ncc, generateExternals = false))
}
83 changes: 52 additions & 31 deletions gradle/build-logic/src/main/kotlin/net/kautler/node.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,9 @@ configure<NodeJsRootExtension> {

dependencies {
implementation(libs.kotlinx.coroutines.core)
implementation(libs.kotlin.extensions)
implementation(libs.kotlinx.nodejs)
implementation(platform(libs.kotlin.wrappers.bom))
implementation(libs.kotlin.wrapper.js)
implementation(libs.kotlin.wrapper.node)
implementation(npm(libs.actions.cache))
implementation(npm(libs.actions.core))
implementation(npm(libs.actions.exec))
Expand Down Expand Up @@ -163,22 +164,55 @@ tasks.withType(IntegratedDukatTask::class).configureEach {
)
fixExternalsFiles(
this,
"index.module_@actions_http-client.kt" to listOf(
"""\Qimport http.IncomingMessage\E$""" to "import node.http.IncomingMessage",
"""\Qimport http.OutgoingHttpHeaders\E$""" to "import node.http.OutgoingHttpHeaders",
"""\Qimport NodeJS.ReadableStream\E$""" to "import node.ReadableStream",
"""\Qimport http.Agent\E$""" to "import node.http.Agent",
"""\Qtypealias HttpClientError = Error\E$""" to "external class HttpClientError : Throwable"
),
"interfaces.module_@actions_exec.kt" to listOf(
"""\Qimport stream.internal.Writable\E$""" to "import node.stream.Writable",
"""\Qimport buffer.global.Buffer\E$""" to "import node.buffer.Buffer",
"""\Qvar env: `T$2`?\E\r?\n\Q get() = definedExternally\E\r?\n\Q set(value) = definedExternally\E""" to "var env: js.core.ReadonlyRecord<String, String>?"
),
"interfaces.module_@actions_http-client.kt" to listOf(
"""\Qimport http.OutgoingHttpHeaders\E$""" to "import node.http.OutgoingHttpHeaders",
"""\Qimport NodeJS.ReadableStream\E$""" to "import node.ReadableStream",
"""\Qimport http.IncomingHttpHeaders\E$""" to "import node.http.IncomingHttpHeaders",
"""\Qexternal interface HttpClient {\E$""" to "external interface HttpClient2 {",
"""\Qoptions: http.RequestOptions\E(\))?$""" to "options: node.http.RequestOptions$1"
),
"lib.dom.kt" to listOf(
"""\Qoverride fun addEventListener(type: String, listener: EventListenerObject\E""" to """fun addEventListener(type: String, listener: EventListenerObject""",
"""\Qoverride fun removeEventListener(type: String, callback: EventListenerObject\E""" to """fun removeEventListener(type: String, callback: EventListenerObject""",
"""\Q`T${'$'}16`\E""" to """`T\${'$'}16`<R, T>"""
"""\Qimport url.URL as _URL\E$""" to "import node.url.URL as _URL",
"""\Qimport url.URLSearchParams as _URLSearchParams\E$""" to "import node.url.URLSearchParams as _URLSearchParams",
"""\Qoverride fun addEventListener(type: String, listener: EventListenerObject\E""" to "fun addEventListener(type: String, listener: EventListenerObject",
"""\Qoverride fun removeEventListener(type: String, callback: EventListenerObject\E""" to "fun removeEventListener(type: String, callback: EventListenerObject",
"""\Q`T$16`\E""" to """`T\$16`<R, T>"""
),
// work-around for https://github.com/Kotlin/dukat/issues/402
"lib.es2018.asynciterable.module_dukat.kt" to listOf(
"""\Qval `return`: ((value: TReturn) -> Promise<dynamic /* IteratorYieldResult<T> | IteratorReturnResult<TReturn> */>)?\E$""" to "val `return`: ((value: dynamic) -> Promise<dynamic /* IteratorYieldResult<T> | IteratorReturnResult<TReturn> */>)?",
"""^*\Qval `return`: ((value: PromiseLike<TReturn>) -> Promise<dynamic /* IteratorYieldResult<T> | IteratorReturnResult<TReturn> */>)?\E\r?\n\Q get() = definedExternally\E\r?\n""" to ""
"""\Qval `return`: ((value: PromiseLike<TReturn>) -> Promise<dynamic /* IteratorYieldResult<T> | IteratorReturnResult<TReturn> */>)?\E\r?\n\Q get() = definedExternally\E\r?\n""" to ""
),
"lib.es2020.bigint.module_dukat.kt" to listOf(
"""\Q : RelativeIndexable<Any>\E""" to ""
),
"lib.es5.kt" to listOf(
"""\Qimport NodeJS.CallSite\E$""" to "import node.CallSite",
"""\Qval resolve: ((specified: String, parent: URL) -> Promise<String>)?\E$""" to "val resolve2: ((specified: String, parent: URL) -> Promise<String>)?"
),
// work-around for https://github.com/Kotlin/dukat/issues/401
"null-writable.module_null-writable.kt" to listOf(
"""\Q`T$13`\E""" to """`T\$10`"""
"""\Qimport stream.internal.`T$13`\E$""" to "",
"""\Qimport stream.internal.Writable\E$""" to "import node.stream.Writable",
"""\Qoverride fun _write(_chunk: Any, _encoding: String, callback: (error: Error?) -> Unit)\E$""" to "override fun _write(chunk: Any, encoding: node.buffer.BufferEncoding, callback: (error: Error?) -> Unit)",
"""\Qopen fun _writev(_chunks: Array<`T$88`>, callback: (error: Error?) -> Unit)\E$""" to "",
"""\Qoverride fun _writev(chunks: Array<`T$13`>, callback: (error: Error?) -> Unit)\E$""" to ""
),
// work-around for https://github.com/Kotlin/dukat/issues/399
"tool-cache.module_@actions_tool-cache.kt" to listOf(
"""\Qimport http.OutgoingHttpHeaders\E$""" to "import node.http.OutgoingHttpHeaders",
"""\Qtypealias HTTPError = Error\E$""" to "external class HTTPError : Throwable",
"""\Qtypealias IToolRelease = IToolRelease\E$""" to "",
"""\Qtypealias IToolReleaseFile = IToolReleaseFile\E$""" to ""
Expand All @@ -188,24 +222,9 @@ tasks.withType(IntegratedDukatTask::class).configureEach {
"""\Qtypealias ValidationError = Error\E$""" to "external class ValidationError : Throwable",
"""\Qtypealias ReserveCacheError = Error\E$""" to "external class ReserveCacheError : Throwable"
),
"index.module_@actions_http-client.kt" to listOf(
"""\Qtypealias HttpClientError = Error\E$""" to "external class HttpClientError : Throwable"
),
"interfaces.module_@actions_http-client.kt" to listOf(
"""\Qexternal interface HttpClient {\E$""" to "external interface HttpClient2 {"
),
// work-around for https://github.com/Kotlin/dukat/issues/400
"semver.module_semver.kt" to listOf(
"""\Q@JsModule("semver")\E$""" to """@JsModule("semver/classes/semver")"""
),
"interfaces.module_@actions_exec.kt" to listOf(
"""\Qimport buffer.global.Buffer\E$""" to """import Buffer"""
),
"lib.es5.kt" to listOf(
"""\Qval resolve: ((specified: String, parent: URL) -> Promise<String>)?\E$""" to """val resolve2: ((specified: String, parent: URL) -> Promise<String>)?"""
),
"lib.es2020.bigint.module_dukat.kt" to listOf(
"""\Q : RelativeIndexable<Any>\E""" to """"""
)
)
}
Expand Down Expand Up @@ -235,16 +254,18 @@ fun addJsModuleAnnotations(task: Task, vararg pairs: Pair<String, String>) {
}

fun deleteExternalsFiles(task: Task, vararg files: String) {
task
.outputs
.files
.asFileTree
.matching {
for (file in files) {
include("**/$file")
if (files.isNotEmpty()) {
task
.outputs
.files
.asFileTree
.matching {
for (file in files) {
include("**/$file")
}
}
}
.forEach { it.delete() }
.forEach { it.delete() }
}
}

fun fixExternalsFiles(task: Task, vararg pairs: Pair<String, List<Pair<String, String>>>) {
Expand Down
8 changes: 4 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ build-kotlinx-serialization = "1.4.1"
build-node = "16.18.1"
build-vercel-ncc = "0.36.1"
kotlin = "1.8.10"
kotlin-extensions = "1.0.1-pre.156-kotlin-1.5.0"
kotlin-wrappers = "1.0.0-pre.491"
kotlinx-coroutines = "1.6.4"
kotlinx-nodejs = "0.0.7"
nullWritable = "1.0.5"
semver = "7.3.8"
types-semver = "7.3.13"
Expand All @@ -52,9 +51,10 @@ build-kotlinx-serialization-bom = { module = "org.jetbrains.kotlinx:kotlinx-seri
build-kotlinx-serialization-core = { module = "org.jetbrains.kotlinx:kotlinx-serialization-core" }
build-kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json" }
build-vercel-ncc = { module = "vercel:ncc", version.ref = "build-vercel-ncc" }
kotlin-extensions = { module = "org.jetbrains:kotlin-extensions", version.ref = "kotlin-extensions" }
kotlin-wrapper-js = { module = "org.jetbrains.kotlin-wrappers:kotlin-js" }
kotlin-wrapper-node = { module = "org.jetbrains.kotlin-wrappers:kotlin-node" }
kotlin-wrappers-bom = { module = "org.jetbrains.kotlin-wrappers:kotlin-wrappers-bom", version.ref = "kotlin-wrappers" }
kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinx-coroutines" }
kotlinx-nodejs = { module = "org.jetbrains.kotlinx:kotlinx-nodejs", version.ref = "kotlinx-nodejs" }
nullWritable = { module = "<unscoped>:null-writable", version.ref = "nullWritable" }
semver = { module = "<unscoped>:semver", version.ref = "semver" }
types-semver = { module = "types:semver", version.ref = "types-semver" }
Expand Down
13 changes: 13 additions & 0 deletions kotlin-js-store/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@
resolved "https://registry.yarnpkg.com/@types/node/-/node-18.11.0.tgz#f38c7139247a1d619f6cc6f27b072606af7c289d"
integrity sha512-IOXCvVRToe7e0ny7HpT/X9Rb2RYtElG1a+VshjwT00HxrM2dWBApHQoqsI6WiY7Q03vdf2bCrIGzVrkF/5t10w==

"@types/node@^18.11.18":
version "18.11.18"
resolved "https://registry.yarnpkg.com/@types/node/-/node-18.11.18.tgz#8dfb97f0da23c2293e554c5a50d61ef134d7697f"
integrity sha512-DHQpWGjyQKSHj3ebjFI/wRKcqQcdR+MoFBygntYOZytCqNfkd2ZC4ARDJ2DQqhjH5p85Nnd3jhUJIXrszFX/JA==

"@types/semver@7.3.13":
version "7.3.13"
resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.3.13.tgz#da4bfd73f49bd541d28920ab0e2bf0ee80f71c91"
Expand Down Expand Up @@ -383,6 +388,14 @@ dukat@0.5.7:
google-protobuf "3.12.2"
typescript "3.9.5"

dukat@0.5.8-rc.4:
version "0.5.8-rc.4"
resolved "https://registry.yarnpkg.com/dukat/-/dukat-0.5.8-rc.4.tgz#90384dcb50b14c26f0e99dae92b2dea44f5fce21"
integrity sha512-ZnMt6DGBjlVgK2uQamXfd7uP/AxH7RqI0BL9GLrrJb2gKdDxvJChWy+M9AQEaL+7/6TmxzJxFOsRiInY9oGWTA==
dependencies:
google-protobuf "3.12.2"
typescript "3.9.5"

emoji-regex@^8.0.0:
version "8.0.0"
resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-8.0.0.tgz#e818fd69ce5ccfcb404594f842963bf53164cc37"
Expand Down
28 changes: 14 additions & 14 deletions ncc-packer/src/main/kotlin/net/kautler/nccpacker/NccPacker.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 Björn Kautler
* Copyright 2020-2023 Björn Kautler
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,35 +16,35 @@

package net.kautler.nccpacker

import fs.MakeDirectoryOptions
import fs.`T$45`
import fs.mkdirSync
import fs.writeFileSync
import kotlinext.js.jsObject
import js.core.jso
import kotlinx.coroutines.await
import path.path
import process
import node.fs.MakeDirectoryOptions
import node.fs.WriteFileOptions
import node.fs.mkdir
import node.fs.writeFile
import node.path.path
import node.process.process

suspend fun main() {
runCatching {
val (input, output) = process.argv.filterIndexed { i, _ -> i > 1 }
val result = ncc(input, jsObject {
val result = ncc(input, jso {
sourceMap = true
license = "LICENSES"
}).await()

mkdirSync(output, jsObject<MakeDirectoryOptions> {
mkdir(output, jso<MakeDirectoryOptions> {
recursive = true
})
writeFileSync(path.join(output, "index.js"), result.code, jsObject<`T$45`>())
result.map?.also { writeFileSync(path.join(output, "index.js.map"), it, jsObject<`T$45`>()) }
writeFile(path.join(output, "index.js"), result.code)
result.map?.also { writeFile(path.join(output, "index.js.map"), it) }

result.assets?.forEach { (assetFileName, asset) ->
val assetFilePath = path.join(output, assetFileName)
mkdirSync(path.dirname(assetFilePath), jsObject<MakeDirectoryOptions> {
mkdir(path.dirname(assetFilePath), jso<MakeDirectoryOptions> {
recursive = true
})
writeFileSync(assetFilePath, asset.source, jsObject<`T$45`> {
writeFile(assetFilePath, asset.source, jso<WriteFileOptions> {
mode = asset.permissions
})
}
Expand Down
6 changes: 3 additions & 3 deletions ncc-packer/src/main/kotlin/net/kautler/nccpacker/ncc.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 Björn Kautler
* Copyright 2020-2023 Björn Kautler
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,8 +16,8 @@

package net.kautler.nccpacker

import Buffer
import kotlinext.js.Object
import js.core.Object
import node.buffer.Buffer
import kotlin.js.Promise

@JsModule("@vercel/ncc")
Expand Down
12 changes: 0 additions & 12 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,6 @@ dependencyResolutionManagement {
}
}
mavenCentral()
//TODO: Remove after getting rid of kotlin-extensions
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/kotlin-js-wrappers/") {
content {
includeModule("org.jetbrains", "kotlin-extensions")
}
}
//TODO: Remove after getting rid of kotlinx-nodejs
jcenter {
content {
includeModule("org.jetbrains.kotlinx", "kotlinx-nodejs")
}
}
}
// work-around for https://youtrack.jetbrains.com/issue/KT-56300
//repositoriesMode.set(FAIL_ON_PROJECT_REPOS)
Expand Down
Loading

0 comments on commit a1aeb4c

Please sign in to comment.