[Gradle, JS] Compilation to compilationName

This commit is contained in:
Ilya Goncharov
2020-12-18 14:10:11 +03:00
committed by Alexander Likhachev
parent 4566b7c6e5
commit 521b722c09
5 changed files with 60 additions and 38 deletions
@@ -26,6 +26,16 @@ internal class DukatCompilationResolverPlugin(
val nodeJs get() = resolver.nodeJs
val npmProject get() = resolver.npmProject
val compilation get() = npmProject.compilation
val compilationName by lazy {
compilation.name
}
val legacyTargetReuseIrTask by lazy {
val target = compilation.target
target is KotlinJsTarget && (target.irTarget != null && externalsOutputFormat == ExternalsOutputFormat.SOURCE)
}
val externalsOutputFormat by lazy {
compilation.externalsOutputFormat
}
val integratedTaskName = npmProject.compilation.disambiguateName("generateExternalsIntegrated")
val separateTaskName = npmProject.compilation.disambiguateName("generateExternals")
@@ -86,12 +96,10 @@ internal class DukatCompilationResolverPlugin(
packageJsonIsUpdated: Boolean,
resolution: KotlinRootNpmResolution
) {
val externalNpmDependencies = resolution[project.path][compilation].externalNpmDependencies
val externalNpmDependencies = resolution[project.path][compilationName].externalNpmDependencies
val target = compilation.target
val externalsOutputFormat = compilation.externalsOutputFormat
val legacyTargetReuseIrTask =
target is KotlinJsTarget && (target.irTarget != null && externalsOutputFormat == ExternalsOutputFormat.SOURCE)
if (legacyTargetReuseIrTask) {
return
}
@@ -11,7 +11,6 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation
import org.jetbrains.kotlin.gradle.targets.js.RequiredKotlinJsDependency
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
import org.jetbrains.kotlin.gradle.targets.js.npm.RequiresNpmDependencies
import org.jetbrains.kotlin.gradle.utils.disableTaskOnConfigurationCacheBuild
import java.io.File
abstract class DukatTask(
@@ -20,11 +19,17 @@ abstract class DukatTask(
override val compilation: KotlinJsCompilation
) : DefaultTask(), RequiresNpmDependencies {
@get:Internal
@Transient
protected val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
@get:Internal
val compilationName by lazy {
compilation.name
}
init {
// TODO: temporary workaround for configuration cache enabled builds
disableTaskOnConfigurationCacheBuild { nodeJs.npmResolutionManager.toString() }
// disableTaskOnConfigurationCacheBuild { nodeJs.npmResolutionManager.toString() }
}
@get:Internal
@@ -41,19 +46,22 @@ abstract class DukatTask(
@Input
var externalsOutputFormat: ExternalsOutputFormat = ExternalsOutputFormat.SOURCE
private val compilationResolution
get() =
nodeJs.npmResolutionManager.requireInstalled(
services,
logger
)[project.path][compilationName]
@get:Internal
@delegate:Transient
val dts by lazy {
val resolvedCompilation = nodeJs.npmResolutionManager.requireInstalled(
services,
logger
)[project.path][compilation]
val dtsResolver = DtsResolver(resolvedCompilation.npmProject)
dtsResolver.getAllDts(
resolvedCompilation.externalNpmDependencies,
considerGeneratingFlag
)
}
val dts: List<DtsResolver.Dts>
get() {
val dtsResolver = DtsResolver(compilationResolution.npmProject)
return dtsResolver.getAllDts(
compilationResolution.externalNpmDependencies,
considerGeneratingFlag
)
}
/**
* Package name for the generated file (by default filename.d.ts renamed to filename.d.kt)
@@ -87,7 +95,7 @@ abstract class DukatTask(
@TaskAction
open fun run() {
nodeJs.npmResolutionManager.checkRequiredDependencies(this)
// nodeJs.npmResolutionManager.checkRequiredDependencies(this)
destinationDir.deleteRecursively()
@@ -25,6 +25,8 @@ val KotlinJsCompilation.npmProject: NpmProject
* More info can be obtained from [KotlinCompilationNpmResolution], which is available after project resolution (after [KotlinNpmInstallTask] execution).
*/
open class NpmProject(@Transient val compilation: KotlinJsCompilation) {
val compilationName = compilation.name
val name: String by lazy {
buildNpmProjectName()
}
@@ -26,27 +26,30 @@ constructor(
private val npmProject = compilation.npmProject
private val nodeJs = npmProject.nodeJs
private val compilationResolution
get() = nodeJs.npmResolutionManager.requireInstalled(
private val compilationName = compilation.name
private val compilationResolution by lazy {
nodeJs.npmResolutionManager.requireInstalled(
services,
logger
)[project.path][npmProject.compilation]
)[project.path][compilationName]
}
init {
// TODO: temporary workaround for configuration cache enabled builds
disableTaskOnConfigurationCacheBuild { nodeJs.npmResolutionManager.toString() }
// disableTaskOnConfigurationCacheBuild { nodeJs.npmResolutionManager.toString() }
}
@get:Input
val packageJsonCustomFields: Map<String, Any?>
get() = PackageJson(fakePackageJsonValue, fakePackageJsonValue)
.apply {
compilation.packageJsonHandlers.forEach { it() }
}.customFields
// @get:Input
// val packageJsonCustomFields: Map<String, Any?>
// get() = PackageJson(fakePackageJsonValue, fakePackageJsonValue)
// .apply {
// compilation.packageJsonHandlers.forEach { it() }
// }.customFields
@get:Nested
internal val externalDependencies: Collection<NpmDependencyDeclaration>
get() = compilationResolution.externalNpmDependencies
internal val externalDependencies: Collection<NpmDependencyDeclaration> by lazy {
compilationResolution.externalNpmDependencies
.map {
NpmDependencyDeclaration(
scope = it.scope,
@@ -55,6 +58,7 @@ constructor(
generateExternals = it.generateExternals
)
}
}
private val publicPackageJsonTaskName = npmProject.publicPackageJsonTaskName
@@ -68,8 +72,8 @@ constructor(
@TaskAction
fun resolve() {
val compilation = npmProject.compilation
// val compilation = npmProject.compilation
//
// packageJson(npmProject, realExternalDependencies).let { packageJson ->
// packageJson.main = "${npmProject.name}.js"
//
@@ -30,11 +30,11 @@ class KotlinProjectNpmResolution(
}
}
val byCompilation by lazy { npmProjects.associateBy { it.npmProject.compilation.name } }
val byCompilation by lazy { npmProjects.associateBy { it.npmProject.compilationName } }
operator fun get(compilation: KotlinJsCompilation): KotlinCompilationNpmResolution {
check(compilation.target.project.path == project)
return byCompilation.getValue(compilation.name)
operator fun get(compilationName: String): KotlinCompilationNpmResolution {
// check(compilation.target.project.path == project)
return byCompilation.getValue(compilationName)
}
companion object {