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