[Gradle, JS] Make KotlinWebpack cc-compatible
This commit is contained in:
+1
-2
@@ -51,8 +51,7 @@ open class NodeJsRootExtension(@Transient val rootProject: Project) : Configurat
|
||||
|
||||
val experimental = Experimental()
|
||||
|
||||
@Transient
|
||||
val taskRequirements = TasksRequirements()
|
||||
val taskRequirements: TasksRequirements = TasksRequirements()
|
||||
|
||||
val nodeJsSetupTaskProvider: TaskProvider<out NodeJsSetupTask>
|
||||
get() = rootProject.tasks.withType(NodeJsSetupTask::class.java).named(NodeJsSetupTask.NAME)
|
||||
|
||||
-1
@@ -12,7 +12,6 @@ import org.jetbrains.kotlin.gradle.targets.js.npm.RequiresNpmDependencies
|
||||
import org.jetbrains.kotlin.gradle.targets.js.npm.toDeclaration
|
||||
|
||||
class TasksRequirements {
|
||||
@Transient
|
||||
private val _byTask = mutableMapOf<RequiresNpmDependencies, Set<RequiredKotlinJsDependency>>()
|
||||
private val byCompilation = mutableMapOf<String, MutableSet<NpmDependencyDeclaration>>()
|
||||
|
||||
|
||||
+15
-16
@@ -6,6 +6,7 @@
|
||||
package org.jetbrains.kotlin.gradle.targets.js.npm
|
||||
|
||||
import org.gradle.api.Incubating
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.Task
|
||||
import org.gradle.api.internal.project.ProjectInternal
|
||||
import org.gradle.api.logging.Logger
|
||||
@@ -120,8 +121,9 @@ class KotlinNpmResolutionManager(private val nodeJsSettings: NodeJsRootExtension
|
||||
@Incubating
|
||||
internal fun requireInstalled(
|
||||
services: ServiceRegistry,
|
||||
logger: Logger
|
||||
) = installIfNeeded(reason = "", services = services, logger = logger)
|
||||
logger: Logger,
|
||||
reason: String = ""
|
||||
) = installIfNeeded(reason = reason, services = services, logger = logger)
|
||||
|
||||
internal fun requireConfiguringState(): KotlinRootNpmResolver =
|
||||
(this.state as? ResolutionState.Configuring ?: error("NPM Dependencies already resolved and installed")).resolver
|
||||
@@ -156,9 +158,6 @@ class KotlinNpmResolutionManager(private val nodeJsSettings: NodeJsRootExtension
|
||||
}
|
||||
}
|
||||
|
||||
// internal fun requireAlreadyInstalled(project: Project, reason: String = ""): KotlinProjectNpmResolution =
|
||||
// installIfNeeded(reason = reason)[project.path]
|
||||
|
||||
internal val packageJsonFiles: Collection<File>
|
||||
get() = state.npmProjects.map { it.packageJsonFile }
|
||||
|
||||
@@ -230,18 +229,18 @@ class KotlinNpmResolutionManager(private val nodeJsSettings: NodeJsRootExtension
|
||||
return resolvedProject.npmProjectsByNpmDependency[npmDependency] ?: error("NPM project resolved without $this")
|
||||
}
|
||||
|
||||
internal fun <T> checkRequiredDependencies(task: T)
|
||||
internal fun <T> checkRequiredDependencies(task: T, services: ServiceRegistry, logger: Logger, projectPath: String)
|
||||
where T : RequiresNpmDependencies,
|
||||
T : Task {
|
||||
// val project = task.project
|
||||
// val requestedTaskDependencies = requireAlreadyInstalled(project, "before $task execution").taskRequirements
|
||||
// val targetRequired = requestedTaskDependencies[task]?.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. " +
|
||||
// "This may be caused by changing $task configuration after npm dependencies resolution."
|
||||
// }
|
||||
// }
|
||||
val project = task.project
|
||||
val requestedTaskDependencies = requireInstalled(services, logger, "before $task execution")[projectPath].taskRequirements
|
||||
val targetRequired = requestedTaskDependencies[task]?.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. " +
|
||||
"This may be caused by changing $task configuration after npm dependencies resolution."
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -18,7 +18,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<RequiresNpmDependencies, Collection<RequiredKotlinJsDependency>>
|
||||
) {
|
||||
val npmProjectsByNpmDependency: Map<NpmDependency, KotlinCompilationNpmResolution> by lazy {
|
||||
mutableMapOf<NpmDependency, KotlinCompilationNpmResolution>().also { result ->
|
||||
|
||||
+3
-1
@@ -35,6 +35,8 @@ constructor(
|
||||
RequiresNpmDependencies {
|
||||
private val nodeJs get() = NodeJsRootPlugin.apply(project.rootProject)
|
||||
|
||||
private val projectPath = project.path
|
||||
|
||||
@get:Internal
|
||||
var testFramework: KotlinJsTestFramework? = null
|
||||
set(value) {
|
||||
@@ -134,7 +136,7 @@ constructor(
|
||||
}
|
||||
|
||||
override fun executeTests() {
|
||||
nodeJs.npmResolutionManager.checkRequiredDependencies(this)
|
||||
nodeJs.npmResolutionManager.checkRequiredDependencies(task = this, services = services, logger = logger, projectPath = projectPath)
|
||||
super.executeTests()
|
||||
}
|
||||
|
||||
|
||||
+16
-7
@@ -10,7 +10,6 @@ import org.gradle.api.Incubating
|
||||
import org.gradle.api.file.FileCollection
|
||||
import org.gradle.api.file.RegularFileProperty
|
||||
import org.gradle.api.internal.file.FileResolver
|
||||
import org.gradle.api.internal.project.ProjectInternal
|
||||
import org.gradle.api.plugins.BasePluginConvention
|
||||
import org.gradle.api.provider.Provider
|
||||
import org.gradle.api.tasks.*
|
||||
@@ -50,6 +49,8 @@ constructor(
|
||||
|
||||
private val npmProject = compilation.npmProject
|
||||
|
||||
private val projectPath = project.path
|
||||
|
||||
@get:Inject
|
||||
open val fileResolver: FileResolver
|
||||
get() = injected
|
||||
@@ -106,6 +107,9 @@ constructor(
|
||||
@Input
|
||||
var saveEvaluatedConfigFile: Boolean = true
|
||||
|
||||
@Transient
|
||||
private val baseConventions: BasePluginConvention? = project.convention.plugins["base"] as BasePluginConvention?
|
||||
|
||||
@Nested
|
||||
val output: KotlinWebpackOutput = KotlinWebpackOutput(
|
||||
library = baseConventions?.archivesBaseName,
|
||||
@@ -118,22 +122,27 @@ constructor(
|
||||
val outputPath: File
|
||||
get() = destinationDirectory
|
||||
|
||||
private val baseConventions: BasePluginConvention?
|
||||
get() = project.convention.plugins["base"] as BasePluginConvention?
|
||||
|
||||
@get:Internal
|
||||
internal var _destinationDirectory: File? = null
|
||||
|
||||
private val defaultDestinationDirectory by lazy {
|
||||
project.buildDir.resolve(baseConventions!!.distsDirName)
|
||||
}
|
||||
|
||||
@get:Internal
|
||||
var destinationDirectory: File
|
||||
get() = _destinationDirectory ?: project.buildDir.resolve(baseConventions!!.distsDirName)
|
||||
get() = _destinationDirectory ?: defaultDestinationDirectory
|
||||
set(value) {
|
||||
_destinationDirectory = value
|
||||
}
|
||||
|
||||
private val defaultOutputFileName by lazy {
|
||||
baseConventions?.archivesBaseName + ".js"
|
||||
}
|
||||
|
||||
@get:Internal
|
||||
var outputFileName: String by property {
|
||||
baseConventions?.archivesBaseName + ".js"
|
||||
defaultOutputFileName
|
||||
}
|
||||
|
||||
@get:OutputFile
|
||||
@@ -250,7 +259,7 @@ constructor(
|
||||
|
||||
@TaskAction
|
||||
fun doExecute() {
|
||||
// nodeJs.npmResolutionManager?.checkRequiredDependencies(this)
|
||||
nodeJs.npmResolutionManager.checkRequiredDependencies(task = this, services = services, logger = logger, projectPath = projectPath)
|
||||
|
||||
val runner = createRunner()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user