Skip to content

Commit

Permalink
Update kotlin wrappers to pre.819, switch to ES modules, and use ktor…
Browse files Browse the repository at this point in the history
… as HTTP client
  • Loading branch information
Vampire committed Oct 24, 2024
1 parent bf0d42a commit ae30506
Show file tree
Hide file tree
Showing 14 changed files with 1,180 additions and 320 deletions.
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,4 @@ outputs:
runs:
using: node20
main: build/distributions/index.js
main: build/distributions/index.mjs
1 change: 1 addition & 0 deletions gradle/build-logic/build-logic.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ plugins {

dependencies {
implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location))
implementation(files(kotlinWrappers.javaClass.superclass.protectionDomain.codeSource.location))
implementation(plugin(libs.plugins.versions))
implementation(plugin(libs.plugins.dependency.analysis))
implementation(plugin(libs.plugins.release))
Expand Down
6 changes: 5 additions & 1 deletion gradle/build-logic/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,13 @@ dependencyResolutionManagement {
repositoriesMode.set(FAIL_ON_PROJECT_REPOS)

versionCatalogs {
create("libs") {
val libs by registering {
from(files("../libs.versions.toml"))
}

val kotlinWrappers by registering {
from("org.jetbrains.kotlin-wrappers:kotlin-wrappers-catalog:0.0.1-pre.819")
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

package net.kautler

import net.kautler.util.npm
import org.gradle.accessors.dm.LibrariesForLibs
import org.gradle.accessors.dm.LibrariesForKotlinWrappers
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsExec
import org.jetbrains.kotlin.gradle.tasks.IncrementalSyncTask

Expand All @@ -26,10 +26,11 @@ plugins {
}

val libs = the<LibrariesForLibs>()
val kotlinWrappers = the<LibrariesForKotlinWrappers>()

kotlin {
js {
useCommonJs()
useEsModules()
binaries.executable()
nodejs()
}
Expand All @@ -38,10 +39,9 @@ kotlin {
jsMain {
dependencies {
implementation(libs.kotlinx.coroutines.core)
implementation(dependencies.platform(libs.kotlin.wrappers.bom))
implementation(libs.kotlin.wrapper.js)
implementation(libs.kotlin.wrapper.node)
implementation(npm(libs.build.vercel.ncc))
implementation(kotlinWrappers.js)
implementation(kotlinWrappers.node)
implementation(kotlinWrappers.vercel.ncc)
}
}
}
Expand Down
38 changes: 29 additions & 9 deletions gradle/build-logic/src/main/kotlin/net/kautler/node.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package net.kautler
import net.kautler.dao.action.GitHubAction
import net.kautler.util.npm
import org.gradle.accessors.dm.LibrariesForLibs
import org.gradle.accessors.dm.LibrariesForKotlinWrappers
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsExec
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension
import org.jetbrains.kotlin.gradle.tasks.IncrementalSyncTask
Expand All @@ -29,10 +30,11 @@ plugins {
}

val libs = the<LibrariesForLibs>()
val kotlinWrappers = the<LibrariesForKotlinWrappers>()

kotlin {
js {
useCommonJs()
useEsModules()
binaries.executable()
nodejs()
}
Expand All @@ -41,22 +43,40 @@ kotlin {
jsMain {
dependencies {
implementation(libs.kotlinx.coroutines.core)
implementation(dependencies.platform(libs.kotlin.wrappers.bom))
implementation(libs.kotlin.wrapper.actions.toolkit)
implementation(libs.kotlin.wrapper.js)
implementation(libs.kotlin.wrapper.node)
implementation(npm(libs.semver))
implementation(npm(libs.nullWritable))
implementation(libs.ktor.client.core)
implementation(libs.ktor.client.js)
implementation(kotlinWrappers.actions.toolkit)
implementation(kotlinWrappers.js)
implementation(kotlinWrappers.node)
implementation(kotlinWrappers.semver)
implementation(kotlinWrappers.nullWritable)
}
}
}
}

// work-around for https://youtrack.jetbrains.com/issue/KT-56305
tasks.withType<IncrementalSyncTask>().configureEach {
// work-around for https://youtrack.jetbrains.com/issue/KT-56305
doFirst {
outputs.files.forEach { it.deleteRecursively() }
}

// work-around for https://youtrack.jetbrains.com/issue/KTOR-6158
doLast {
outputs
.files
.asFileTree
.filter { it.name == "setup-wsl.mjs" }
.forEach {
it
.readText()
.replace("eval('require')('abort-controller')", "globalThis.AbortController")
.replace("eval('require')('node-fetch')", "globalThis.fetch")
.replace("function readBodyNode(", "function _readBodyNode(")
.replace(" readBodyNode(", " readBodyBrowser(")
.apply(it::writeText)
}
}
}

val inputDefaultValues by lazy {
Expand Down Expand Up @@ -109,7 +129,7 @@ artifacts {
it
.destinationDirectory
.get()
.resolve("${project.name}.js")
.resolve("${project.name}.mjs")
}
)
}
Expand Down
14 changes: 3 additions & 11 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,9 @@ build-inject = "1"
build-kotlinx-serialization = "1.5.0"
build-node = "20.11.0"
build-snakeyaml = "2.0"
build-vercel-ncc = "0.36.1"
kotlin = "2.0.20"
kotlin-wrappers = "1.0.0-pre.529"
kotlinx-coroutines = "1.6.4"
nullWritable = "1.0.5"
semver = "7.3.8"
ktor = "3.0.0"
workflows-kotlin = "2.0.20"

[libraries]
Expand All @@ -39,14 +36,9 @@ 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-snakeyaml = { module = "org.yaml:snakeyaml", version.ref = "build-snakeyaml" }
build-vercel-ncc = { module = "vercel:ncc", version.ref = "build-vercel-ncc" }
kotlin-wrapper-actions-toolkit = { module = "org.jetbrains.kotlin-wrappers:kotlin-actions-toolkit" }
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" }
nullWritable = { module = "<unscoped>:null-writable", version.ref = "nullWritable" }
semver = { module = "<unscoped>:semver", version.ref = "semver" }
ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor" }
ktor-client-js = { module = "io.ktor:ktor-client-js", version.ref = "ktor" }
workflows-kotlin-compiler = { module = "org.jetbrains.kotlin:kotlin-compiler", version.ref = "workflows-kotlin" }
workflows-kotlin-main-kts = { module = "org.jetbrains.kotlin:kotlin-main-kts", version.ref = "workflows-kotlin" }
workflows-kotlin-scripting-compiler = { module = "org.jetbrains.kotlin:kotlin-scripting-compiler", version.ref = "workflows-kotlin" }
Expand Down
Loading

0 comments on commit ae30506

Please sign in to comment.