Skip to content

Commit 208dc65

Browse files
authored
1.0.4 (#4)
2 parents ad8b174 + e7915dd commit 208dc65

File tree

13 files changed

+133
-79
lines changed

13 files changed

+133
-79
lines changed

build.gradle.kts

Lines changed: 14 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask
21
import nl.littlerobots.vcu.plugin.versionCatalogUpdate
2+
import nl.littlerobots.vcu.plugin.versionSelector
33
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnLockMismatchReport
44
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnRootExtension
55
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
66

77
plugins {
88
alias(libs.plugins.detekt)
99
alias(libs.plugins.gradleDoctor)
10-
alias(libs.plugins.versions)
1110
alias(libs.plugins.version.catalog.update)
1211
alias(libs.plugins.dokka)
13-
alias(libs.plugins.dependencyAnalysis)
12+
alias(libs.plugins.atomicfu)
1413
// plugins already on a classpath (conventions)
1514
// alias(libs.plugins.androidApplication) apply false
1615
// alias(libs.plugins.androidLibrary) apply false
@@ -61,34 +60,30 @@ doctor {
6160
}
6261
}
6362

64-
dependencyAnalysis {
65-
structure {
66-
ignoreKtx(true)
67-
}
68-
}
69-
7063
dependencies {
7164
detektPlugins(rootProject.libs.detekt.formatting)
7265
detektPlugins(rootProject.libs.detekt.compose)
7366
detektPlugins(rootProject.libs.detekt.libraries)
7467
}
7568

7669
versionCatalogUpdate {
77-
sortByKey.set(true)
70+
sortByKey = true
71+
72+
versionSelector { stabilityLevel(it.candidate.version) >= Config.minStabilityLevel }
7873

7974
keep {
80-
keepUnusedVersions.set(true)
81-
keepUnusedLibraries.set(true)
82-
keepUnusedPlugins.set(true)
75+
keepUnusedVersions = true
76+
keepUnusedLibraries = true
77+
keepUnusedPlugins = true
8378
}
8479
}
8580

86-
// atomicfu {
87-
// dependenciesVersion = libs.versions.kotlinx.atomicfu.get()
88-
// transformJvm = false
89-
// jvmVariant = "VH"
90-
// transformJs = false
91-
// }
81+
atomicfu {
82+
dependenciesVersion = libs.versions.kotlinx.atomicfu.get()
83+
transformJvm = false
84+
jvmVariant = "VH"
85+
transformJs = false
86+
}
9287

9388
tasks {
9489
withType<io.gitlab.arturbosch.detekt.Detekt>().configureEach {
@@ -118,22 +113,6 @@ tasks {
118113
description = "Run detekt on whole project"
119114
autoCorrect = false
120115
}
121-
122-
withType<DependencyUpdatesTask>().configureEach {
123-
outputFormatter = "json"
124-
125-
fun stabilityLevel(version: String): Int {
126-
Config.stabilityLevels.forEachIndexed { index, postfix ->
127-
val regex = """.*[.\-]$postfix[.\-\d]*""".toRegex(RegexOption.IGNORE_CASE)
128-
if (version.matches(regex)) return index
129-
}
130-
return Config.stabilityLevels.size
131-
}
132-
133-
rejectVersionIf {
134-
stabilityLevel(currentVersion) > stabilityLevel(candidate.version)
135-
}
136-
}
137116
}
138117

139118
extensions.findByType<YarnRootExtension>()?.run {

buildSrc/src/main/kotlin/Config.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ object Config {
1717

1818
const val majorRelease = 1
1919
const val minorRelease = 0
20-
const val patch = 3
20+
const val patch = 4
2121
const val postfix = ""
2222
const val versionName = "$majorRelease.$minorRelease.$patch$postfix"
2323
const val url = "https://github.com/respawn-app/ApiResult"
@@ -68,6 +68,8 @@ feature-rich.
6868
const val consumerProguardFile = "consumer-rules.pro"
6969

7070
val stabilityLevels = listOf("preview", "eap", "alpha", "beta", "m", "cr", "rc")
71+
val minStabilityLevel = stabilityLevels.indexOf("beta")
72+
7173
object Detekt {
7274

7375
const val configFile = "detekt.yml"

buildSrc/src/main/kotlin/ConfigureMultiplatform.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import org.gradle.api.Project
44
import org.gradle.kotlin.dsl.getValue
55
import org.gradle.kotlin.dsl.getting
66
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
7+
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
78

9+
@OptIn(ExperimentalWasmDsl::class)
10+
@Suppress("LongParameterList", "CyclomaticComplexMethod")
811
fun Project.configureMultiplatform(
912
ext: KotlinMultiplatformExtension,
1013
jvm: Boolean = true,
@@ -14,7 +17,8 @@ fun Project.configureMultiplatform(
1417
js: Boolean = true,
1518
tvOs: Boolean = true,
1619
macOs: Boolean = true,
17-
watchOs: Boolean = true
20+
watchOs: Boolean = true,
21+
wasm: Boolean = true,
1822
) = ext.apply {
1923
val libs by versionCatalog
2024
explicitApi()
@@ -27,6 +31,13 @@ fun Project.configureMultiplatform(
2731
mingwX64()
2832
}
2933

34+
if (wasm) wasmJs {
35+
moduleName = this@configureMultiplatform.name
36+
nodejs()
37+
browser()
38+
binaries.library()
39+
}
40+
3041
if (js) {
3142
js(IR) {
3243
browser()

buildSrc/src/main/kotlin/Util.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,11 @@ val Project.localProperties
6060
load(FileInputStream(File(rootProject.rootDir, "local.properties")))
6161
}
6262
}
63+
64+
fun stabilityLevel(version: String): Int {
65+
Config.stabilityLevels.forEachIndexed { index, postfix ->
66+
val regex = """.*[.\-]$postfix[.\-\d]*""".toRegex(RegexOption.IGNORE_CASE)
67+
if (version.matches(regex)) return index
68+
}
69+
return Config.stabilityLevels.size
70+
}

core/src/commonMain/kotlin/pro/respawn/apiresult/ApiResult.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,3 +627,16 @@ public inline val <T> T.asResult: ApiResult<T> get() = ApiResult(this)
627627
* Alias for [map] that takes [this] as a parameter
628628
*/
629629
public inline infix fun <T, R> ApiResult<T>.apply(block: T.() -> R): ApiResult<R> = map(block)
630+
631+
/**
632+
* @return if [this] result value is [R], then returns it. If not, returns an [ApiResult.Error]
633+
*/
634+
public inline fun <reified R, T> ApiResult<T>.requireIs(
635+
exception: (T) -> Exception = { value ->
636+
"Result value is of type ${value?.let { it::class.simpleName }} but expected ${R::class}"
637+
.let(::ConditionNotSatisfiedException)
638+
},
639+
): ApiResult<R> = tryMap { value ->
640+
if (value !is R) throw exception(value)
641+
value
642+
}

core/src/commonMain/kotlin/pro/respawn/apiresult/CollectionResult.kt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,37 @@ public inline fun <T> Iterable<ApiResult<T>>.firstSuccessOrThrow(): T = firstSuc
206206
* @see firstSuccessOrThrow
207207
*/
208208
public inline fun <T> Iterable<ApiResult<T>>.firstSuccessOrNull(): T? = firstSuccess().orNull()
209+
210+
/**
211+
* Maps each value in the collection, wrapping each map operation in an [ApiResult]
212+
*/
213+
public inline fun <T, R> Sequence<T>.mapResulting(
214+
crossinline map: (T) -> R
215+
): Sequence<ApiResult<R>> = map { ApiResult { map(it) } }
216+
217+
/**
218+
* Accumulates all errors from this collection and splits them into two lists:
219+
* - First is the [ApiResult.Success] results
220+
* - Seconds is [ApiResult.Error] or errors produced by [ApiResult.Loading] (see [ApiResult.errorOnLoading]
221+
*/
222+
public fun <T> Sequence<ApiResult<T>>.accumulate(): Pair<List<T>, List<Exception>> {
223+
val (success, other) = partition { it.isSuccess }
224+
return Pair(
225+
success.map { (it as Success).result },
226+
other.mapNotNull { it.errorOnLoading().exceptionOrNull() }
227+
)
228+
}
229+
230+
/**
231+
* Maps each value in the collection, wrapping each map operation in an [ApiResult]
232+
*/
233+
public inline fun <T, R> Iterable<T>.mapResulting(
234+
crossinline map: (T) -> R
235+
): List<ApiResult<R>> = map { ApiResult { map(it) } }
236+
237+
/**
238+
* Accumulates all errors from this collection and splits them into two lists:
239+
* - First is the [ApiResult.Success] results
240+
* - Seconds is [ApiResult.Error] or errors produced by [ApiResult.Loading] (see [ApiResult.errorOnLoading]
241+
*/
242+
public fun <T> Iterable<ApiResult<T>>.accumulate(): Pair<List<T>, List<Exception>> = asSequence().accumulate()

core/src/commonMain/kotlin/pro/respawn/apiresult/SuspendResult.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,13 @@ public inline fun <T> Flow<ApiResult<T>>.onEachResult(
112112
public inline fun <T> Flow<ApiResult<T>>.onEachSuccess(
113113
crossinline block: suspend (T) -> Unit
114114
): Flow<ApiResult<T>> = onEachResult(block)
115+
116+
/**
117+
* Maps this flow to an [ApiResult.Success] value, otherwise throws the resulting error
118+
*/
119+
public fun <T> Flow<ApiResult<T>>.orThrow(): Flow<T> = map { it.orThrow() }
120+
121+
/**
122+
* Maps this flow to an [ApiResult.Success] value, otherwise the value is `null`
123+
*/
124+
public fun <T> Flow<ApiResult<T>>.orNull(): Flow<T?> = map { it.orNull() }

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ android.disableResourceValidation=true
2121
android.nonFinalResIds=true
2222
kotlinx.atomicfu.enableJvmIrTransformation=true
2323
org.gradle.configuration-cache.problems=warn
24-
nl.littlerobots.vcu.resolver=false
24+
nl.littlerobots.vcu.resolver=true

gradle/libs.versions.toml

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
11
[versions]
2-
compose = "1.5.4"
3-
compose-activity = "1.8.2"
4-
compose-compiler = "1.5.7"
5-
compose-material3 = "1.2.0-beta01"
2+
compose = "1.6.5"
3+
compose-activity = "1.9.0-rc01"
4+
compose-compiler = "1.5.11"
5+
compose-material3 = "1.2.1"
66
composeDetektPlugin = "1.3.0"
7-
core-ktx = "1.12.0"
8-
coroutines = "1.7.3"
9-
dependencyAnalysisPlugin = "1.28.0"
10-
detekt = "1.23.4"
11-
detektFormattingPlugin = "1.23.4"
12-
dokka = "1.9.10"
13-
gradleAndroid = "8.3.0-alpha18"
14-
gradleDoctorPlugin = "0.9.1"
15-
kotest = "5.8.0"
16-
kotest-plugin = "5.8.0"
7+
core-ktx = "1.13.0-rc01"
8+
coroutines = "1.8.1-Beta"
9+
dependencyAnalysisPlugin = "1.31.0"
10+
detekt = "1.23.6"
11+
detektFormattingPlugin = "1.23.6"
12+
dokka = "1.9.20"
13+
gradleAndroid = "8.4.0-rc02"
14+
gradleDoctorPlugin = "0.9.2"
15+
kotest = "5.8.1"
16+
kotest-plugin = "5.8.1"
1717
# @pin
18-
kotlin = "1.9.22"
18+
kotlin = "1.9.23"
1919
kotlinx-atomicfu = "0.23.1"
20-
lifecycle = "2.6.2"
21-
lifecycle-runtime-ktx = "2.6.2"
20+
lifecycle = "2.7.0"
21+
lifecycle-runtime-ktx = "2.7.0"
2222
turbine = "1.0.0"
23-
versionCatalogUpdatePlugin = "0.8.2"
24-
versionsPlugin = "0.50.0"
23+
versionCatalogUpdatePlugin = "0.8.4"
2524

2625
[libraries]
2726
android-gradle = { module = "com.android.tools.build:gradle", version.ref = "gradleAndroid" }
@@ -39,7 +38,6 @@ detekt-formatting = { module = "io.gitlab.arturbosch.detekt:detekt-formatting",
3938
detekt-gradle = { module = "io.gitlab.arturbosch.detekt:detekt-gradle-plugin", version.ref = "detekt" }
4039
detekt-libraries = { module = "io.gitlab.arturbosch.detekt:detekt-rules-libraries", version.ref = "detekt" }
4140
dokka-android = { module = "org.jetbrains.dokka:android-documentation-plugin", version.ref = "dokka" }
42-
gradle-versions = { module = "com.github.ben-manes:gradle-versions-plugin", version.ref = "versionsPlugin" }
4341
kotest-assertions = { module = "io.kotest:kotest-assertions-core", version.ref = "kotest" }
4442
kotest-framework = { module = "io.kotest:kotest-framework-engine", version.ref = "kotest" }
4543
kotest-junit = { module = "io.kotest:kotest-runner-junit5", version.ref = "kotest" }
@@ -51,7 +49,6 @@ kotlin-gradle = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.
5149
kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref = "kotlin" }
5250
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test-common", version.ref = "kotlin" }
5351
lifecycle-runtime = { module = "androidx.lifecycle:lifecycle-runtime-ktx", version.ref = "lifecycle-runtime-ktx" }
54-
version-gradle = { module = "com.github.ben-manes:gradle-versions-plugin", version.ref = "versionsPlugin" }
5552

5653
[bundles]
5754
unittest = [
@@ -71,4 +68,3 @@ dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }
7168
gradleDoctor = { id = "com.osacky.doctor", version.ref = "gradleDoctorPlugin" }
7269
kotest = { id = "io.kotest.multiplatform", version.ref = "kotest-plugin" }
7370
version-catalog-update = { id = "nl.littlerobots.version-catalog-update", version.ref = "versionCatalogUpdatePlugin" }
74-
versions = { id = "com.github.ben-manes.versions", version.ref = "versionsPlugin" }

gradle/wrapper/gradle-wrapper.jar

-19.4 KB
Binary file not shown.

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

gradlew

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ done
8383
# This is normally unused
8484
# shellcheck disable=SC2034
8585
APP_BASE_NAME=${0##*/}
86-
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
86+
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
87+
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
8788

8889
# Use the maximum available, or set MAX_FD != -1 to use that value.
8990
MAX_FD=maximum
@@ -144,15 +145,15 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
144145
case $MAX_FD in #(
145146
max*)
146147
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
147-
# shellcheck disable=SC3045
148+
# shellcheck disable=SC2039,SC3045
148149
MAX_FD=$( ulimit -H -n ) ||
149150
warn "Could not query maximum file descriptor limit"
150151
esac
151152
case $MAX_FD in #(
152153
'' | soft) :;; #(
153154
*)
154155
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
155-
# shellcheck disable=SC3045
156+
# shellcheck disable=SC2039,SC3045
156157
ulimit -n "$MAX_FD" ||
157158
warn "Could not set maximum file descriptor limit to $MAX_FD"
158159
esac
@@ -201,11 +202,11 @@ fi
201202
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
202203
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
203204

204-
# Collect all arguments for the java command;
205-
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
206-
# shell script including quotes and variable substitutions, so put them in
207-
# double quotes to make sure that they get re-expanded; and
208-
# * put everything else in single quotes, so that it's not re-expanded.
205+
# Collect all arguments for the java command:
206+
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
207+
# and any embedded shellness will be escaped.
208+
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
209+
# treated as '${Hostname}' itself on the command line.
209210

210211
set -- \
211212
"-Dorg.gradle.appname=$APP_BASE_NAME" \

gradlew.bat

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ set JAVA_EXE=java.exe
4343
%JAVA_EXE% -version >NUL 2>&1
4444
if %ERRORLEVEL% equ 0 goto execute
4545

46-
echo.
47-
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
48-
echo.
49-
echo Please set the JAVA_HOME variable in your environment to match the
50-
echo location of your Java installation.
46+
echo. 1>&2
47+
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
48+
echo. 1>&2
49+
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
50+
echo location of your Java installation. 1>&2
5151

5252
goto fail
5353

@@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
5757

5858
if exist "%JAVA_EXE%" goto execute
5959

60-
echo.
61-
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
62-
echo.
63-
echo Please set the JAVA_HOME variable in your environment to match the
64-
echo location of your Java installation.
60+
echo. 1>&2
61+
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
62+
echo. 1>&2
63+
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
64+
echo location of your Java installation. 1>&2
6565

6666
goto fail
6767

0 commit comments

Comments
 (0)