[Gradle, JS] Resolve -> install
#KT-34832 fixed
This commit is contained in:
+1
-1
@@ -17,7 +17,7 @@ open class PackageJsonDukatTask : AbstractDukatTask() {
|
||||
|
||||
@get:Internal
|
||||
val dts by lazy {
|
||||
val resolvedCompilation = nodeJs.npmResolutionManager.requireResolved()[project][compilation]
|
||||
val resolvedCompilation = nodeJs.npmResolutionManager.installIfNeeded()[project][compilation]
|
||||
val dtsResolver = DtsResolver(resolvedCompilation.npmProject)
|
||||
dtsResolver.getAllDts(resolvedCompilation.externalNpmDependencies)
|
||||
}
|
||||
|
||||
+6
@@ -28,15 +28,21 @@ open class NodeJsRootPlugin : Plugin<Project> {
|
||||
it.description = "Download and install a local node/npm version"
|
||||
}
|
||||
|
||||
val rootClean = project.rootProject.tasks.named(BasePlugin.CLEAN_TASK_NAME)
|
||||
|
||||
val rootPackageJson = tasks.register(RootPackageJsonTask.NAME, RootPackageJsonTask::class.java) {
|
||||
it.group = TASKS_GROUP_NAME
|
||||
it.description = "Create root package.json"
|
||||
|
||||
it.mustRunAfter(rootClean)
|
||||
}
|
||||
|
||||
tasks.register(KotlinNpmInstallTask.NAME, KotlinNpmInstallTask::class.java) {
|
||||
it.dependsOn(setupTask, rootPackageJson)
|
||||
it.group = TASKS_GROUP_NAME
|
||||
it.description = "Find, download and link NPM dependencies and projects"
|
||||
|
||||
it.mustRunAfter(rootClean)
|
||||
}
|
||||
|
||||
tasks.register("node" + CleanDataTask.NAME_SUFFIX, CleanDataTask::class.java) {
|
||||
|
||||
+10
-12
@@ -91,7 +91,6 @@ class KotlinNpmResolutionManager(private val nodeJsSettings: NodeJsRootExtension
|
||||
class Configuring(val resolver: KotlinRootNpmResolver) : ResolutionState() {
|
||||
override val npmProjects: List<NpmProject>
|
||||
get() = resolver.compilations.map { it.npmProject }
|
||||
|
||||
}
|
||||
|
||||
open class Prepared(val resolved: KotlinRootNpmResolution) : ResolutionState() {
|
||||
@@ -99,7 +98,7 @@ class KotlinNpmResolutionManager(private val nodeJsSettings: NodeJsRootExtension
|
||||
get() = resolved.projects.values.flatMap { it.npmProjects.map { it.npmProject } }
|
||||
}
|
||||
|
||||
class Resolved(resolved: KotlinRootNpmResolution) : Prepared(resolved)
|
||||
class Installed(resolved: KotlinRootNpmResolution) : Prepared(resolved)
|
||||
}
|
||||
|
||||
@Incubating
|
||||
@@ -110,12 +109,12 @@ class KotlinNpmResolutionManager(private val nodeJsSettings: NodeJsRootExtension
|
||||
|
||||
internal fun prepare() = prepareIfNeeded(requireNotInstalled = true)
|
||||
|
||||
internal fun requireResolved(
|
||||
internal fun installIfNeeded(
|
||||
reason: String = "",
|
||||
args: List<String> = emptyList()
|
||||
): KotlinRootNpmResolution {
|
||||
if (state is ResolutionState.Resolved) {
|
||||
return (state as ResolutionState.Resolved).resolved
|
||||
if (state is ResolutionState.Installed) {
|
||||
return (state as ResolutionState.Installed).resolved
|
||||
}
|
||||
|
||||
val npmResolution = prepareIfNeeded(requireUpToDateReason = reason)
|
||||
@@ -130,7 +129,7 @@ class KotlinNpmResolutionManager(private val nodeJsSettings: NodeJsRootExtension
|
||||
args
|
||||
)
|
||||
|
||||
return ResolutionState.Resolved((state as ResolutionState.Prepared).resolved)
|
||||
return ResolutionState.Installed((state as ResolutionState.Prepared).resolved)
|
||||
.apply {
|
||||
state = this
|
||||
npmResolution.plugins
|
||||
@@ -138,8 +137,8 @@ class KotlinNpmResolutionManager(private val nodeJsSettings: NodeJsRootExtension
|
||||
}.resolved
|
||||
}
|
||||
|
||||
internal fun requireAlreadyResolved(project: Project, reason: String = ""): KotlinProjectNpmResolution =
|
||||
requireResolved(reason = reason)[project]
|
||||
internal fun requireAlreadyInstalled(project: Project, reason: String = ""): KotlinProjectNpmResolution =
|
||||
installIfNeeded(reason = reason)[project]
|
||||
|
||||
internal val packageJsonFiles: Collection<File>
|
||||
get() = state.npmProjects.map { it.packageJsonFile }
|
||||
@@ -189,7 +188,8 @@ class KotlinNpmResolutionManager(private val nodeJsSettings: NodeJsRootExtension
|
||||
|
||||
val resolvedProject =
|
||||
if (forceFullResolve) {
|
||||
prepareIfNeeded()[project]
|
||||
prepareIfNeeded()
|
||||
installIfNeeded()[project]
|
||||
} else {
|
||||
// may return null only during npm resolution
|
||||
// (it can be called since NpmDependency added to configuration that
|
||||
@@ -204,8 +204,6 @@ class KotlinNpmResolutionManager(private val nodeJsSettings: NodeJsRootExtension
|
||||
}
|
||||
}
|
||||
|
||||
requireResolved()
|
||||
|
||||
return resolvedProject.npmProjectsByNpmDependency[npmDependency] ?: error("NPM project resolved without $this")
|
||||
}
|
||||
|
||||
@@ -213,7 +211,7 @@ class KotlinNpmResolutionManager(private val nodeJsSettings: NodeJsRootExtension
|
||||
where T : RequiresNpmDependencies,
|
||||
T : Task {
|
||||
val project = task.project
|
||||
val requestedTaskDependencies = requireAlreadyResolved(project, "before $task execution").taskRequirements
|
||||
val requestedTaskDependencies = requireAlreadyInstalled(project, "before $task execution").taskRequirements
|
||||
val targetRequired = requestedTaskDependencies[task]?.toSet() ?: setOf()
|
||||
|
||||
task.requiredNpmDependencies.forEach {
|
||||
|
||||
+1
-1
@@ -79,7 +79,7 @@ open class NpmProject(val compilation: KotlinJsCompilation) {
|
||||
* Require [request] nodejs module and return canonical path to it's main js file.
|
||||
*/
|
||||
fun require(request: String): String {
|
||||
nodeJs.npmResolutionManager.requireAlreadyResolved(project)
|
||||
nodeJs.npmResolutionManager.requireAlreadyInstalled(project)
|
||||
return modules.require(request)
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -45,7 +45,7 @@ open class KotlinNpmInstallTask : DefaultTask() {
|
||||
|
||||
@TaskAction
|
||||
fun resolve() {
|
||||
resolutionManager.requireResolved(args = args)
|
||||
resolutionManager.installIfNeeded(args = args)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
@@ -74,7 +74,7 @@ open class KotlinPackageJsonTask : DefaultTask() {
|
||||
task.inputs.file(packageJsonTask.map { it.packageJson })
|
||||
}
|
||||
|
||||
npmInstallTask.mustRunAfter(rootClean, packageJsonTask)
|
||||
npmInstallTask.mustRunAfter(packageJsonTask)
|
||||
|
||||
compilation.compileKotlinTask.dependsOn(
|
||||
npmInstallTask,
|
||||
|
||||
Reference in New Issue
Block a user