[Gradle, JS] Move yarn resolutions from dependency constraints
^KT-41054 fixed
This commit is contained in:
-11
@@ -192,17 +192,6 @@ class KotlinNpmResolutionManager(private val nodeJsSettings: NodeJsRootExtension
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun putNpmResolution(
|
|
||||||
path: String,
|
|
||||||
version: String
|
|
||||||
) {
|
|
||||||
with(state) {
|
|
||||||
if (this is ResolutionState.Configuring) {
|
|
||||||
resolver.resolutions[path] = version
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
internal fun getNpmDependencyResolvedCompilation(npmDependency: NpmDependency): KotlinCompilationNpmResolution? {
|
internal fun getNpmDependencyResolvedCompilation(npmDependency: NpmDependency): KotlinCompilationNpmResolution? {
|
||||||
val project = npmDependency.project
|
val project = npmDependency.project
|
||||||
|
|
||||||
|
|||||||
-112
@@ -1,112 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.jetbrains.kotlin.gradle.targets.js.npm
|
|
||||||
|
|
||||||
import org.gradle.api.Action
|
|
||||||
import org.gradle.api.Project
|
|
||||||
import org.gradle.api.artifacts.*
|
|
||||||
import org.gradle.api.attributes.AttributeContainer
|
|
||||||
import org.gradle.api.internal.artifacts.ModuleVersionSelectorStrictSpec
|
|
||||||
import org.gradle.api.internal.artifacts.dependencies.DefaultMutableVersionConstraint
|
|
||||||
import org.gradle.api.internal.artifacts.dependencies.DependencyConstraintInternal
|
|
||||||
import org.gradle.api.internal.attributes.ImmutableAttributes
|
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
|
|
||||||
|
|
||||||
class NpmDependencyConstraint(
|
|
||||||
internal val project: Project,
|
|
||||||
private val path: String,
|
|
||||||
private val version: String
|
|
||||||
) : DependencyConstraintInternal {
|
|
||||||
|
|
||||||
private var reason: String? = null
|
|
||||||
|
|
||||||
private val versionConstraint = NpmVersionConstraint(version)
|
|
||||||
|
|
||||||
override fun getGroup(): String? = null
|
|
||||||
|
|
||||||
override fun getName(): String = path
|
|
||||||
|
|
||||||
override fun getVersion(): String = versionConstraint.version
|
|
||||||
|
|
||||||
override fun matchesStrictly(identifier: ModuleVersionIdentifier): Boolean {
|
|
||||||
return ModuleVersionSelectorStrictSpec(this)
|
|
||||||
.isSatisfiedBy(identifier)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getModule(): ModuleIdentifier {
|
|
||||||
return object : ModuleIdentifier {
|
|
||||||
override fun getGroup(): String? = null
|
|
||||||
|
|
||||||
override fun getName(): String = path
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getAttributes(): AttributeContainer {
|
|
||||||
return ImmutableAttributes.EMPTY
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun attributes(configureAction: Action<in AttributeContainer>): DependencyConstraint {
|
|
||||||
warnAboutInternalApiUse()
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun warnAboutInternalApiUse() {
|
|
||||||
project.logger.warn(
|
|
||||||
"""Cannot set attributes for NPM constraint '${this.path}:${this.version}"""
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun version(configureAction: Action<in MutableVersionConstraint>) {
|
|
||||||
configureAction.execute(versionConstraint)
|
|
||||||
val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
|
||||||
nodeJs.npmResolutionManager.putNpmResolution(path, versionConstraint.toSemVer())
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getReason(): String? {
|
|
||||||
return reason
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun because(reason: String?) {
|
|
||||||
this.reason = reason
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getVersionConstraint(): VersionConstraint {
|
|
||||||
val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
|
||||||
nodeJs.npmResolutionManager.putNpmResolution(path, versionConstraint.toSemVer())
|
|
||||||
return versionConstraint
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun setForce(force: Boolean) {
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun isForce(): Boolean {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
|
||||||
if (this === other) return true
|
|
||||||
if (javaClass != other?.javaClass) return false
|
|
||||||
|
|
||||||
other as NpmDependencyConstraint
|
|
||||||
|
|
||||||
if (project != other.project) return false
|
|
||||||
if (path != other.path) return false
|
|
||||||
if (versionConstraint != other.versionConstraint) return false
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
|
||||||
var result = project.hashCode()
|
|
||||||
result = 31 * result + path.hashCode()
|
|
||||||
result = 31 * result + versionConstraint.hashCode()
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun toString(): String {
|
|
||||||
return "NpmDependencyConstraint(path='$path', versionConstraint=$versionConstraint)"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-40
@@ -1,40 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.jetbrains.kotlin.gradle.targets.js.npm
|
|
||||||
|
|
||||||
import org.gradle.api.internal.artifacts.dependencies.DefaultMutableVersionConstraint
|
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.npm.NpmRangeVisitor.Companion.WILDCARD
|
|
||||||
|
|
||||||
class NpmVersionConstraint(
|
|
||||||
version: String
|
|
||||||
) : DefaultMutableVersionConstraint(version) {
|
|
||||||
override fun rejectAll() {
|
|
||||||
super.rejectAll()
|
|
||||||
reject(WILDCARD)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun toSemVer(): String {
|
|
||||||
if (requiredVersion.isEmpty()) {
|
|
||||||
return buildNpmVersion(
|
|
||||||
includedVersions = listOf(preferredVersion),
|
|
||||||
excludedVersions = rejectedVersions
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strictVersion.isNotEmpty()) {
|
|
||||||
return buildNpmVersion(
|
|
||||||
includedVersions = listOf(strictVersion),
|
|
||||||
excludedVersions = rejectedVersions
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
return buildNpmVersion(
|
|
||||||
listOf(requiredVersion),
|
|
||||||
rejectedVersions,
|
|
||||||
true
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+6
-2
@@ -20,6 +20,8 @@ import org.jetbrains.kotlin.gradle.targets.js.npm.plugins.RootResolverPlugin
|
|||||||
import org.jetbrains.kotlin.gradle.targets.js.npm.resolved.KotlinCompilationNpmResolution
|
import org.jetbrains.kotlin.gradle.targets.js.npm.resolved.KotlinCompilationNpmResolution
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.npm.resolved.KotlinProjectNpmResolution
|
import org.jetbrains.kotlin.gradle.targets.js.npm.resolved.KotlinProjectNpmResolution
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.npm.resolved.KotlinRootNpmResolution
|
import org.jetbrains.kotlin.gradle.targets.js.npm.resolved.KotlinRootNpmResolution
|
||||||
|
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnPlugin
|
||||||
|
import org.jetbrains.kotlin.gradle.targets.js.yarn.toVersionString
|
||||||
import org.jetbrains.kotlin.gradle.tasks.registerTask
|
import org.jetbrains.kotlin.gradle.tasks.registerTask
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -49,7 +51,6 @@ internal class KotlinRootNpmResolver internal constructor(
|
|||||||
val compositeNodeModules = CompositeNodeModulesCache(nodeJs)
|
val compositeNodeModules = CompositeNodeModulesCache(nodeJs)
|
||||||
val packageJsonUmbrella = rootProject.registerTask(PACKAGE_JSON_UMBRELLA_TASK_NAME, Task::class.java) {}
|
val packageJsonUmbrella = rootProject.registerTask(PACKAGE_JSON_UMBRELLA_TASK_NAME, Task::class.java) {}
|
||||||
val projectResolvers = mutableMapOf<Project, KotlinProjectNpmResolver>()
|
val projectResolvers = mutableMapOf<Project, KotlinProjectNpmResolver>()
|
||||||
val resolutions = mutableMapOf<String, String>()
|
|
||||||
|
|
||||||
fun alreadyResolvedMessage(action: String) = "Cannot $action. NodeJS projects already resolved."
|
fun alreadyResolvedMessage(action: String) = "Cannot $action. NodeJS projects already resolved."
|
||||||
|
|
||||||
@@ -109,10 +110,13 @@ internal class KotlinRootNpmResolver internal constructor(
|
|||||||
|
|
||||||
gradleNodeModules.close()
|
gradleNodeModules.close()
|
||||||
|
|
||||||
|
val yarn = YarnPlugin.apply(rootProject)
|
||||||
|
|
||||||
nodeJs.packageManager.prepareRootProject(
|
nodeJs.packageManager.prepareRootProject(
|
||||||
rootProject,
|
rootProject,
|
||||||
allNpmPackages,
|
allNpmPackages,
|
||||||
resolutions
|
yarn.resolutions
|
||||||
|
.associate { it.path to it.toVersionString() }
|
||||||
)
|
)
|
||||||
|
|
||||||
return Installation(
|
return Installation(
|
||||||
|
|||||||
+27
@@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.gradle.targets.js.yarn
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.gradle.targets.js.npm.buildNpmVersion
|
||||||
|
|
||||||
|
class YarnResolution(
|
||||||
|
val path: String
|
||||||
|
) {
|
||||||
|
var includedVersions = mutableListOf<String>()
|
||||||
|
var excludedVersions = mutableListOf<String>()
|
||||||
|
|
||||||
|
fun include(vararg include: String) {
|
||||||
|
includedVersions.addAll(include)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun exclude(vararg exclude: String) {
|
||||||
|
excludedVersions.addAll(exclude)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun YarnResolution.toVersionString(): String {
|
||||||
|
return buildNpmVersion(includedVersions, excludedVersions)
|
||||||
|
}
|
||||||
+2
@@ -43,6 +43,8 @@ open class YarnRootExtension(val project: Project) : ConfigurationPhaseAware<Yar
|
|||||||
.withType(RootPackageJsonTask::class.java)
|
.withType(RootPackageJsonTask::class.java)
|
||||||
.named(RootPackageJsonTask.NAME)
|
.named(RootPackageJsonTask.NAME)
|
||||||
|
|
||||||
|
var resolutions: MutableList<YarnResolution> = mutableListOf()
|
||||||
|
|
||||||
@Incubating
|
@Incubating
|
||||||
fun disableGranularWorkspaces() {
|
fun disableGranularWorkspaces() {
|
||||||
val packageJsonUmbrella = NodeJsRootPlugin.apply(project)
|
val packageJsonUmbrella = NodeJsRootPlugin.apply(project)
|
||||||
|
|||||||
Reference in New Issue
Block a user