[Gradle, JS] Remove dukat integration
^KT-54445 fixed
This commit is contained in:
committed by
Space Team
parent
1ce99db830
commit
05a6a07b08
-9
@@ -26,8 +26,6 @@ import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLI
|
|||||||
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_STDLIB_DEFAULT_DEPENDENCY
|
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_STDLIB_DEFAULT_DEPENDENCY
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMultiplatformPlugin
|
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMultiplatformPlugin
|
||||||
import org.jetbrains.kotlin.gradle.plugin.statistics.KotlinBuildStatsService
|
import org.jetbrains.kotlin.gradle.plugin.statistics.KotlinBuildStatsService
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.dukat.ExternalsOutputFormat
|
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.dukat.ExternalsOutputFormat.Companion.externalsOutputFormatProperty
|
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinIrJsGeneratedTSValidationStrategy
|
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinIrJsGeneratedTSValidationStrategy
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrOutputGranularity
|
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrOutputGranularity
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.webpack.WebpackMajorVersion
|
import org.jetbrains.kotlin.gradle.targets.js.webpack.WebpackMajorVersion
|
||||||
@@ -406,13 +404,6 @@ internal class PropertiesProvider private constructor(private val project: Proje
|
|||||||
}
|
}
|
||||||
?: WebpackMajorVersion.DEFAULT
|
?: WebpackMajorVersion.DEFAULT
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Default mode of generating of Dukat
|
|
||||||
*/
|
|
||||||
val externalsOutputFormat: ExternalsOutputFormat?
|
|
||||||
get() = this.property(externalsOutputFormatProperty)?.let { ExternalsOutputFormat.byArgumentOrNull(it) }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use Kotlin/JS backend compiler type
|
* Use Kotlin/JS backend compiler type
|
||||||
*/
|
*/
|
||||||
|
|||||||
-6
@@ -23,7 +23,6 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.util.*
|
|||||||
import org.jetbrains.kotlin.gradle.plugin.sources.*
|
import org.jetbrains.kotlin.gradle.plugin.sources.*
|
||||||
import org.jetbrains.kotlin.gradle.plugin.sources.kpm.FragmentMappedKotlinSourceSet
|
import org.jetbrains.kotlin.gradle.plugin.sources.kpm.FragmentMappedKotlinSourceSet
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTarget
|
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTarget
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrCompilation
|
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget
|
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget
|
||||||
import org.jetbrains.kotlin.gradle.targets.metadata.getMetadataCompilationForSourceSet
|
import org.jetbrains.kotlin.gradle.targets.metadata.getMetadataCompilationForSourceSet
|
||||||
import org.jetbrains.kotlin.gradle.utils.*
|
import org.jetbrains.kotlin.gradle.utils.*
|
||||||
@@ -672,11 +671,6 @@ internal class JsIrCompilationDetails(
|
|||||||
target: KotlinTarget, compilationPurpose: String, defaultSourceSet: KotlinSourceSet
|
target: KotlinTarget, compilationPurpose: String, defaultSourceSet: KotlinSourceSet
|
||||||
) : JsCompilationDetails(target, compilationPurpose, defaultSourceSet) {
|
) : JsCompilationDetails(target, compilationPurpose, defaultSourceSet) {
|
||||||
|
|
||||||
override fun addSourcesToCompileTask(sourceSet: KotlinSourceSet, addAsCommonSources: Lazy<Boolean>) {
|
|
||||||
super.addSourcesToCompileTask(sourceSet, addAsCommonSources)
|
|
||||||
(compilation as KotlinJsIrCompilation).allSources.add(sourceSet.kotlin)
|
|
||||||
}
|
|
||||||
|
|
||||||
internal abstract class JsIrCompilationDependencyHolder @Inject constructor(target: KotlinTarget, compilationPurpose: String) :
|
internal abstract class JsIrCompilationDependencyHolder @Inject constructor(target: KotlinTarget, compilationPurpose: String) :
|
||||||
JsCompilationDependenciesHolder(target, compilationPurpose) {
|
JsCompilationDependenciesHolder(target, compilationPurpose) {
|
||||||
override val disambiguationClassifierInPlatform: String?
|
override val disambiguationClassifierInPlatform: String?
|
||||||
|
|||||||
-53
@@ -29,10 +29,6 @@ import org.jetbrains.kotlin.gradle.plugin.*
|
|||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.hasKpmModel
|
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.hasKpmModel
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsSubTargetContainerDsl
|
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsSubTargetContainerDsl
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsSubTargetDsl
|
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsSubTargetDsl
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.dukat.DukatCompilationResolverPlugin
|
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.dukat.DukatCompilationResolverPlugin.Companion.shouldDependOnDukatIntegrationTask
|
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.dukat.DukatCompilationResolverPlugin.Companion.shouldLegacyUseIrTargetDukatIntegrationTask
|
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.dukat.ExternalsOutputFormat
|
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget
|
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.npm.npmProject
|
import org.jetbrains.kotlin.gradle.targets.js.npm.npmProject
|
||||||
import org.jetbrains.kotlin.gradle.tasks.dependsOn
|
import org.jetbrains.kotlin.gradle.tasks.dependsOn
|
||||||
@@ -195,10 +191,6 @@ abstract class AbstractKotlinTarget(
|
|||||||
classifierPrefix: String? = null
|
classifierPrefix: String? = null
|
||||||
): PublishArtifact {
|
): PublishArtifact {
|
||||||
val sourcesJarTask = sourcesJarTask(producingCompilation, componentName, artifactNameAppendix)
|
val sourcesJarTask = sourcesJarTask(producingCompilation, componentName, artifactNameAppendix)
|
||||||
linkToSourcesProducedByDukatTasks(
|
|
||||||
producingCompilation,
|
|
||||||
sourcesJarTask
|
|
||||||
)
|
|
||||||
val sourceArtifactConfigurationName = producingCompilation.disambiguateName("sourceArtifacts")
|
val sourceArtifactConfigurationName = producingCompilation.disambiguateName("sourceArtifacts")
|
||||||
|
|
||||||
return with(producingCompilation.target.project) {
|
return with(producingCompilation.target.project) {
|
||||||
@@ -216,51 +208,6 @@ abstract class AbstractKotlinTarget(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun linkToSourcesProducedByDukatTasks(
|
|
||||||
producingCompilation: KotlinCompilation<*>,
|
|
||||||
sourcesJarTask: TaskProvider<Jar>
|
|
||||||
) {
|
|
||||||
if (producingCompilation is KotlinJsCompilation) {
|
|
||||||
val configAction: (KotlinJsSubTargetDsl) -> Unit = {
|
|
||||||
val dukatGenerateExternalsTaskName = producingCompilation.npmProject.compilation
|
|
||||||
.disambiguateName(
|
|
||||||
DukatCompilationResolverPlugin.GENERATE_EXTERNALS_INTEGRATED_TASK_SIMPLE_NAME
|
|
||||||
)
|
|
||||||
|
|
||||||
with(producingCompilation.target.project) {
|
|
||||||
val dukatTask = tasks.named(dukatGenerateExternalsTaskName)
|
|
||||||
sourcesJarTask.dependsOn(dukatTask)
|
|
||||||
|
|
||||||
plugins.withId("maven-publish") {
|
|
||||||
tasks
|
|
||||||
.matching { it.name == "sourcesJar" }
|
|
||||||
.configureEach { it.dependsOn(dukatTask) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// See DukatCompilationResolverPlugin for details
|
|
||||||
if (producingCompilation.shouldDependOnDukatIntegrationTask()) {
|
|
||||||
(producingCompilation.target as KotlinJsSubTargetContainerDsl)
|
|
||||||
.whenNodejsConfigured(configAction)
|
|
||||||
(producingCompilation.target as KotlinJsSubTargetContainerDsl)
|
|
||||||
.whenBrowserConfigured(configAction)
|
|
||||||
} else if (producingCompilation.shouldLegacyUseIrTargetDukatIntegrationTask()) {
|
|
||||||
(producingCompilation.target as KotlinJsIrTarget)
|
|
||||||
.legacyTarget
|
|
||||||
?.compilations
|
|
||||||
?.named(producingCompilation.name) {
|
|
||||||
if (it.externalsOutputFormat == ExternalsOutputFormat.SOURCE) {
|
|
||||||
(producingCompilation.target as KotlinJsSubTargetContainerDsl)
|
|
||||||
.whenNodejsConfigured(configAction)
|
|
||||||
(producingCompilation.target as KotlinJsSubTargetContainerDsl)
|
|
||||||
.whenBrowserConfigured(configAction)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
internal val publicationConfigureActions: DomainObjectSet<Action<MavenPublication>> = project
|
internal val publicationConfigureActions: DomainObjectSet<Action<MavenPublication>> = project
|
||||||
.objects
|
.objects
|
||||||
|
|||||||
-9
@@ -14,9 +14,7 @@ import org.jetbrains.kotlin.gradle.dsl.*
|
|||||||
import org.jetbrains.kotlin.gradle.plugin.HasCompilerOptions
|
import org.jetbrains.kotlin.gradle.plugin.HasCompilerOptions
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilationWithResources
|
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilationWithResources
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
|
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
|
||||||
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider
|
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsSubTargetContainerDsl
|
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsSubTargetContainerDsl
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.dukat.ExternalsOutputFormat
|
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.ir.JsBinary
|
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.ir.KotlinJsBinaryContainer
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.npm.PackageJson
|
import org.jetbrains.kotlin.gradle.targets.js.npm.PackageJson
|
||||||
@@ -34,13 +32,6 @@ abstract class KotlinJsCompilation @Inject internal constructor(
|
|||||||
final override val compilerOptions: HasCompilerOptions<KotlinJsCompilerOptions>
|
final override val compilerOptions: HasCompilerOptions<KotlinJsCompilerOptions>
|
||||||
get() = super.compilerOptions as HasCompilerOptions<KotlinJsCompilerOptions>
|
get() = super.compilerOptions as HasCompilerOptions<KotlinJsCompilerOptions>
|
||||||
|
|
||||||
private val kotlinProperties = PropertiesProvider(target.project)
|
|
||||||
|
|
||||||
internal open val externalsOutputFormat: ExternalsOutputFormat
|
|
||||||
get() = kotlinProperties.externalsOutputFormat ?: defaultExternalsOutputFormat
|
|
||||||
|
|
||||||
internal open val defaultExternalsOutputFormat: ExternalsOutputFormat = ExternalsOutputFormat.SOURCE
|
|
||||||
|
|
||||||
val binaries: KotlinJsBinaryContainer =
|
val binaries: KotlinJsBinaryContainer =
|
||||||
target.project.objects.newInstance(
|
target.project.objects.newInstance(
|
||||||
KotlinJsBinaryContainer::class.java,
|
KotlinJsBinaryContainer::class.java,
|
||||||
|
|||||||
-86
@@ -1,86 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.jetbrains.kotlin.gradle.targets.js.dukat
|
|
||||||
|
|
||||||
import org.jetbrains.kotlin.gradle.plugin.statistics.KotlinBuildStatsService
|
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.npm.NpmDependency
|
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.npm.NpmDependency.Scope.NORMAL
|
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.npm.NpmDependency.Scope.OPTIONAL
|
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.npm.NpmProject
|
|
||||||
import org.jetbrains.kotlin.statistics.metrics.BooleanMetrics
|
|
||||||
import java.io.File
|
|
||||||
|
|
||||||
class DtsResolver(val npmProject: NpmProject) {
|
|
||||||
private val typeModules = npmProject.modules.copy(
|
|
||||||
// https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html
|
|
||||||
packageJsonEntries = listOf("types", "typings"),
|
|
||||||
indexFileSuffixes = listOf(".d.ts")
|
|
||||||
)
|
|
||||||
|
|
||||||
fun getAllDts(
|
|
||||||
externalNpmDependencies: Collection<NpmDependency>,
|
|
||||||
considerGeneratingFlag: Boolean = true
|
|
||||||
): List<Dts> {
|
|
||||||
val buildStatsService = KotlinBuildStatsService.getInstance()
|
|
||||||
return externalNpmDependencies
|
|
||||||
.asSequence()
|
|
||||||
.filter { !considerGeneratingFlag || it.generateExternals }
|
|
||||||
.filter { it.scope == NORMAL || it.scope == OPTIONAL }
|
|
||||||
.mapNotNullTo(mutableSetOf()) { dependency ->
|
|
||||||
getDtsFromDependency(dependency, considerGeneratingFlag)
|
|
||||||
}
|
|
||||||
.sortedBy { it.inputKey }
|
|
||||||
.toList()
|
|
||||||
.also {
|
|
||||||
buildStatsService?.report(BooleanMetrics.JS_GENERATE_EXTERNALS, it.isNotEmpty())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getDtsFromDependency(
|
|
||||||
dependency: NpmDependency,
|
|
||||||
considerGeneratingFlag: Boolean
|
|
||||||
): Dts? {
|
|
||||||
val dts = typeModules.resolve(dependency.key)
|
|
||||||
?.let { file ->
|
|
||||||
Dts(file.canonicalFile, dependency)
|
|
||||||
}
|
|
||||||
if (dts == null && considerGeneratingFlag) {
|
|
||||||
warningOnMissedDTs(dependency)
|
|
||||||
}
|
|
||||||
return dts
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun warningOnMissedDTs(dependency: NpmDependency) {
|
|
||||||
npmProject.project.logger.warn(
|
|
||||||
"""
|
|
||||||
No `types` or `typings` found for '$dependency'.
|
|
||||||
To find d.ts for dependency, fields `types` and `typings` should be declared in `package.json`
|
|
||||||
""".trimIndent()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
class Dts(val file: File, val npmDependency: NpmDependency) {
|
|
||||||
val inputKey: String
|
|
||||||
get() = npmDependency.key + "@" + npmDependency.resolvedVersion + "#" + npmDependency.integrity
|
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
|
||||||
if (this === other) return true
|
|
||||||
if (javaClass != other?.javaClass) return false
|
|
||||||
|
|
||||||
other as Dts
|
|
||||||
|
|
||||||
if (file != other.file) return false
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
|
||||||
return file.hashCode()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun toString(): String = inputKey
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-168
@@ -1,168 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.jetbrains.kotlin.gradle.targets.js.dukat
|
|
||||||
|
|
||||||
import org.gradle.api.internal.project.ProjectInternal
|
|
||||||
import org.gradle.api.tasks.TaskProvider
|
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation
|
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.disambiguateName
|
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTarget
|
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget
|
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.npm.NpmDependency
|
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.npm.NpmProject
|
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.npm.isCompatibleArchive
|
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.npm.plugins.CompilationResolverPlugin
|
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.npm.resolved.KotlinRootNpmResolution
|
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.npm.resolver.KotlinCompilationNpmResolver
|
|
||||||
import org.jetbrains.kotlin.gradle.tasks.dependsOn
|
|
||||||
import org.jetbrains.kotlin.gradle.tasks.registerTask
|
|
||||||
import org.jetbrains.kotlin.gradle.utils.unavailableValueError
|
|
||||||
|
|
||||||
internal class DukatCompilationResolverPlugin(
|
|
||||||
@Transient
|
|
||||||
private val resolver: KotlinCompilationNpmResolver
|
|
||||||
) : CompilationResolverPlugin {
|
|
||||||
val project get() = resolver.project
|
|
||||||
val nodeJs get() = resolver.nodeJs
|
|
||||||
private val nodeJs_ get() = nodeJs ?: unavailableValueError("nodeJs")
|
|
||||||
val versions by lazy { nodeJs_.versions }
|
|
||||||
val npmProject by lazy { resolver.npmProject }
|
|
||||||
val compilation get() = npmProject.compilation
|
|
||||||
val compilationName by lazy {
|
|
||||||
compilation.disambiguatedName
|
|
||||||
}
|
|
||||||
val legacyTargetReuseIrTask by lazy {
|
|
||||||
val target = compilation.target
|
|
||||||
target is KotlinJsTarget && (target.mixedMode && externalsOutputFormat == ExternalsOutputFormat.SOURCE)
|
|
||||||
}
|
|
||||||
val externalsOutputFormat by lazy {
|
|
||||||
compilation.externalsOutputFormat
|
|
||||||
}
|
|
||||||
val integratedTaskName = npmProject.compilation.disambiguateName(GENERATE_EXTERNALS_INTEGRATED_TASK_SIMPLE_NAME)
|
|
||||||
val separateTaskName = npmProject.compilation.disambiguateName(GENERATE_EXTERNALS_TASK_SIMPLE_NAME)
|
|
||||||
|
|
||||||
private fun registerIntegratedTask(): TaskProvider<IntegratedDukatTask> {
|
|
||||||
return project.registerTask(
|
|
||||||
integratedTaskName,
|
|
||||||
listOf(compilation)
|
|
||||||
) {
|
|
||||||
it.group = DUKAT_TASK_GROUP
|
|
||||||
it.description = "Integrated generation Kotlin/JS external declarations for .d.ts files in $compilation"
|
|
||||||
it.externalsOutputFormat = externalsOutputFormat
|
|
||||||
it.dependsOn(
|
|
||||||
nodeJs_.npmInstallTaskProvider,
|
|
||||||
nodeJs_.storeYarnLockTaskProvider,
|
|
||||||
npmProject.packageJsonTask
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
init {
|
|
||||||
val externalsOutputFormat = compilation.externalsOutputFormat
|
|
||||||
|
|
||||||
gradleModelPostProcess(externalsOutputFormat, npmProject)
|
|
||||||
|
|
||||||
var integratedTask: TaskProvider<IntegratedDukatTask>? = null
|
|
||||||
if (compilation.shouldDependOnDukatIntegrationTask()) {
|
|
||||||
val task = integratedTask ?: registerIntegratedTask().also { integratedTask = it }
|
|
||||||
compilation.compileKotlinTaskProvider.dependsOn(task)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (compilation.shouldLegacyUseIrTargetDukatIntegrationTask()) {
|
|
||||||
(compilation.target as KotlinJsIrTarget).legacyTarget?.compilations?.named(compilation.name) {
|
|
||||||
val task = integratedTask ?: registerIntegratedTask()
|
|
||||||
if (it.externalsOutputFormat == ExternalsOutputFormat.SOURCE) {
|
|
||||||
it.compileKotlinTaskProvider.dependsOn(task)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
project.registerTask<SeparateDukatTask>(
|
|
||||||
separateTaskName,
|
|
||||||
listOf(compilation)
|
|
||||||
) {
|
|
||||||
it.group = DUKAT_TASK_GROUP
|
|
||||||
it.description = "Generate Kotlin/JS external declarations for .d.ts files of all NPM dependencies in ${compilation}"
|
|
||||||
it.dependsOn(
|
|
||||||
nodeJs_.npmInstallTaskProvider,
|
|
||||||
nodeJs_.storeYarnLockTaskProvider,
|
|
||||||
npmProject.packageJsonTask
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hookDependencies(
|
|
||||||
internalDependencies: Set<KotlinCompilationNpmResolver.InternalDependency>,
|
|
||||||
internalCompositeDependencies: Set<KotlinCompilationNpmResolver.CompositeDependency>,
|
|
||||||
externalGradleDependencies: Set<KotlinCompilationNpmResolver.ExternalGradleDependency>,
|
|
||||||
externalNpmDependencies: Set<NpmDependency>,
|
|
||||||
fileCollectionDependencies: Set<KotlinCompilationNpmResolver.FileCollectionExternalGradleDependency>
|
|
||||||
) {
|
|
||||||
if (nodeJs_.experimental.discoverTypes) {
|
|
||||||
// todo: discoverTypes
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun executeDukatIfNeeded(
|
|
||||||
packageJsonIsUpdated: Boolean,
|
|
||||||
resolution: KotlinRootNpmResolution
|
|
||||||
) {
|
|
||||||
val externalNpmDependencies = resolution[project.path][compilationName].externalNpmDependencies
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (legacyTargetReuseIrTask) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
DukatExecutor(
|
|
||||||
versions,
|
|
||||||
DtsResolver(npmProject).getAllDts(externalNpmDependencies),
|
|
||||||
externalsOutputFormat,
|
|
||||||
npmProject,
|
|
||||||
packageJsonIsUpdated,
|
|
||||||
operation = compilation.name + " > " + DukatExecutor.OPERATION,
|
|
||||||
compareInputs = true
|
|
||||||
).execute((project as ProjectInternal).services)
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
const val VERSION = "3"
|
|
||||||
internal const val GENERATE_EXTERNALS_INTEGRATED_TASK_SIMPLE_NAME = "generateExternalsIntegrated"
|
|
||||||
internal const val GENERATE_EXTERNALS_TASK_SIMPLE_NAME = "generateExternals"
|
|
||||||
|
|
||||||
internal fun KotlinJsCompilation.shouldDependOnDukatIntegrationTask(): Boolean = with(target) {
|
|
||||||
this is KotlinJsIrTarget ||
|
|
||||||
(this is KotlinJsTarget &&
|
|
||||||
(!mixedMode || externalsOutputFormat != ExternalsOutputFormat.SOURCE)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
internal fun KotlinJsCompilation.shouldLegacyUseIrTargetDukatIntegrationTask(): Boolean =
|
|
||||||
with(target) {
|
|
||||||
this is KotlinJsIrTarget && legacyTarget != null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
internal fun gradleModelPostProcess(
|
|
||||||
externalsOutputFormat: ExternalsOutputFormat,
|
|
||||||
npmProject: NpmProject
|
|
||||||
) {
|
|
||||||
val compilation = npmProject.compilation
|
|
||||||
val project = npmProject.project
|
|
||||||
when (externalsOutputFormat) {
|
|
||||||
ExternalsOutputFormat.SOURCE -> compilation.defaultSourceSet.kotlin.srcDir(npmProject.externalsDir)
|
|
||||||
ExternalsOutputFormat.BINARY -> {
|
|
||||||
project.dependencies.add(
|
|
||||||
compilation.compileDependencyConfigurationName,
|
|
||||||
project.fileTree(npmProject.externalsDir).include {
|
|
||||||
it.file.isCompatibleArchive
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-64
@@ -1,64 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.jetbrains.kotlin.gradle.targets.js.dukat
|
|
||||||
|
|
||||||
import org.gradle.internal.service.ServiceRegistry
|
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.NpmVersions
|
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.npm.NpmProject
|
|
||||||
|
|
||||||
class DukatExecutor(
|
|
||||||
val npmVersions: NpmVersions,
|
|
||||||
val typeDefinitions: List<DtsResolver.Dts>,
|
|
||||||
val externalsOutputFormat: ExternalsOutputFormat,
|
|
||||||
val npmProject: NpmProject,
|
|
||||||
val packageJsonIsUpdated: Boolean,
|
|
||||||
val operation: String = OPERATION,
|
|
||||||
val compareInputs: Boolean = true
|
|
||||||
) {
|
|
||||||
companion object {
|
|
||||||
const val OPERATION = "Generating Kotlin/JS external declarations"
|
|
||||||
}
|
|
||||||
|
|
||||||
val versionFile = npmProject.externalsDirRoot.resolve("version.txt")
|
|
||||||
val version = DukatCompilationResolverPlugin.VERSION + ", " + npmVersions.dukat.version
|
|
||||||
val prevVersion = if (versionFile.exists()) versionFile.readText() else null
|
|
||||||
|
|
||||||
val inputsFile = npmProject.externalsDirRoot.resolve("inputs.txt")
|
|
||||||
|
|
||||||
val shouldSkip: Boolean
|
|
||||||
get() = inputsFile.isFile && prevVersion == version && !packageJsonIsUpdated
|
|
||||||
|
|
||||||
fun execute(services: ServiceRegistry) {
|
|
||||||
if (typeDefinitions.isEmpty()) {
|
|
||||||
npmProject.externalsDirRoot.deleteRecursively()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// delete file to run visit on error even without package.json updates
|
|
||||||
versionFile.delete()
|
|
||||||
|
|
||||||
npmProject.externalsDirRoot.mkdirs()
|
|
||||||
val inputs = "$externalsOutputFormat: " + typeDefinitions.joinToString("\n") { it.inputKey }
|
|
||||||
|
|
||||||
if (!compareInputs || !inputsFile.isFile || inputsFile.readText() != inputs) {
|
|
||||||
// delete file to run visit on error even without package.json updates
|
|
||||||
inputsFile.delete()
|
|
||||||
|
|
||||||
npmProject.externalsDir.deleteRecursively()
|
|
||||||
DukatRunner(
|
|
||||||
npmProject,
|
|
||||||
typeDefinitions.map { it.file },
|
|
||||||
externalsOutputFormat,
|
|
||||||
npmProject.externalsDir,
|
|
||||||
operation = operation
|
|
||||||
).execute(services)
|
|
||||||
|
|
||||||
inputsFile.writeText(inputs)
|
|
||||||
}
|
|
||||||
|
|
||||||
versionFile.writeText(version)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-30
@@ -1,30 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.jetbrains.kotlin.gradle.targets.js.dukat
|
|
||||||
|
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.npm.plugins.RootResolverPlugin
|
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.npm.resolved.KotlinRootNpmResolution
|
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.npm.resolver.KotlinCompilationNpmResolver
|
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.npm.resolver.KotlinRootNpmResolver
|
|
||||||
|
|
||||||
internal class DukatRootResolverPlugin(val forceFullResolve: Boolean) : RootResolverPlugin {
|
|
||||||
val compilations = mutableListOf<DukatCompilationResolverPlugin>()
|
|
||||||
|
|
||||||
override fun createCompilationResolverPlugins(resolver: KotlinCompilationNpmResolver): List<DukatCompilationResolverPlugin> {
|
|
||||||
val plugin = DukatCompilationResolverPlugin(resolver)
|
|
||||||
compilations.add(plugin)
|
|
||||||
return listOf(plugin)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun close(resolution: KotlinRootNpmResolution) {
|
|
||||||
if (forceFullResolve) {
|
|
||||||
// inside idea import
|
|
||||||
compilations.forEach {
|
|
||||||
it.executeDukatIfNeeded(true, resolution)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-55
@@ -1,55 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.jetbrains.kotlin.gradle.targets.js.dukat
|
|
||||||
|
|
||||||
import org.gradle.internal.service.ServiceRegistry
|
|
||||||
import org.jetbrains.kotlin.gradle.internal.execWithProgress
|
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.npm.NpmProject
|
|
||||||
import java.io.File
|
|
||||||
|
|
||||||
class DukatRunner(
|
|
||||||
val npmProject: NpmProject,
|
|
||||||
val dTsFiles: Collection<File>,
|
|
||||||
val externalsOutputFormat: ExternalsOutputFormat,
|
|
||||||
val destDir: File,
|
|
||||||
val qualifiedPackageName: String? = null,
|
|
||||||
val jsInteropJvmEngine: String? = null,
|
|
||||||
val operation: String = "Generating Kotlin/JS external declarations"
|
|
||||||
) {
|
|
||||||
fun execute(services: ServiceRegistry) {
|
|
||||||
services.execWithProgress(operation) { exec ->
|
|
||||||
val args = mutableListOf<String>()
|
|
||||||
|
|
||||||
if (externalsOutputFormat == ExternalsOutputFormat.BINARY) {
|
|
||||||
args.add("--descriptors-jar")
|
|
||||||
}
|
|
||||||
|
|
||||||
val qualifiedPackageName = qualifiedPackageName
|
|
||||||
if (qualifiedPackageName != null) {
|
|
||||||
args.add("-p")
|
|
||||||
args.add(qualifiedPackageName)
|
|
||||||
}
|
|
||||||
|
|
||||||
args.add("-d")
|
|
||||||
args.add(destDir.absolutePath)
|
|
||||||
|
|
||||||
val jsInteropJvmEngine = jsInteropJvmEngine
|
|
||||||
if (jsInteropJvmEngine != null) {
|
|
||||||
args.add("-js")
|
|
||||||
args.add(jsInteropJvmEngine)
|
|
||||||
}
|
|
||||||
|
|
||||||
args.addAll(dTsFiles.map { it.absolutePath })
|
|
||||||
|
|
||||||
npmProject.useTool(
|
|
||||||
exec,
|
|
||||||
"dukat/bin/dukat-cli.js",
|
|
||||||
listOf(),
|
|
||||||
args
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-122
@@ -1,122 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.jetbrains.kotlin.gradle.targets.js.dukat
|
|
||||||
|
|
||||||
import org.gradle.api.DefaultTask
|
|
||||||
import org.gradle.api.tasks.*
|
|
||||||
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.KotlinNpmResolutionManager
|
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.npm.RequiresNpmDependencies
|
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.npm.npmProject
|
|
||||||
import java.io.File
|
|
||||||
|
|
||||||
abstract class DukatTask(
|
|
||||||
@Internal
|
|
||||||
@Transient
|
|
||||||
override val compilation: KotlinJsCompilation
|
|
||||||
) : DefaultTask(), RequiresNpmDependencies {
|
|
||||||
@get:Internal
|
|
||||||
@Transient
|
|
||||||
protected val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
|
||||||
|
|
||||||
private val resolutionManager = nodeJs.npmResolutionManager
|
|
||||||
|
|
||||||
@get:Internal
|
|
||||||
val compilationName by lazy {
|
|
||||||
compilation.disambiguatedName
|
|
||||||
}
|
|
||||||
|
|
||||||
private val npmProject by lazy { compilation.npmProject }
|
|
||||||
|
|
||||||
@get:Internal
|
|
||||||
override val nodeModulesRequired: Boolean
|
|
||||||
get() = true
|
|
||||||
|
|
||||||
@get:Internal
|
|
||||||
override val requiredNpmDependencies: Set<RequiredKotlinJsDependency> by lazy {
|
|
||||||
emptySet<RequiredKotlinJsDependency>()
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* [ExternalsOutputFormat] what to generate, sources or binaries
|
|
||||||
*/
|
|
||||||
@Input
|
|
||||||
var externalsOutputFormat: ExternalsOutputFormat = ExternalsOutputFormat.SOURCE
|
|
||||||
|
|
||||||
private val projectPath = project.path
|
|
||||||
|
|
||||||
private val compilationResolution
|
|
||||||
get() = resolutionManager.requireInstalled(
|
|
||||||
services,
|
|
||||||
logger
|
|
||||||
)?.get(projectPath)?.get(compilationName)
|
|
||||||
?: throw (resolutionManager.state as KotlinNpmResolutionManager.ResolutionState.Error).wrappedException
|
|
||||||
|
|
||||||
@get:Internal
|
|
||||||
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)
|
|
||||||
*/
|
|
||||||
@Input
|
|
||||||
@Optional
|
|
||||||
var qualifiedPackageName: String? = null
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Collection of d.ts files
|
|
||||||
*/
|
|
||||||
@get:Internal
|
|
||||||
val dTsFiles: List<File>
|
|
||||||
get() = dts.map { it.file }
|
|
||||||
|
|
||||||
@get:Input
|
|
||||||
val inputs
|
|
||||||
get() = dts.map { it.inputKey }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Destination directory for files with converted declarations
|
|
||||||
*/
|
|
||||||
@get:OutputDirectory
|
|
||||||
abstract val destinationDir: File
|
|
||||||
|
|
||||||
@get:Internal
|
|
||||||
internal abstract val considerGeneratingFlag: Boolean
|
|
||||||
|
|
||||||
@get:Internal
|
|
||||||
val operation: String = "Generating Kotlin/JS external declarations"
|
|
||||||
|
|
||||||
@TaskAction
|
|
||||||
open fun run() {
|
|
||||||
resolutionManager.checkRequiredDependencies(this)
|
|
||||||
|
|
||||||
destinationDir.deleteRecursively()
|
|
||||||
|
|
||||||
if (dTsFiles.isEmpty()) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
DukatRunner(
|
|
||||||
npmProject,
|
|
||||||
dTsFiles,
|
|
||||||
externalsOutputFormat,
|
|
||||||
destinationDir,
|
|
||||||
qualifiedPackageName,
|
|
||||||
null,
|
|
||||||
operation
|
|
||||||
).execute(services)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
internal const val DUKAT_TASK_GROUP = "Dukat"
|
|
||||||
-18
@@ -1,18 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.jetbrains.kotlin.gradle.targets.js.dukat
|
|
||||||
|
|
||||||
enum class ExternalsOutputFormat {
|
|
||||||
SOURCE,
|
|
||||||
BINARY;
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
fun byArgumentOrNull(argument: String): ExternalsOutputFormat? =
|
|
||||||
values().firstOrNull { it.name.equals(argument, ignoreCase = true) }
|
|
||||||
|
|
||||||
const val externalsOutputFormatProperty = "kotlin.js.externals.output.format"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-53
@@ -1,53 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.jetbrains.kotlin.gradle.targets.js.dukat
|
|
||||||
|
|
||||||
import org.gradle.api.tasks.OutputDirectory
|
|
||||||
import org.gradle.api.tasks.TaskAction
|
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation
|
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.npm.npmProject
|
|
||||||
import java.io.File
|
|
||||||
import javax.inject.Inject
|
|
||||||
|
|
||||||
open class IntegratedDukatTask
|
|
||||||
@Inject
|
|
||||||
constructor(
|
|
||||||
compilation: KotlinJsCompilation
|
|
||||||
) : DukatTask(compilation) {
|
|
||||||
init {
|
|
||||||
onlyIf {
|
|
||||||
dts.isNotEmpty() || npmProject.externalsDirRoot.resolve("inputs.txt").exists()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override val considerGeneratingFlag: Boolean = true
|
|
||||||
|
|
||||||
private val npmProject = compilation.npmProject
|
|
||||||
|
|
||||||
private val versions by lazy {
|
|
||||||
nodeJs.versions
|
|
||||||
}
|
|
||||||
|
|
||||||
@get:OutputDirectory
|
|
||||||
override val destinationDir: File by lazy {
|
|
||||||
npmProject.externalsDir
|
|
||||||
}
|
|
||||||
|
|
||||||
private val executor
|
|
||||||
get() = DukatExecutor(
|
|
||||||
versions,
|
|
||||||
dts,
|
|
||||||
externalsOutputFormat,
|
|
||||||
npmProject,
|
|
||||||
true,
|
|
||||||
compareInputs = false
|
|
||||||
)
|
|
||||||
|
|
||||||
@TaskAction
|
|
||||||
override fun run() {
|
|
||||||
executor.execute(services)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-30
@@ -1,30 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
open class SeparateDukatTask
|
|
||||||
@Inject
|
|
||||||
constructor(
|
|
||||||
compilation: KotlinJsCompilation
|
|
||||||
) : DukatTask(compilation) {
|
|
||||||
override val considerGeneratingFlag: Boolean = false
|
|
||||||
|
|
||||||
override val requiredNpmDependencies: Set<RequiredKotlinJsDependency> by lazy {
|
|
||||||
emptySet()
|
|
||||||
}
|
|
||||||
|
|
||||||
@get:OutputDirectory
|
|
||||||
override var destinationDir: File by property {
|
|
||||||
project.projectDir.resolve("externals")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+1
-8
@@ -5,17 +5,10 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.gradle.targets.js.ir
|
package org.jetbrains.kotlin.gradle.targets.js.ir
|
||||||
|
|
||||||
import org.gradle.api.file.SourceDirectorySet
|
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.JsIrCompilationDetails
|
import org.jetbrains.kotlin.gradle.plugin.mpp.JsIrCompilationDetails
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation
|
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.dukat.ExternalsOutputFormat
|
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
abstract class KotlinJsIrCompilation @Inject internal constructor(
|
abstract class KotlinJsIrCompilation @Inject internal constructor(
|
||||||
compilationDetails: JsIrCompilationDetails
|
compilationDetails: JsIrCompilationDetails
|
||||||
) : KotlinJsCompilation(compilationDetails) {
|
) : KotlinJsCompilation(compilationDetails)
|
||||||
|
|
||||||
override val externalsOutputFormat: ExternalsOutputFormat = ExternalsOutputFormat.SOURCE
|
|
||||||
|
|
||||||
internal val allSources: MutableSet<SourceDirectorySet> = mutableSetOf()
|
|
||||||
}
|
|
||||||
-1
@@ -179,7 +179,6 @@ class KotlinNpmResolutionManager(@Transient private val nodeJsSettings: NodeJsRo
|
|||||||
val resolution = installation
|
val resolution = installation
|
||||||
.install(forceUpToDate, args, services, logger)
|
.install(forceUpToDate, args, services, logger)
|
||||||
state = ResolutionState.Installed(resolution)
|
state = ResolutionState.Installed(resolution)
|
||||||
installation.closePlugins(resolution)
|
|
||||||
resolution
|
resolution
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
state = ResolutionState.Error(e)
|
state = ResolutionState.Error(e)
|
||||||
|
|||||||
-20
@@ -1,20 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.jetbrains.kotlin.gradle.targets.js.npm.plugins
|
|
||||||
|
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.npm.NpmDependency
|
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.npm.resolver.KotlinCompilationNpmResolver
|
|
||||||
import java.io.Serializable
|
|
||||||
|
|
||||||
internal interface CompilationResolverPlugin : Serializable {
|
|
||||||
fun hookDependencies(
|
|
||||||
internalDependencies: Set<KotlinCompilationNpmResolver.InternalDependency>,
|
|
||||||
internalCompositeDependencies: Set<KotlinCompilationNpmResolver.CompositeDependency>,
|
|
||||||
externalGradleDependencies: Set<KotlinCompilationNpmResolver.ExternalGradleDependency>,
|
|
||||||
externalNpmDependencies: Set<NpmDependency>,
|
|
||||||
fileCollectionDependencies: Set<KotlinCompilationNpmResolver.FileCollectionExternalGradleDependency>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
-15
@@ -1,15 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.jetbrains.kotlin.gradle.targets.js.npm.plugins
|
|
||||||
|
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.npm.resolved.KotlinRootNpmResolution
|
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.npm.resolver.KotlinCompilationNpmResolver
|
|
||||||
import java.io.Serializable
|
|
||||||
|
|
||||||
internal interface RootResolverPlugin : Serializable {
|
|
||||||
fun createCompilationResolverPlugins(resolver: KotlinCompilationNpmResolver): List<CompilationResolverPlugin>
|
|
||||||
fun close(resolution: KotlinRootNpmResolution)
|
|
||||||
}
|
|
||||||
-21
@@ -31,7 +31,6 @@ import org.jetbrains.kotlin.gradle.plugin.usesPlatformOf
|
|||||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget
|
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.npm.*
|
import org.jetbrains.kotlin.gradle.targets.js.npm.*
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.npm.NpmProject.Companion.PACKAGE_JSON
|
import org.jetbrains.kotlin.gradle.targets.js.npm.NpmProject.Companion.PACKAGE_JSON
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.npm.plugins.CompilationResolverPlugin
|
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.npm.resolved.KotlinCompilationNpmResolution
|
import org.jetbrains.kotlin.gradle.targets.js.npm.resolved.KotlinCompilationNpmResolution
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinPackageJsonTask
|
import org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinPackageJsonTask
|
||||||
import org.jetbrains.kotlin.gradle.tasks.registerTask
|
import org.jetbrains.kotlin.gradle.tasks.registerTask
|
||||||
@@ -97,16 +96,6 @@ internal class KotlinCompilationNpmResolver(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transient
|
|
||||||
val plugins: List<CompilationResolverPlugin> = projectResolver.resolver.plugins
|
|
||||||
.flatMap {
|
|
||||||
if (compilation.isMain()) {
|
|
||||||
it.createCompilationResolverPlugins(this)
|
|
||||||
} else {
|
|
||||||
emptyList()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun toString(): String = "KotlinCompilationNpmResolver(${npmProject.name})"
|
override fun toString(): String = "KotlinCompilationNpmResolver(${npmProject.name})"
|
||||||
|
|
||||||
@delegate:Transient
|
@delegate:Transient
|
||||||
@@ -279,16 +268,6 @@ internal class KotlinCompilationNpmResolver(
|
|||||||
task.from(publicPackageJsonTaskHolder)
|
task.from(publicPackageJsonTaskHolder)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
plugins.forEach {
|
|
||||||
it.hookDependencies(
|
|
||||||
internalDependencies,
|
|
||||||
internalCompositeDependencies,
|
|
||||||
externalGradleDependencies,
|
|
||||||
externalNpmDependencies,
|
|
||||||
fileCollectionDependencies
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun visitDependency(dependency: ResolvedDependency) {
|
private fun visitDependency(dependency: ResolvedDependency) {
|
||||||
|
|||||||
-17
@@ -12,12 +12,10 @@ import org.gradle.internal.service.ServiceRegistry
|
|||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
|
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation
|
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.isMain
|
import org.jetbrains.kotlin.gradle.plugin.mpp.isMain
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.dukat.DukatRootResolverPlugin
|
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrCompilation
|
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrCompilation
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension
|
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.nodejs.TasksRequirements
|
import org.jetbrains.kotlin.gradle.targets.js.nodejs.TasksRequirements
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.npm.*
|
import org.jetbrains.kotlin.gradle.targets.js.npm.*
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.npm.plugins.RootResolverPlugin
|
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.npm.resolved.KotlinCompilationNpmResolution
|
import org.jetbrains.kotlin.gradle.targets.js.npm.resolved.KotlinCompilationNpmResolution
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.npm.resolved.KotlinProjectNpmResolution
|
import org.jetbrains.kotlin.gradle.targets.js.npm.resolved.KotlinProjectNpmResolution
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.npm.resolved.KotlinRootNpmResolution
|
import org.jetbrains.kotlin.gradle.targets.js.npm.resolved.KotlinRootNpmResolution
|
||||||
@@ -98,11 +96,6 @@ class KotlinRootNpmResolver internal constructor(
|
|||||||
internal val compositeNodeModules: CompositeNodeModulesCache
|
internal val compositeNodeModules: CompositeNodeModulesCache
|
||||||
get() = compositeNodeModulesProvider.get()
|
get() = compositeNodeModulesProvider.get()
|
||||||
|
|
||||||
@Transient
|
|
||||||
private val plugins_: MutableList<RootResolverPlugin>? = mutableListOf<RootResolverPlugin>().also {
|
|
||||||
it.add(DukatRootResolverPlugin(forceFullResolve))
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transient
|
@Transient
|
||||||
private val projectResolvers_: MutableMap<String, KotlinProjectNpmResolver>? = mutableMapOf()
|
private val projectResolvers_: MutableMap<String, KotlinProjectNpmResolver>? = mutableMapOf()
|
||||||
|
|
||||||
@@ -129,7 +122,6 @@ class KotlinRootNpmResolver internal constructor(
|
|||||||
KotlinRootNpmResolverStateHolder::class.qualifiedName,
|
KotlinRootNpmResolverStateHolder::class.qualifiedName,
|
||||||
KotlinRootNpmResolverStateHolder::class.java
|
KotlinRootNpmResolverStateHolder::class.java
|
||||||
) { service ->
|
) { service ->
|
||||||
service.parameters.plugins.set(plugins_)
|
|
||||||
service.parameters.projectResolvers.set(projectResolvers_)
|
service.parameters.projectResolvers.set(projectResolvers_)
|
||||||
service.parameters.packageManager.set(nodeJs_.packageManager)
|
service.parameters.packageManager.set(nodeJs_.packageManager)
|
||||||
service.parameters.yarnEnvironment.set(yarnEnvironment_?.get())
|
service.parameters.yarnEnvironment.set(yarnEnvironment_?.get())
|
||||||
@@ -157,9 +149,6 @@ class KotlinRootNpmResolver internal constructor(
|
|||||||
return projResolvers
|
return projResolvers
|
||||||
}
|
}
|
||||||
|
|
||||||
internal val plugins
|
|
||||||
get() = plugins_ ?: resolverStateHolder.get().parameters.plugins.get()
|
|
||||||
|
|
||||||
private val projectResolvers
|
private val projectResolvers
|
||||||
get() = projectResolvers_ ?: configurationCacheProjectResolvers
|
get() = projectResolvers_ ?: configurationCacheProjectResolvers
|
||||||
|
|
||||||
@@ -304,12 +293,6 @@ class KotlinRootNpmResolver internal constructor(
|
|||||||
return KotlinRootNpmResolution(rootProject, projectResolutions)
|
return KotlinRootNpmResolution(rootProject, projectResolutions)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun closePlugins(resolution: KotlinRootNpmResolution) {
|
|
||||||
plugins.forEach {
|
|
||||||
it.close(resolution)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun removeOutdatedPackages(nodeJs: NodeJsRootExtension, allNpmPackages: List<KotlinCompilationNpmResolution>) {
|
private fun removeOutdatedPackages(nodeJs: NodeJsRootExtension, allNpmPackages: List<KotlinCompilationNpmResolution>) {
|
||||||
|
|||||||
-2
@@ -14,14 +14,12 @@ import org.jetbrains.kotlin.gradle.targets.js.nodejs.TasksRequirements
|
|||||||
import org.jetbrains.kotlin.gradle.targets.js.npm.NpmApi
|
import org.jetbrains.kotlin.gradle.targets.js.npm.NpmApi
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.npm.NpmEnvironment
|
import org.jetbrains.kotlin.gradle.targets.js.npm.NpmEnvironment
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.npm.PackageJson
|
import org.jetbrains.kotlin.gradle.targets.js.npm.PackageJson
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.npm.plugins.RootResolverPlugin
|
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnEnv
|
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnEnv
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnResolution
|
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnResolution
|
||||||
|
|
||||||
// We use this service as a single storage for duplicated data in configuration cache
|
// We use this service as a single storage for duplicated data in configuration cache
|
||||||
abstract class KotlinRootNpmResolverStateHolder : BuildService<KotlinRootNpmResolverStateHolder.Parameters> {
|
abstract class KotlinRootNpmResolverStateHolder : BuildService<KotlinRootNpmResolverStateHolder.Parameters> {
|
||||||
internal interface Parameters : BuildServiceParameters {
|
internal interface Parameters : BuildServiceParameters {
|
||||||
val plugins: ListProperty<RootResolverPlugin>
|
|
||||||
val projectResolvers: MapProperty<String, KotlinProjectNpmResolver>
|
val projectResolvers: MapProperty<String, KotlinProjectNpmResolver>
|
||||||
val packageManager: Property<NpmApi>
|
val packageManager: Property<NpmApi>
|
||||||
val yarnEnvironment: Property<YarnEnv>
|
val yarnEnvironment: Property<YarnEnv>
|
||||||
|
|||||||
Reference in New Issue
Block a user