[Gradle, JS] Make yarn working without downloading
^KT-32071 fixed
This commit is contained in:
committed by
TeamCityServer
parent
eb73527b9f
commit
81ac48390c
+2
-1
@@ -35,7 +35,8 @@ interface NpmApi {
|
|||||||
services: ServiceRegistry,
|
services: ServiceRegistry,
|
||||||
logger: Logger,
|
logger: Logger,
|
||||||
nodeJs: NodeJsRootExtension,
|
nodeJs: NodeJsRootExtension,
|
||||||
yarnHome: File,
|
command: String,
|
||||||
|
isStandalone: Boolean,
|
||||||
npmProjects: Collection<KotlinCompilationNpmResolution>,
|
npmProjects: Collection<KotlinCompilationNpmResolution>,
|
||||||
cliArgs: List<String>
|
cliArgs: List<String>
|
||||||
)
|
)
|
||||||
|
|||||||
+3
-1
@@ -230,11 +230,13 @@ internal class KotlinRootNpmResolver internal constructor(
|
|||||||
.values
|
.values
|
||||||
.flatMap { it.npmProjects }
|
.flatMap { it.npmProjects }
|
||||||
|
|
||||||
|
val yarnConfigured = yarn.requireConfigured()
|
||||||
nodeJs.packageManager.resolveRootProject(
|
nodeJs.packageManager.resolveRootProject(
|
||||||
services,
|
services,
|
||||||
logger,
|
logger,
|
||||||
nodeJs,
|
nodeJs,
|
||||||
yarn.requireConfigured().home,
|
yarnConfigured.executable,
|
||||||
|
yarnConfigured.standalone,
|
||||||
allNpmPackages,
|
allNpmPackages,
|
||||||
args
|
args
|
||||||
)
|
)
|
||||||
|
|||||||
+4
-2
@@ -51,7 +51,8 @@ class Yarn : NpmApi {
|
|||||||
services: ServiceRegistry,
|
services: ServiceRegistry,
|
||||||
logger: Logger,
|
logger: Logger,
|
||||||
nodeJs: NodeJsRootExtension,
|
nodeJs: NodeJsRootExtension,
|
||||||
yarnHome: File,
|
command: String,
|
||||||
|
isStandalone: Boolean,
|
||||||
npmProjects: Collection<KotlinCompilationNpmResolution>,
|
npmProjects: Collection<KotlinCompilationNpmResolution>,
|
||||||
cliArgs: List<String>
|
cliArgs: List<String>
|
||||||
) {
|
) {
|
||||||
@@ -60,7 +61,8 @@ class Yarn : NpmApi {
|
|||||||
services,
|
services,
|
||||||
logger,
|
logger,
|
||||||
nodeJs,
|
nodeJs,
|
||||||
yarnHome,
|
command,
|
||||||
|
isStandalone,
|
||||||
npmProjects,
|
npmProjects,
|
||||||
cliArgs
|
cliArgs
|
||||||
)
|
)
|
||||||
|
|||||||
+12
-6
@@ -6,12 +6,10 @@
|
|||||||
package org.jetbrains.kotlin.gradle.targets.js.yarn
|
package org.jetbrains.kotlin.gradle.targets.js.yarn
|
||||||
|
|
||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
import org.gradle.api.internal.project.ProjectInternal
|
|
||||||
import org.gradle.api.logging.Logger
|
import org.gradle.api.logging.Logger
|
||||||
import org.gradle.internal.service.ServiceRegistry
|
import org.gradle.internal.service.ServiceRegistry
|
||||||
import org.jetbrains.kotlin.gradle.internal.execWithProgress
|
import org.jetbrains.kotlin.gradle.internal.execWithProgress
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension
|
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
|
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.npm.NpmApi
|
import org.jetbrains.kotlin.gradle.targets.js.npm.NpmApi
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.npm.NpmDependency
|
import org.jetbrains.kotlin.gradle.targets.js.npm.NpmDependency
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.npm.NpmDependency.Scope.PEER
|
import org.jetbrains.kotlin.gradle.targets.js.npm.NpmDependency.Scope.PEER
|
||||||
@@ -31,16 +29,24 @@ abstract class YarnBasics : NpmApi {
|
|||||||
services: ServiceRegistry,
|
services: ServiceRegistry,
|
||||||
logger: Logger,
|
logger: Logger,
|
||||||
nodeJs: NodeJsRootExtension,
|
nodeJs: NodeJsRootExtension,
|
||||||
yarnHome: File,
|
command: String,
|
||||||
|
isStandalone: Boolean,
|
||||||
dir: File,
|
dir: File,
|
||||||
description: String,
|
description: String,
|
||||||
args: List<String>
|
args: List<String>
|
||||||
) {
|
) {
|
||||||
services.execWithProgress(description) { exec ->
|
services.execWithProgress(description) { exec ->
|
||||||
exec.executable = nodeJs.requireConfigured().nodeExecutable
|
val arguments = args +
|
||||||
exec.args = listOf(yarnHome.resolve("bin/yarn.js").absolutePath) +
|
|
||||||
args +
|
|
||||||
if (logger.isDebugEnabled) "--verbose" else ""
|
if (logger.isDebugEnabled) "--verbose" else ""
|
||||||
|
|
||||||
|
if (isStandalone) {
|
||||||
|
exec.executable = command
|
||||||
|
exec.args = arguments
|
||||||
|
} else {
|
||||||
|
exec.executable = nodeJs.requireConfigured().nodeExecutable
|
||||||
|
exec.args = listOf(command) + arguments
|
||||||
|
}
|
||||||
|
|
||||||
exec.workingDir = dir
|
exec.workingDir = dir
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-1
@@ -12,5 +12,7 @@ data class YarnEnv(
|
|||||||
val downloadUrl: String,
|
val downloadUrl: String,
|
||||||
val cleanableStore: CleanableStore,
|
val cleanableStore: CleanableStore,
|
||||||
val home: File,
|
val home: File,
|
||||||
val ivyDependency: String
|
val executable: String,
|
||||||
|
val ivyDependency: String,
|
||||||
|
val standalone: Boolean
|
||||||
)
|
)
|
||||||
|
|||||||
+23
-1
@@ -11,6 +11,7 @@ import org.gradle.api.Project
|
|||||||
import org.gradle.api.tasks.TaskProvider
|
import org.gradle.api.tasks.TaskProvider
|
||||||
import org.jetbrains.kotlin.gradle.internal.ConfigurationPhaseAware
|
import org.jetbrains.kotlin.gradle.internal.ConfigurationPhaseAware
|
||||||
import org.jetbrains.kotlin.gradle.logging.kotlinInfo
|
import org.jetbrains.kotlin.gradle.logging.kotlinInfo
|
||||||
|
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsPlatform
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
|
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.npm.RequiresNpmDependencies
|
import org.jetbrains.kotlin.gradle.targets.js.npm.RequiresNpmDependencies
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.npm.resolver.implementing
|
import org.jetbrains.kotlin.gradle.targets.js.npm.resolver.implementing
|
||||||
@@ -34,6 +35,10 @@ open class YarnRootExtension(
|
|||||||
var downloadBaseUrl by Property("https://github.com/yarnpkg/yarn/releases/download")
|
var downloadBaseUrl by Property("https://github.com/yarnpkg/yarn/releases/download")
|
||||||
var version by Property("1.22.10")
|
var version by Property("1.22.10")
|
||||||
|
|
||||||
|
var command by Property("yarn")
|
||||||
|
|
||||||
|
var download by Property(true)
|
||||||
|
|
||||||
val yarnSetupTaskProvider: TaskProvider<YarnSetupTask>
|
val yarnSetupTaskProvider: TaskProvider<YarnSetupTask>
|
||||||
get() = project.tasks
|
get() = project.tasks
|
||||||
.withType(YarnSetupTask::class.java)
|
.withType(YarnSetupTask::class.java)
|
||||||
@@ -77,16 +82,33 @@ open class YarnRootExtension(
|
|||||||
override fun finalizeConfiguration(): YarnEnv {
|
override fun finalizeConfiguration(): YarnEnv {
|
||||||
val cleanableStore = CleanableStore[installationDir.path]
|
val cleanableStore = CleanableStore[installationDir.path]
|
||||||
|
|
||||||
|
val isWindows = NodeJsPlatform.name == NodeJsPlatform.WIN
|
||||||
|
|
||||||
|
val home = cleanableStore["yarn-v$version"].use()
|
||||||
|
|
||||||
|
fun getExecutable(command: String, customCommand: String, windowsExtension: String): String {
|
||||||
|
val finalCommand = if (isWindows && customCommand == command) "$command.$windowsExtension" else customCommand
|
||||||
|
return if (download)
|
||||||
|
home
|
||||||
|
.resolve("bin/yarn.js").absolutePath
|
||||||
|
else
|
||||||
|
finalCommand
|
||||||
|
}
|
||||||
return YarnEnv(
|
return YarnEnv(
|
||||||
downloadUrl = downloadBaseUrl,
|
downloadUrl = downloadBaseUrl,
|
||||||
cleanableStore = cleanableStore,
|
cleanableStore = cleanableStore,
|
||||||
home = cleanableStore["yarn-v$version"].use(),
|
home = home,
|
||||||
|
executable = getExecutable("yarn", command, "cmd"),
|
||||||
|
standalone = !download,
|
||||||
ivyDependency = "com.yarnpkg:yarn:$version@tar.gz"
|
ivyDependency = "com.yarnpkg:yarn:$version@tar.gz"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun executeSetup() {
|
internal fun executeSetup() {
|
||||||
NodeJsRootPlugin.apply(project).executeSetup()
|
NodeJsRootPlugin.apply(project).executeSetup()
|
||||||
|
|
||||||
|
if (!download) return
|
||||||
|
|
||||||
val yarnSetupTask = yarnSetupTaskProvider.get()
|
val yarnSetupTask = yarnSetupTaskProvider.get()
|
||||||
yarnSetupTask.actions.forEach {
|
yarnSetupTask.actions.forEach {
|
||||||
it.execute(yarnSetupTask)
|
it.execute(yarnSetupTask)
|
||||||
|
|||||||
+4
-2
@@ -71,7 +71,8 @@ class YarnWorkspaces : YarnBasics() {
|
|||||||
services: ServiceRegistry,
|
services: ServiceRegistry,
|
||||||
logger: Logger,
|
logger: Logger,
|
||||||
nodeJs: NodeJsRootExtension,
|
nodeJs: NodeJsRootExtension,
|
||||||
yarnHome: File,
|
command: String,
|
||||||
|
isStandalone: Boolean,
|
||||||
npmProjects: Collection<KotlinCompilationNpmResolution>,
|
npmProjects: Collection<KotlinCompilationNpmResolution>,
|
||||||
cliArgs: List<String>
|
cliArgs: List<String>
|
||||||
) {
|
) {
|
||||||
@@ -81,7 +82,8 @@ class YarnWorkspaces : YarnBasics() {
|
|||||||
services,
|
services,
|
||||||
logger,
|
logger,
|
||||||
nodeJs,
|
nodeJs,
|
||||||
yarnHome,
|
command,
|
||||||
|
isStandalone,
|
||||||
nodeJsWorldDir,
|
nodeJsWorldDir,
|
||||||
NpmApi.resolveOperationDescription("yarn"),
|
NpmApi.resolveOperationDescription("yarn"),
|
||||||
cliArgs
|
cliArgs
|
||||||
|
|||||||
Reference in New Issue
Block a user