[Gradle, JS] Compatibility breaking changes for css and scss support
This reverts commit 487e854f60.
^KT-53367 fixed
This commit is contained in:
+2
-2
@@ -13,10 +13,10 @@ kotlin {
|
|||||||
browser {
|
browser {
|
||||||
commonWebpackConfig {
|
commonWebpackConfig {
|
||||||
cssSupport {
|
cssSupport {
|
||||||
enabled = true
|
enabled.set(true)
|
||||||
}
|
}
|
||||||
scssSupport {
|
scssSupport {
|
||||||
enabled = true
|
enabled.set(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -16,7 +16,7 @@ abstract class CustomWebpackRule
|
|||||||
@javax.inject.Inject
|
@javax.inject.Inject
|
||||||
constructor(name: String) : org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackRule(name) {
|
constructor(name: String) : org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackRule(name) {
|
||||||
init {
|
init {
|
||||||
test = "none"
|
test.set("none")
|
||||||
}
|
}
|
||||||
override fun loaders() = listOf<org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackRule.Loader>()
|
override fun loaders() = listOf<org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackRule.Loader>()
|
||||||
}
|
}
|
||||||
@@ -26,10 +26,10 @@ kotlin {
|
|||||||
browser {
|
browser {
|
||||||
webpackTask {
|
webpackTask {
|
||||||
cssSupport {
|
cssSupport {
|
||||||
enabled = true
|
enabled.set(true)
|
||||||
}
|
}
|
||||||
scssSupport {
|
scssSupport {
|
||||||
enabled = true
|
enabled.set(true)
|
||||||
}
|
}
|
||||||
rules {
|
rules {
|
||||||
rule<CustomWebpackRule>("custom")
|
rule<CustomWebpackRule>("custom")
|
||||||
|
|||||||
+2
-14
@@ -8,6 +8,8 @@
|
|||||||
package org.jetbrains.kotlin.gradle.targets.js.webpack
|
package org.jetbrains.kotlin.gradle.targets.js.webpack
|
||||||
|
|
||||||
import com.google.gson.GsonBuilder
|
import com.google.gson.GsonBuilder
|
||||||
|
import org.gradle.api.ExtensiblePolymorphicDomainObjectContainer
|
||||||
|
import org.gradle.api.model.ObjectFactory
|
||||||
import org.gradle.api.tasks.Input
|
import org.gradle.api.tasks.Input
|
||||||
import org.gradle.api.tasks.Internal
|
import org.gradle.api.tasks.Internal
|
||||||
import org.gradle.api.tasks.Nested
|
import org.gradle.api.tasks.Nested
|
||||||
@@ -70,20 +72,6 @@ data class KotlinWebpackConfig(
|
|||||||
@Input
|
@Input
|
||||||
val webpackMajorVersion: WebpackMajorVersion = WebpackMajorVersion.V5
|
val webpackMajorVersion: WebpackMajorVersion = WebpackMajorVersion.V5
|
||||||
) : WebpackRulesDsl {
|
) : WebpackRulesDsl {
|
||||||
@get:Internal
|
|
||||||
@Deprecated("use cssSupport methods instead")
|
|
||||||
var cssSupport: KotlinWebpackCssRule
|
|
||||||
get() = rules.maybeCreate("css", KotlinWebpackCssRule::class.java)
|
|
||||||
set(value) {
|
|
||||||
rules.maybeCreate("css", KotlinWebpackCssRule::class.java).apply {
|
|
||||||
this.mode = value.mode
|
|
||||||
this.enabled = value.enabled
|
|
||||||
this.test = value.test
|
|
||||||
this.include = value.include
|
|
||||||
this.exclude = value.exclude
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@get:Input
|
@get:Input
|
||||||
@get:Optional
|
@get:Optional
|
||||||
val entryInput: String?
|
val entryInput: String?
|
||||||
|
|||||||
+8
-5
@@ -25,12 +25,15 @@ typealias KotlinWebpackCssSupport = KotlinWebpackCssRule
|
|||||||
@Suppress("LeakingThis")
|
@Suppress("LeakingThis")
|
||||||
abstract class KotlinWebpackCssRule @Inject constructor(name: String) : KotlinWebpackRule(name) {
|
abstract class KotlinWebpackCssRule @Inject constructor(name: String) : KotlinWebpackRule(name) {
|
||||||
@get:Input
|
@get:Input
|
||||||
var mode: String = INLINE
|
abstract val mode: Property<String>
|
||||||
|
|
||||||
override var test: String = "/\\.css\$/"
|
init {
|
||||||
|
mode.convention(INLINE)
|
||||||
|
test.convention("/\\.css\$/")
|
||||||
|
}
|
||||||
|
|
||||||
override fun validate(): Boolean {
|
override fun validate(): Boolean {
|
||||||
if (mode !in arrayOf(EXTRACT, INLINE, IMPORT)) {
|
if (mode.get() !in arrayOf(EXTRACT, INLINE, IMPORT)) {
|
||||||
error(
|
error(
|
||||||
"""
|
"""
|
||||||
Possible values for cssSupport.mode:
|
Possible values for cssSupport.mode:
|
||||||
@@ -46,7 +49,7 @@ abstract class KotlinWebpackCssRule @Inject constructor(name: String) : KotlinWe
|
|||||||
override fun dependencies(versions: NpmVersions): Collection<RequiredKotlinJsDependency> {
|
override fun dependencies(versions: NpmVersions): Collection<RequiredKotlinJsDependency> {
|
||||||
return mutableListOf<RequiredKotlinJsDependency>().apply {
|
return mutableListOf<RequiredKotlinJsDependency>().apply {
|
||||||
add(versions.cssLoader)
|
add(versions.cssLoader)
|
||||||
when (mode) {
|
when (mode.get()) {
|
||||||
EXTRACT -> add(versions.miniCssExtractPlugin)
|
EXTRACT -> add(versions.miniCssExtractPlugin)
|
||||||
INLINE -> add(versions.styleLoader)
|
INLINE -> add(versions.styleLoader)
|
||||||
IMPORT -> add(versions.toStringLoader)
|
IMPORT -> add(versions.toStringLoader)
|
||||||
@@ -54,7 +57,7 @@ abstract class KotlinWebpackCssRule @Inject constructor(name: String) : KotlinWe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun loaders(): List<Loader> = when (mode) {
|
override fun loaders(): List<Loader> = when (mode.get()) {
|
||||||
EXTRACT -> listOf(
|
EXTRACT -> listOf(
|
||||||
Loader(
|
Loader(
|
||||||
loader = "MiniCssExtractPlugin.loader",
|
loader = "MiniCssExtractPlugin.loader",
|
||||||
|
|||||||
+12
-8
@@ -20,24 +20,28 @@ import javax.inject.Inject
|
|||||||
@Suppress("LeakingThis")
|
@Suppress("LeakingThis")
|
||||||
abstract class KotlinWebpackRule @Inject constructor(private val name: String) : Named {
|
abstract class KotlinWebpackRule @Inject constructor(private val name: String) : Named {
|
||||||
@get:Input
|
@get:Input
|
||||||
var enabled: Boolean = false
|
abstract val enabled: Property<Boolean>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Raw rule `test` field value. Needs to be wrapped in quotes when using string notation.
|
* Raw rule `test` field value. Needs to be wrapped in quotes when using string notation.
|
||||||
*/
|
*/
|
||||||
@get:Input
|
@get:Input
|
||||||
abstract var test: String
|
abstract val test: Property<String>
|
||||||
|
|
||||||
@get:Input
|
@get:Input
|
||||||
var include: MutableList<String> = mutableListOf()
|
abstract val include: ListProperty<String>
|
||||||
|
|
||||||
@get:Input
|
@get:Input
|
||||||
var exclude: MutableList<String> = mutableListOf()
|
abstract val exclude: ListProperty<String>
|
||||||
|
|
||||||
@get:Input
|
@get:Input
|
||||||
protected open val description: String
|
protected open val description: String
|
||||||
get() = (this::class.simpleName?.removeSuffix("_Decorated") ?: "KotlinWebpackRule") + "[${getName()}]"
|
get() = (this::class.simpleName?.removeSuffix("_Decorated") ?: "KotlinWebpackRule") + "[${getName()}]"
|
||||||
|
|
||||||
|
init {
|
||||||
|
enabled.convention(false)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validates the rule state just before it getting applied.
|
* Validates the rule state just before it getting applied.
|
||||||
* Returning false will skip the rule silently. To terminate the build instead, throw an error.
|
* Returning false will skip the rule silently. To terminate the build instead, throw an error.
|
||||||
@@ -55,7 +59,7 @@ abstract class KotlinWebpackRule @Inject constructor(private val name: String) :
|
|||||||
protected abstract fun loaders(): List<Loader>
|
protected abstract fun loaders(): List<Loader>
|
||||||
|
|
||||||
@get:Internal
|
@get:Internal
|
||||||
internal val active: Boolean get() = enabled && validate()
|
internal val active: Boolean get() = enabled.get() && validate()
|
||||||
internal fun Appendable.appendToWebpackConfig() {
|
internal fun Appendable.appendToWebpackConfig() {
|
||||||
appendLine(
|
appendLine(
|
||||||
"""
|
"""
|
||||||
@@ -83,14 +87,14 @@ abstract class KotlinWebpackRule @Inject constructor(private val name: String) :
|
|||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
)
|
)
|
||||||
|
|
||||||
val excluded = exclude.takeIf(List<*>::isNotEmpty)
|
val excluded = exclude.get().takeIf(List<*>::isNotEmpty)
|
||||||
?.joinToString(separator = ",", prefix = "[", postfix = "]") ?: "undefined"
|
?.joinToString(separator = ",", prefix = "[", postfix = "]") ?: "undefined"
|
||||||
val included = include.takeIf(List<*>::isNotEmpty)
|
val included = include.get().takeIf(List<*>::isNotEmpty)
|
||||||
?.joinToString(separator = ",", prefix = "[", postfix = "]") ?: "undefined"
|
?.joinToString(separator = ",", prefix = "[", postfix = "]") ?: "undefined"
|
||||||
appendLine(
|
appendLine(
|
||||||
"""
|
"""
|
||||||
config.module.rules.push({
|
config.module.rules.push({
|
||||||
test: ${test},
|
test: ${test.get()},
|
||||||
use: use,
|
use: use,
|
||||||
exclude: $excluded,
|
exclude: $excluded,
|
||||||
include: $included,
|
include: $included,
|
||||||
|
|||||||
+3
-1
@@ -11,7 +11,9 @@ import javax.inject.Inject
|
|||||||
|
|
||||||
@Suppress("LeakingThis")
|
@Suppress("LeakingThis")
|
||||||
abstract class KotlinWebpackScssRule @Inject constructor(name: String) : KotlinWebpackCssRule(name) {
|
abstract class KotlinWebpackScssRule @Inject constructor(name: String) : KotlinWebpackCssRule(name) {
|
||||||
override var test: String = "/\\.(scss|sass)\$/"
|
init {
|
||||||
|
test.convention("/\\.(scss|sass)\$/")
|
||||||
|
}
|
||||||
|
|
||||||
override fun dependencies(versions: NpmVersions): Collection<RequiredKotlinJsDependency> {
|
override fun dependencies(versions: NpmVersions): Collection<RequiredKotlinJsDependency> {
|
||||||
return super.dependencies(versions) + versions.sass + versions.sassLoader
|
return super.dependencies(versions) + versions.sass + versions.sassLoader
|
||||||
|
|||||||
Reference in New Issue
Block a user