[Gradle] Fix JS module name and freeCompilerArgs config is not propagated to the task
Task was not using configured module name correctly. In case of using "browser()" DSL freeCompilerArgs could be overwritten. ^KT-61194 Fixed
This commit is contained in:
committed by
Space Team
parent
4c60dd3f38
commit
55a0c86508
+1
-3
@@ -56,9 +56,7 @@ abstract class KotlinJsIrSubTarget(
|
||||
internal fun configure() {
|
||||
target.compilations.all {
|
||||
val npmProject = it.npmProject
|
||||
it.kotlinOptions {
|
||||
freeCompilerArgs += "$PER_MODULE_OUTPUT_NAME=${npmProject.name}"
|
||||
}
|
||||
it.compilerOptions.options.freeCompilerArgs.add("$PER_MODULE_OUTPUT_NAME=${npmProject.name}")
|
||||
}
|
||||
|
||||
configureTests()
|
||||
|
||||
+1
-2
@@ -37,8 +37,7 @@ internal open class BaseKotlin2JsCompileConfig<TASK : Kotlin2JsCompile>(
|
||||
|
||||
configureAdditionalFreeCompilerArguments(task, compilation)
|
||||
|
||||
task.compilerOptions.moduleName.convention(compilation.moduleName)
|
||||
task.moduleName.set(providers.provider { compilation.moduleName })
|
||||
task.moduleName.set(task.compilerOptions.moduleName)
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
task.outputFileProperty.value(
|
||||
|
||||
+49
@@ -11,11 +11,13 @@ import org.jetbrains.kotlin.gradle.dsl.multiplatformExtension
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMetadataTarget
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.external.createCompilation
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.external.createExternalKotlinTarget
|
||||
import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile as KotlinJvmCompileTask
|
||||
import org.jetbrains.kotlin.gradle.tasks.withType
|
||||
import org.jetbrains.kotlin.gradle.util.*
|
||||
import org.jetbrains.kotlin.gradle.utils.named
|
||||
import org.jetbrains.kotlin.test.util.JUnit4Assertions.assertTrue
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
@@ -322,6 +324,53 @@ class ProjectCompilerOptionsTests {
|
||||
assertEquals("my-custom-module-name", project.kotlinJvmTask("compileKotlinJvm").compilerOptions.moduleName.orNull)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testJsOptionsIsConfigured() {
|
||||
val project = buildProjectWithMPP()
|
||||
project.runLifecycleAwareTest {
|
||||
with(multiplatformExtension) {
|
||||
js {
|
||||
compilerOptions {
|
||||
moduleName.set("js-module-name")
|
||||
freeCompilerArgs.add("-Xstrict-implicit-export-types")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val kotlinJsCompileTask = project.kotlinJsTask("compileKotlinJs")
|
||||
assertEquals("js-module-name", kotlinJsCompileTask.compilerOptions.moduleName.orNull)
|
||||
assertTrue(
|
||||
kotlinJsCompileTask
|
||||
.compilerOptions
|
||||
.freeCompilerArgs.get()
|
||||
.contains("-Xstrict-implicit-export-types")
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testJsBrowserConfigDoesNotOverrideFreeCompilerArgsFromTarget() {
|
||||
val project = buildProjectWithMPP()
|
||||
project.runLifecycleAwareTest {
|
||||
with(multiplatformExtension) {
|
||||
js {
|
||||
binaries.executable()
|
||||
browser()
|
||||
compilerOptions {
|
||||
freeCompilerArgs.addAll("-Xstrict-implicit-export-types", "-Xexplicit-api=warning")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val kotlinJsCompileTask = project.kotlinJsTask("compileKotlinJs")
|
||||
assertTrue(
|
||||
(kotlinJsCompileTask as Kotlin2JsCompile)
|
||||
.enhancedFreeCompilerArgs.get()
|
||||
.containsAll(listOf("-Xstrict-implicit-export-types", "-Xexplicit-api=warning"))
|
||||
)
|
||||
}
|
||||
|
||||
private fun Project.kotlinNativeTask(name: String): KotlinCompilationTask<KotlinNativeCompilerOptions> = tasks
|
||||
.named<KotlinCompilationTask<KotlinNativeCompilerOptions>>(name)
|
||||
.get()
|
||||
|
||||
Reference in New Issue
Block a user