[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,
|
||||
logger: Logger,
|
||||
nodeJs: NodeJsRootExtension,
|
||||
yarnHome: File,
|
||||
command: String,
|
||||
isStandalone: Boolean,
|
||||
npmProjects: Collection<KotlinCompilationNpmResolution>,
|
||||
cliArgs: List<String>
|
||||
)
|
||||
|
||||
+3
-1
@@ -230,11 +230,13 @@ internal class KotlinRootNpmResolver internal constructor(
|
||||
.values
|
||||
.flatMap { it.npmProjects }
|
||||
|
||||
val yarnConfigured = yarn.requireConfigured()
|
||||
nodeJs.packageManager.resolveRootProject(
|
||||
services,
|
||||
logger,
|
||||
nodeJs,
|
||||
yarn.requireConfigured().home,
|
||||
yarnConfigured.executable,
|
||||
yarnConfigured.standalone,
|
||||
allNpmPackages,
|
||||
args
|
||||
)
|
||||
|
||||
+4
-2
@@ -51,7 +51,8 @@ class Yarn : NpmApi {
|
||||
services: ServiceRegistry,
|
||||
logger: Logger,
|
||||
nodeJs: NodeJsRootExtension,
|
||||
yarnHome: File,
|
||||
command: String,
|
||||
isStandalone: Boolean,
|
||||
npmProjects: Collection<KotlinCompilationNpmResolution>,
|
||||
cliArgs: List<String>
|
||||
) {
|
||||
@@ -60,7 +61,8 @@ class Yarn : NpmApi {
|
||||
services,
|
||||
logger,
|
||||
nodeJs,
|
||||
yarnHome,
|
||||
command,
|
||||
isStandalone,
|
||||
npmProjects,
|
||||
cliArgs
|
||||
)
|
||||
|
||||
+12
-6
@@ -6,12 +6,10 @@
|
||||
package org.jetbrains.kotlin.gradle.targets.js.yarn
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.internal.project.ProjectInternal
|
||||
import org.gradle.api.logging.Logger
|
||||
import org.gradle.internal.service.ServiceRegistry
|
||||
import org.jetbrains.kotlin.gradle.internal.execWithProgress
|
||||
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.NpmDependency
|
||||
import org.jetbrains.kotlin.gradle.targets.js.npm.NpmDependency.Scope.PEER
|
||||
@@ -31,16 +29,24 @@ abstract class YarnBasics : NpmApi {
|
||||
services: ServiceRegistry,
|
||||
logger: Logger,
|
||||
nodeJs: NodeJsRootExtension,
|
||||
yarnHome: File,
|
||||
command: String,
|
||||
isStandalone: Boolean,
|
||||
dir: File,
|
||||
description: String,
|
||||
args: List<String>
|
||||
) {
|
||||
services.execWithProgress(description) { exec ->
|
||||
exec.executable = nodeJs.requireConfigured().nodeExecutable
|
||||
exec.args = listOf(yarnHome.resolve("bin/yarn.js").absolutePath) +
|
||||
args +
|
||||
val arguments = args +
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
+3
-1
@@ -12,5 +12,7 @@ data class YarnEnv(
|
||||
val downloadUrl: String,
|
||||
val cleanableStore: CleanableStore,
|
||||
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.jetbrains.kotlin.gradle.internal.ConfigurationPhaseAware
|
||||
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.npm.RequiresNpmDependencies
|
||||
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 version by Property("1.22.10")
|
||||
|
||||
var command by Property("yarn")
|
||||
|
||||
var download by Property(true)
|
||||
|
||||
val yarnSetupTaskProvider: TaskProvider<YarnSetupTask>
|
||||
get() = project.tasks
|
||||
.withType(YarnSetupTask::class.java)
|
||||
@@ -77,16 +82,33 @@ open class YarnRootExtension(
|
||||
override fun finalizeConfiguration(): YarnEnv {
|
||||
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(
|
||||
downloadUrl = downloadBaseUrl,
|
||||
cleanableStore = cleanableStore,
|
||||
home = cleanableStore["yarn-v$version"].use(),
|
||||
home = home,
|
||||
executable = getExecutable("yarn", command, "cmd"),
|
||||
standalone = !download,
|
||||
ivyDependency = "com.yarnpkg:yarn:$version@tar.gz"
|
||||
)
|
||||
}
|
||||
|
||||
internal fun executeSetup() {
|
||||
NodeJsRootPlugin.apply(project).executeSetup()
|
||||
|
||||
if (!download) return
|
||||
|
||||
val yarnSetupTask = yarnSetupTaskProvider.get()
|
||||
yarnSetupTask.actions.forEach {
|
||||
it.execute(yarnSetupTask)
|
||||
|
||||
+4
-2
@@ -71,7 +71,8 @@ class YarnWorkspaces : YarnBasics() {
|
||||
services: ServiceRegistry,
|
||||
logger: Logger,
|
||||
nodeJs: NodeJsRootExtension,
|
||||
yarnHome: File,
|
||||
command: String,
|
||||
isStandalone: Boolean,
|
||||
npmProjects: Collection<KotlinCompilationNpmResolution>,
|
||||
cliArgs: List<String>
|
||||
) {
|
||||
@@ -81,7 +82,8 @@ class YarnWorkspaces : YarnBasics() {
|
||||
services,
|
||||
logger,
|
||||
nodeJs,
|
||||
yarnHome,
|
||||
command,
|
||||
isStandalone,
|
||||
nodeJsWorldDir,
|
||||
NpmApi.resolveOperationDescription("yarn"),
|
||||
cliArgs
|
||||
|
||||
Reference in New Issue
Block a user