Gradle, js: resolve npm dependencies without task only during IDEA import
#KT-30530
This commit is contained in:
+22
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2010-2019 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.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.gradle.internal
|
||||
|
||||
internal val isInIdeaSync: Boolean
|
||||
get() {
|
||||
// "idea.sync.active" was introduced in 2019.1
|
||||
if (System.getProperty("idea.sync.active")?.toBoolean() == true) return true
|
||||
|
||||
// before 2019.1 there is "idea.active" that was true only on sync,
|
||||
// but since 2019.1 "idea.active" present in task execution too.
|
||||
// So let's check Idea version
|
||||
val majorIdeaVersion = System.getProperty("idea.version")
|
||||
?.split(".")
|
||||
?.getOrNull(0)
|
||||
val isBeforeIdea2019 = majorIdeaVersion == null || majorIdeaVersion.toInt() < 2019
|
||||
|
||||
return isBeforeIdea2019 && System.getProperty("idea.active")?.toBoolean() == true
|
||||
}
|
||||
+5
-1
@@ -15,6 +15,7 @@ import org.gradle.api.internal.artifacts.ResolvableDependency
|
||||
import org.gradle.api.internal.artifacts.dependencies.SelfResolvingDependencyInternal
|
||||
import org.gradle.api.tasks.TaskDependency
|
||||
import org.gradle.internal.component.local.model.DefaultLibraryBinaryIdentifier
|
||||
import org.jetbrains.kotlin.gradle.internal.isInIdeaSync
|
||||
import org.jetbrains.kotlin.gradle.targets.js.npm.NpmResolver.ResolutionCallResult.*
|
||||
import java.io.File
|
||||
|
||||
@@ -51,9 +52,12 @@ data class NpmDependency(
|
||||
}
|
||||
|
||||
private fun resolveProject(): NpmResolver.ResolvedProject? {
|
||||
val result = NpmResolver.resolve(project)
|
||||
val result =
|
||||
if (isInIdeaSync) NpmResolver.resolve(project)
|
||||
else NpmResolver.getAlreadyResolvedOrNull(project)
|
||||
|
||||
return when (result) {
|
||||
null -> null
|
||||
is AlreadyInProgress -> null
|
||||
is AlreadyResolved -> {
|
||||
check(this in result.resolution.npmPackage!!.npmDependencies) {
|
||||
|
||||
+11
-2
@@ -40,8 +40,7 @@ internal class NpmResolver private constructor(val rootProject: Project) : AutoC
|
||||
val rootProject = project.rootProject
|
||||
val process = ProjectData[rootProject]
|
||||
|
||||
if (process != null && process.resolved == null)
|
||||
return AlreadyInProgress
|
||||
if (process != null && process.resolved == null) return AlreadyInProgress
|
||||
|
||||
val resolved = process?.resolved
|
||||
|
||||
@@ -54,6 +53,16 @@ internal class NpmResolver private constructor(val rootProject: Project) : AutoC
|
||||
}
|
||||
}
|
||||
|
||||
fun getAlreadyResolvedOrNull(project: Project): ResolutionCallResult? {
|
||||
val rootProject = project.rootProject
|
||||
val process = ProjectData[rootProject]
|
||||
if (process != null && process.resolved == null) return AlreadyInProgress
|
||||
val resolved = process?.resolved
|
||||
if (resolved != null) return AlreadyResolved(ProjectData[project]!!.resolved!!)
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
fun requireResolved(project: Project, reason: String = ""): ResolvedProject =
|
||||
ProjectData[project.rootProject]?.resolved
|
||||
?: error("NPM dependencies should be resolved$reason")
|
||||
|
||||
Reference in New Issue
Block a user