[Gradle, JS] Install dukat only if there is dependency with generateExternals
^KT-46178 fixed
This commit is contained in:
committed by
TeamCityServer
parent
dab693b075
commit
c73dadbcdf
+30
@@ -5,10 +5,14 @@
|
||||
|
||||
package org.jetbrains.kotlin.gradle
|
||||
|
||||
import com.google.gson.Gson
|
||||
import org.gradle.api.logging.configuration.WarningMode
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dukat.ExternalsOutputFormat
|
||||
import org.jetbrains.kotlin.gradle.targets.js.npm.NpmProject
|
||||
import org.jetbrains.kotlin.gradle.targets.js.npm.PackageJson
|
||||
import org.jetbrains.kotlin.gradle.util.modify
|
||||
import org.junit.Test
|
||||
import kotlin.test.assertFalse
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
class DukatIntegrationIT : BaseGradleIT() {
|
||||
@@ -397,6 +401,32 @@ class DukatIntegrationIT : BaseGradleIT() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testWithoutGenerateExternals() {
|
||||
val projectName = "without-generate-externals"
|
||||
val project = Project(
|
||||
projectName = projectName,
|
||||
directoryPrefix = "dukat-integration"
|
||||
)
|
||||
project.setupWorkingDir()
|
||||
|
||||
project.gradleBuildScript().modify(::transformBuildScriptWithPluginsDsl)
|
||||
|
||||
project.build("assemble", options = defaultBuildOptions().copy(warningMode = WarningMode.Summary)) {
|
||||
assertSuccessful()
|
||||
|
||||
assertTasksNotExecuted(":generateExternalsIntegrated")
|
||||
|
||||
assertFalse("Dukat don't need to be dependency for thus project") {
|
||||
fileInWorkingDir("build/js/packages/without-generate-externals")
|
||||
.resolve(NpmProject.PACKAGE_JSON)
|
||||
.let {
|
||||
Gson().fromJson(it.readText(), PackageJson::class.java)
|
||||
}.dependencies.containsKey("dukat")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun projectName(
|
||||
dslType: DslType,
|
||||
dependenciesLocation: DependenciesLocation
|
||||
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
plugins {
|
||||
kotlin("js") version "<pluginMarkerVersion>"
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(kotlin("stdlib-js"))
|
||||
implementation(npm("left-pad", "1.3.0"))
|
||||
implementation(npm("decamelize", "4.0.0"))
|
||||
}
|
||||
|
||||
kotlin {
|
||||
js {
|
||||
useCommonJs()
|
||||
nodejs()
|
||||
}
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
pluginManagement {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
gradlePluginPortal()
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -38,7 +38,7 @@ abstract class DukatTask(
|
||||
|
||||
@get:Internal
|
||||
override val requiredNpmDependencies: Set<RequiredKotlinJsDependency> by lazy {
|
||||
setOf(nodeJs.versions.dukat)
|
||||
emptySet<RequiredKotlinJsDependency>()
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+5
@@ -17,6 +17,11 @@ open class IntegratedDukatTask
|
||||
constructor(
|
||||
compilation: KotlinJsCompilation
|
||||
) : DukatTask(compilation) {
|
||||
init {
|
||||
onlyIf {
|
||||
dts.isNotEmpty() || npmProject.externalsDirRoot.resolve("inputs.txt").exists()
|
||||
}
|
||||
}
|
||||
|
||||
override val considerGeneratingFlag: Boolean = true
|
||||
|
||||
|
||||
+5
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.gradle.targets.js.dukat
|
||||
|
||||
import org.gradle.api.tasks.OutputDirectory
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation
|
||||
import org.jetbrains.kotlin.gradle.targets.js.RequiredKotlinJsDependency
|
||||
import org.jetbrains.kotlin.gradle.utils.property
|
||||
import java.io.File
|
||||
import javax.inject.Inject
|
||||
@@ -18,6 +19,10 @@ constructor(
|
||||
) : DukatTask(compilation) {
|
||||
override val considerGeneratingFlag: Boolean = false
|
||||
|
||||
override val requiredNpmDependencies: Set<RequiredKotlinJsDependency> by lazy {
|
||||
setOf(nodeJs.versions.dukat)
|
||||
}
|
||||
|
||||
@get:OutputDirectory
|
||||
override var destinationDir: File by property {
|
||||
project.projectDir.resolve("externals")
|
||||
|
||||
+16
-1
@@ -405,6 +405,10 @@ internal class KotlinCompilationNpmResolver(
|
||||
private val projectPackagesDir by lazy { compilationResolver.nodeJs.projectPackagesDir }
|
||||
private val rootDir by lazy { compilationResolver.nodeJs.rootProject.rootDir }
|
||||
|
||||
private val dukatPackageVersion by lazy {
|
||||
compilationResolver.nodeJs.versions.dukat
|
||||
}
|
||||
|
||||
@Transient
|
||||
internal lateinit var compilationResolver: KotlinCompilationNpmResolver
|
||||
|
||||
@@ -452,7 +456,18 @@ internal class KotlinCompilationNpmResolver(
|
||||
val toolsNpmDependencies = compilationResolver.rootResolver.nodeJs.taskRequirements
|
||||
.getCompilationNpmRequirements(compilationResolver.compilationDisambiguatedName)
|
||||
|
||||
val allNpmDependencies = externalNpmDependencies + toolsNpmDependencies
|
||||
val dukatIfNecessary = if (externalNpmDependencies.any { it.generateExternals }) {
|
||||
setOf(
|
||||
NpmDependencyDeclaration(
|
||||
scope = NpmDependency.Scope.DEV,
|
||||
name = dukatPackageVersion.name,
|
||||
version = dukatPackageVersion.version,
|
||||
generateExternals = false
|
||||
)
|
||||
)
|
||||
} else emptySet()
|
||||
|
||||
val allNpmDependencies = externalNpmDependencies + toolsNpmDependencies + dukatIfNecessary
|
||||
|
||||
val packageJson = packageJson(
|
||||
compilationResolver.npmProject.name,
|
||||
|
||||
Reference in New Issue
Block a user