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