[Gradle, JS] Add checks on module name set before browser and nodejs

- Add outputModuleName for compilations

KT-32017
This commit is contained in:
Ilya Goncharov
2020-03-24 19:01:59 +03:00
parent 59393e06f0
commit 930b69bef5
4 changed files with 29 additions and 0 deletions
@@ -14,6 +14,7 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilationWithResources
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTarget
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsSubTargetContainerDsl
import org.jetbrains.kotlin.gradle.targets.js.ir.JsBinary
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsBinaryContainer
import org.jetbrains.kotlin.gradle.targets.js.npm.PackageJson
@@ -31,6 +32,17 @@ open class KotlinJsCompilation(
WrapUtil.toDomainObjectSet(JsBinary::class.java)
)
var outputModuleName: String? = null
set(value) {
(target as KotlinJsSubTargetContainerDsl).apply {
check(!isBrowserConfigured && !isNodejsConfigured) {
"Please set outputModuleName for compilation before initialize browser() or nodejs() on target"
}
}
field = value
}
override val processResourcesTaskName: String
get() = disambiguateName("processResources")
@@ -43,6 +43,13 @@ constructor(
internal set
override var moduleName: String? = null
set(value) {
check(!isBrowserConfigured && !isNodejsConfigured) {
"Please set moduleName before initialize browser() or nodejs()"
}
irTarget?.moduleName = value
field = value
}
val disambiguationClassifierInPlatform: String?
get() = disambiguationClassifier?.removeJsCompilerSuffix(KotlinJsCompilerType.LEGACY)
@@ -40,6 +40,12 @@ constructor(
internal set
override var moduleName: String? = null
set(value) {
check(!isBrowserConfigured && !isNodejsConfigured) {
"Please set moduleName before initialize browser() or nodejs()"
}
field = value
}
val disambiguationClassifierInPlatform: String?
get() = disambiguationClassifier?.removeJsCompilerSuffix(KotlinJsCompilerType.IR)
@@ -92,6 +92,10 @@ open class NpmProject(val compilation: KotlinJsCompilation) {
internal fun resolve(name: String): File? = modules.resolve(name)
private fun buildNpmProjectName(): String {
compilation.outputModuleName?.let {
return it
}
val project = target.project
val moduleName = target.moduleName