[Gradle, JS] Add nullable custom fields
^KT-42395 fixed
This commit is contained in:
committed by
Space Team
parent
7854b01473
commit
4e13b7a202
+26
@@ -6,6 +6,8 @@
|
|||||||
package org.jetbrains.kotlin.gradle
|
package org.jetbrains.kotlin.gradle
|
||||||
|
|
||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
|
import com.google.gson.JsonNull
|
||||||
|
import com.google.gson.JsonObject
|
||||||
import org.gradle.api.logging.LogLevel
|
import org.gradle.api.logging.LogLevel
|
||||||
import org.gradle.api.logging.configuration.WarningMode
|
import org.gradle.api.logging.configuration.WarningMode
|
||||||
import org.gradle.testkit.runner.BuildResult
|
import org.gradle.testkit.runner.BuildResult
|
||||||
@@ -1112,6 +1114,30 @@ abstract class AbstractKotlin2JsGradlePluginIT(protected val irBackend: Boolean)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@DisplayName("package.json custom fields")
|
||||||
|
@GradleTest
|
||||||
|
fun testPackageJsonCustomField(gradleVersion: GradleVersion) {
|
||||||
|
project("kotlin-js-browser-project", gradleVersion) {
|
||||||
|
buildGradleKts.modify(::transformBuildScriptWithPluginsDsl)
|
||||||
|
|
||||||
|
build("rootPackageJson") {
|
||||||
|
assertTasksExecuted(":app:packageJson")
|
||||||
|
|
||||||
|
val jso = projectPath.resolve("build/js/packages/kotlin-js-browser-app")
|
||||||
|
.resolve(NpmProject.PACKAGE_JSON)
|
||||||
|
.let {
|
||||||
|
Gson().fromJson(it.readText(), JsonObject::class.java)
|
||||||
|
}
|
||||||
|
|
||||||
|
assertEquals(1, jso.get("customField1").asJsonObject.get("one").asInt)
|
||||||
|
assertEquals(2, jso.get("customField1").asJsonObject.get("two").asInt)
|
||||||
|
assertEquals(JsonNull.INSTANCE, jso.get("customField2").asJsonNull)
|
||||||
|
assertEquals(JsonNull.INSTANCE, jso.get("customField3").asJsonNull)
|
||||||
|
assertEquals(JsonNull.INSTANCE, jso.get("customField4").asJsonObject.get("foo").asJsonNull)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@DisplayName("kotlin/js compiler warning")
|
@DisplayName("kotlin/js compiler warning")
|
||||||
@GradleTest
|
@GradleTest
|
||||||
fun testKotlinJsCompilerWarn(gradleVersion: GradleVersion) {
|
fun testKotlinJsCompilerWarn(gradleVersion: GradleVersion) {
|
||||||
|
|||||||
+4
-1
@@ -47,7 +47,10 @@ kotlin {
|
|||||||
|
|
||||||
compilations.named("main") {
|
compilations.named("main") {
|
||||||
packageJson {
|
packageJson {
|
||||||
customField("customField", mapOf("one" to 1, "two" to 2))
|
customField("customField1", mapOf("one" to 1, "two" to 2))
|
||||||
|
customField("customField2", null)
|
||||||
|
customField("customField3" to null)
|
||||||
|
customField("customField4", mapOf("foo" to null))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-2
@@ -58,11 +58,11 @@ class PackageJson(
|
|||||||
val bundledDependencies = mutableListOf<String>()
|
val bundledDependencies = mutableListOf<String>()
|
||||||
get() = field ?: mutableListOf()
|
get() = field ?: mutableListOf()
|
||||||
|
|
||||||
fun customField(pair: Pair<String, Any>) {
|
fun customField(pair: Pair<String, Any?>) {
|
||||||
customFields[pair.first] = pair.second
|
customFields[pair.first] = pair.second
|
||||||
}
|
}
|
||||||
|
|
||||||
fun customField(key: String, value: Any) {
|
fun customField(key: String, value: Any?) {
|
||||||
customFields[key] = value
|
customFields[key] = value
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,6 +92,7 @@ class PackageJson(
|
|||||||
val gson = GsonBuilder()
|
val gson = GsonBuilder()
|
||||||
.setPrettyPrinting()
|
.setPrettyPrinting()
|
||||||
.disableHtmlEscaping()
|
.disableHtmlEscaping()
|
||||||
|
.serializeNulls()
|
||||||
.addSerializationExclusionStrategy(
|
.addSerializationExclusionStrategy(
|
||||||
object : ExclusionStrategy {
|
object : ExclusionStrategy {
|
||||||
override fun shouldSkipField(f: FieldAttributes?): Boolean =
|
override fun shouldSkipField(f: FieldAttributes?): Boolean =
|
||||||
|
|||||||
Reference in New Issue
Block a user