[Gradle, JS] Make KotlinJsDce, Dukat, KotlinPackageJson cc-compatible
This commit is contained in:
+3
-2
@@ -19,7 +19,6 @@ abstract class DukatTask(
|
||||
override val compilation: KotlinJsCompilation
|
||||
) : DefaultTask(), RequiresNpmDependencies {
|
||||
@get:Internal
|
||||
@Transient
|
||||
protected val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
||||
|
||||
@get:Internal
|
||||
@@ -46,12 +45,14 @@ abstract class DukatTask(
|
||||
@Input
|
||||
var externalsOutputFormat: ExternalsOutputFormat = ExternalsOutputFormat.SOURCE
|
||||
|
||||
private val projectPath = project.path
|
||||
|
||||
private val compilationResolution
|
||||
get() =
|
||||
nodeJs.npmResolutionManager.requireInstalled(
|
||||
services,
|
||||
logger
|
||||
)[project.path][compilationName]
|
||||
)[projectPath][compilationName]
|
||||
|
||||
@get:Internal
|
||||
val dts: List<DtsResolver.Dts>
|
||||
|
||||
+6
-6
@@ -20,22 +20,22 @@ constructor(
|
||||
|
||||
override val considerGeneratingFlag: Boolean = true
|
||||
|
||||
private val npmProject = compilation.npmProject
|
||||
|
||||
@get:OutputDirectory
|
||||
override val destinationDir: File by lazy {
|
||||
compilation.npmProject.externalsDir
|
||||
npmProject.externalsDir
|
||||
}
|
||||
|
||||
@delegate:Transient
|
||||
private val executor by lazy {
|
||||
DukatExecutor(
|
||||
private val executor
|
||||
get() = DukatExecutor(
|
||||
nodeJs,
|
||||
dts,
|
||||
externalsOutputFormat,
|
||||
compilation.npmProject,
|
||||
npmProject,
|
||||
true,
|
||||
compareInputs = false
|
||||
)
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
override fun run() {
|
||||
|
||||
+3
-3
@@ -12,10 +12,10 @@ import org.jetbrains.kotlin.gradle.targets.js.npm.RequiresNpmDependencies
|
||||
import org.jetbrains.kotlin.gradle.targets.js.npm.toDeclaration
|
||||
|
||||
class TasksRequirements {
|
||||
private val _byTask = mutableMapOf<RequiresNpmDependencies, Set<RequiredKotlinJsDependency>>()
|
||||
private val _byTask = mutableMapOf<String, Set<RequiredKotlinJsDependency>>()
|
||||
private val byCompilation = mutableMapOf<String, MutableSet<NpmDependencyDeclaration>>()
|
||||
|
||||
val byTask: Map<RequiresNpmDependencies, Set<RequiredKotlinJsDependency>>
|
||||
val byTask: Map<String, Set<RequiredKotlinJsDependency>>
|
||||
get() = _byTask
|
||||
|
||||
internal fun getCompilationNpmRequirements(compilationName: String): Set<NpmDependencyDeclaration> =
|
||||
@@ -25,7 +25,7 @@ class TasksRequirements {
|
||||
fun addTaskRequirements(task: RequiresNpmDependencies) {
|
||||
val requirements = task.requiredNpmDependencies
|
||||
|
||||
_byTask[task] = requirements
|
||||
_byTask[task.getPath()] = requirements
|
||||
|
||||
val requiredNpmDependencies = requirements
|
||||
.asSequence()
|
||||
|
||||
+2
-3
@@ -232,13 +232,12 @@ class KotlinNpmResolutionManager(private val nodeJsSettings: NodeJsRootExtension
|
||||
internal fun <T> checkRequiredDependencies(task: T, services: ServiceRegistry, logger: Logger, projectPath: String)
|
||||
where T : RequiresNpmDependencies,
|
||||
T : Task {
|
||||
val project = task.project
|
||||
val requestedTaskDependencies = requireInstalled(services, logger, "before $task execution")[projectPath].taskRequirements
|
||||
val targetRequired = requestedTaskDependencies[task]?.toSet() ?: setOf()
|
||||
val targetRequired = requestedTaskDependencies[task.path]?.toSet() ?: setOf()
|
||||
|
||||
task.requiredNpmDependencies.forEach {
|
||||
check(it in targetRequired) {
|
||||
"${it.createDependency(project)} required by $task was not found resolved at the time of nodejs package manager call. " +
|
||||
"${it.createDependency(task.project)} required by $task was not found resolved at the time of nodejs package manager call. " +
|
||||
"This may be caused by changing $task configuration after npm dependencies resolution."
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -65,8 +65,9 @@ open class NpmProject(@Transient val compilation: KotlinJsCompilation) {
|
||||
val main: String
|
||||
get() = "$DIST_FOLDER/$name.js"
|
||||
|
||||
val externalsDirRoot: File
|
||||
get() = project.buildDir.resolve("externals").resolve(name)
|
||||
val externalsDirRoot by lazy {
|
||||
project.buildDir.resolve("externals").resolve(name)
|
||||
}
|
||||
|
||||
val externalsDir: File
|
||||
get() = externalsDirRoot.resolve("src")
|
||||
|
||||
+4
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.gradle.targets.js.npm
|
||||
|
||||
import org.gradle.api.tasks.Internal
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation
|
||||
import org.jetbrains.kotlin.gradle.targets.js.RequiredKotlinJsDependency
|
||||
|
||||
@@ -12,4 +13,7 @@ interface RequiresNpmDependencies {
|
||||
val compilation: KotlinJsCompilation
|
||||
val nodeModulesRequired: Boolean
|
||||
val requiredNpmDependencies: Set<RequiredKotlinJsDependency>
|
||||
|
||||
@Internal
|
||||
fun getPath(): String
|
||||
}
|
||||
+1
-5
@@ -5,12 +5,8 @@
|
||||
|
||||
package org.jetbrains.kotlin.gradle.targets.js.npm.resolved
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.file.FileCollection
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation
|
||||
import org.jetbrains.kotlin.gradle.targets.js.RequiredKotlinJsDependency
|
||||
import org.jetbrains.kotlin.gradle.targets.js.npm.NpmDependency
|
||||
import org.jetbrains.kotlin.gradle.targets.js.npm.RequiresNpmDependencies
|
||||
|
||||
/**
|
||||
* Info about NPM projects inside particular gradle [project].
|
||||
@@ -18,7 +14,7 @@ import org.jetbrains.kotlin.gradle.targets.js.npm.RequiresNpmDependencies
|
||||
class KotlinProjectNpmResolution(
|
||||
val project: String,
|
||||
val npmProjects: List<KotlinCompilationNpmResolution>,
|
||||
val taskRequirements: Map<RequiresNpmDependencies, Collection<RequiredKotlinJsDependency>>
|
||||
val taskRequirements: Map<String, Collection<RequiredKotlinJsDependency>>
|
||||
) {
|
||||
val npmProjectsByNpmDependency: Map<NpmDependency, KotlinCompilationNpmResolution> by lazy {
|
||||
mutableMapOf<NpmDependency, KotlinCompilationNpmResolution>().also { result ->
|
||||
|
||||
+5
-1
@@ -40,6 +40,10 @@ internal class KotlinProjectNpmResolver(
|
||||
return byCompilation[compilation.name] ?: error("$compilation was not registered in $this")
|
||||
}
|
||||
|
||||
operator fun get(compilationName: String): KotlinCompilationNpmResolver {
|
||||
return byCompilation[compilationName] ?: error("$compilationName was not registered in $this")
|
||||
}
|
||||
|
||||
private var closed = false
|
||||
|
||||
val compilationResolvers: Collection<KotlinCompilationNpmResolver>
|
||||
@@ -116,7 +120,7 @@ internal class KotlinProjectNpmResolver(
|
||||
return KotlinProjectNpmResolution(
|
||||
projectPath,
|
||||
byCompilation.values.mapNotNull { it.close() },
|
||||
resolver.nodeJs.taskRequirements?.byTask
|
||||
resolver.nodeJs.taskRequirements.byTask
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -41,7 +41,7 @@ open class KotlinPackageJsonTask : DefaultTask() {
|
||||
val projectPath = project.path
|
||||
|
||||
private val compilationResolver
|
||||
get() = nodeJs.npmResolutionManager.resolver[projectPath][compilation]
|
||||
get() = nodeJs.npmResolutionManager.resolver[projectPath][compilationName]
|
||||
|
||||
private val producer: KotlinCompilationNpmResolver.PackageJsonProducer
|
||||
get() = compilationResolver.packageJsonProducer
|
||||
|
||||
+2
-2
@@ -106,7 +106,7 @@ constructor(
|
||||
}
|
||||
|
||||
fun useMocha() = useMocha {}
|
||||
fun useMocha(body: KotlinMocha.() -> Unit) = use(KotlinMocha(compilation), body)
|
||||
fun useMocha(body: KotlinMocha.() -> Unit) = use(KotlinMocha(compilation, path), body)
|
||||
fun useMocha(fn: Closure<*>) {
|
||||
useMocha {
|
||||
ConfigureUtil.configure(fn, this)
|
||||
@@ -115,7 +115,7 @@ constructor(
|
||||
|
||||
fun useKarma() = useKarma {}
|
||||
fun useKarma(body: KotlinKarma.() -> Unit) = use(
|
||||
KotlinKarma(compilation, services),
|
||||
KotlinKarma(compilation, services, path),
|
||||
body
|
||||
)
|
||||
fun useKarma(fn: Closure<*>) {
|
||||
|
||||
+3
-1
@@ -36,7 +36,7 @@ import org.jetbrains.kotlin.gradle.utils.property
|
||||
import org.slf4j.Logger
|
||||
import java.io.File
|
||||
|
||||
class KotlinKarma(override val compilation: KotlinJsCompilation, private val services: ServiceRegistry) :
|
||||
class KotlinKarma(override val compilation: KotlinJsCompilation, private val services: ServiceRegistry, private val basePath: String) :
|
||||
KotlinJsTestFramework {
|
||||
private val project: Project = compilation.target.project
|
||||
private val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
||||
@@ -56,6 +56,8 @@ class KotlinKarma(override val compilation: KotlinJsCompilation, private val ser
|
||||
override val requiredNpmDependencies: Set<RequiredKotlinJsDependency>
|
||||
get() = requiredDependencies + webpackConfig.getRequiredDependencies(versions)
|
||||
|
||||
override fun getPath() = "$basePath:kotlinKarma"
|
||||
|
||||
override val settingsState: String
|
||||
get() = "KotlinKarma($config)"
|
||||
|
||||
|
||||
+3
-1
@@ -21,7 +21,7 @@ import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTestFramework
|
||||
import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinTestRunnerCliArgs
|
||||
import java.io.File
|
||||
|
||||
class KotlinMocha(override val compilation: KotlinJsCompilation) :
|
||||
class KotlinMocha(override val compilation: KotlinJsCompilation, private val basePath: String) :
|
||||
KotlinJsTestFramework {
|
||||
private val project: Project = compilation.target.project
|
||||
private val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
||||
@@ -37,6 +37,8 @@ class KotlinMocha(override val compilation: KotlinJsCompilation) :
|
||||
versions.sourceMapSupport
|
||||
)
|
||||
|
||||
override fun getPath() = "$basePath:kotlinMocha"
|
||||
|
||||
// https://mochajs.org/#-timeout-ms-t-ms
|
||||
var timeout: String = DEFAULT_TIMEOUT
|
||||
|
||||
|
||||
+6
-5
@@ -19,10 +19,7 @@ package org.jetbrains.kotlin.gradle.tasks
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.file.FileCollection
|
||||
import org.gradle.api.file.FileTree
|
||||
import org.gradle.api.tasks.CacheableTask
|
||||
import org.gradle.api.tasks.Input
|
||||
import org.gradle.api.tasks.Internal
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
import org.gradle.api.tasks.*
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2JSDceArguments
|
||||
import org.jetbrains.kotlin.cli.js.dce.K2JSDce
|
||||
import org.jetbrains.kotlin.compilerRunner.runToolInSeparateProcess
|
||||
@@ -74,6 +71,10 @@ open class KotlinJsDce : AbstractKotlinCompileTool<K2JSDceArguments>(), KotlinJs
|
||||
@Input
|
||||
var jvmArgs = mutableListOf<String>()
|
||||
|
||||
private val buildDir by lazy {
|
||||
project.buildDir
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
fun performDce() {
|
||||
val inputFiles = (listOf(source) + classpath
|
||||
@@ -94,7 +95,7 @@ open class KotlinJsDce : AbstractKotlinCompileTool<K2JSDceArguments>(), KotlinJs
|
||||
K2JSDce::class.java.name,
|
||||
computedCompilerClasspath,
|
||||
log,
|
||||
project.buildDir,
|
||||
buildDir,
|
||||
jvmArgs
|
||||
)
|
||||
throwGradleExceptionIfError(exitCode)
|
||||
|
||||
Reference in New Issue
Block a user