[Gradle, JS] Not resolve configuration with nodejs and yarn if it should not be downloaded

This commit is contained in:
Ilya Goncharov
2021-11-22 14:19:52 +03:00
committed by Space
parent 5020d5f2f9
commit e32a1ca562
6 changed files with 114 additions and 40 deletions
@@ -1045,14 +1045,44 @@ class GeneralKotlin2JsGradlePluginIT : KGPBaseTest() {
build("checkDownloadedFolder")
build("checkIfLastModifiedNotNow", "--rerun-tasks")
buildGradle.modify {
it + "\n" +
"""
rootProject.plugins.withType<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin> {
rootProject.the<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension>().nodeVersion = "unspecified"
rootProject.the<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension>().download = false
}
"""
}
}
}
@DisplayName("Disable download should not download Node.JS and Yarn")
@GradleTest
fun testNodeJsAndYarnNotDownloaded(gradleVersion: GradleVersion) {
project("nodeJsDownload", gradleVersion) {
buildGradleKts.modify {
it + "\n" +
"""
rootProject.plugins.withType<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin> {
rootProject.the<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension>().nodeVersion = "unspecified"
rootProject.the<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension>().download = false
}
rootProject.plugins.withType<org.jetbrains.kotlin.gradle.targets.js.yarn.YarnPlugin> {
rootProject.the<org.jetbrains.kotlin.gradle.targets.js.yarn.YarnRootExtension>().version = "unspecified"
rootProject.the<org.jetbrains.kotlin.gradle.targets.js.yarn.YarnRootExtension>().download = false
}
"""
}
build("assemble")
}
}
@DisplayName("Yarn.lock persistence")
@GradleTest
fun testYarnLockStore(gradleVersion: GradleVersion) {
project("cleanTask", gradleVersion) {
buildGradle.modify(::transformBuildScriptWithPluginsDsl)
project("nodeJsDownload", gradleVersion) {
build("assemble") {
assertFileExists(projectPath.resolve("kotlin-js-store").resolve("yarn.lock"))
assert(
@@ -0,0 +1,15 @@
plugins {
id("org.jetbrains.kotlin.js")
}
repositories {
mavenLocal()
mavenCentral()
}
kotlin {
js {
nodejs()
}
}
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>CleanTask</title>
<script src="CleanTask.js"></script>
</head>
<body>
</body>
</html>
@@ -0,0 +1,10 @@
/*
* 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.
*/
import kotlinx.browser.document
fun main() {
document.write("Hello, world!")
}
@@ -50,26 +50,29 @@ abstract class NodeJsSetupTask : DefaultTask() {
internal lateinit var configuration: Provider<Configuration>
@get:Classpath
val nodeJsDist: File by lazy {
val repo = project.repositories.ivy { repo ->
repo.name = "Node Distributions at ${downloadBaseUrl}"
repo.url = URI(downloadBaseUrl)
@get:Optional
val nodeJsDist: File? by lazy {
if (shouldDownload) {
val repo = project.repositories.ivy { repo ->
repo.name = "Node Distributions at ${downloadBaseUrl}"
repo.url = URI(downloadBaseUrl)
repo.patternLayout {
it.artifact("v[revision]/[artifact](-v[revision]-[classifier]).[ext]")
repo.patternLayout {
it.artifact("v[revision]/[artifact](-v[revision]-[classifier]).[ext]")
}
repo.metadataSources { it.artifact() }
repo.content { it.includeModule("org.nodejs", "node") }
}
repo.metadataSources { it.artifact() }
repo.content { it.includeModule("org.nodejs", "node") }
}
val startDownloadTime = System.currentTimeMillis()
val dist = configuration.get().files.single()
val downloadDuration = System.currentTimeMillis() - startDownloadTime
if (downloadDuration > 0) {
KotlinBuildStatsService.getInstance()
?.report(NumericalMetrics.ARTIFACTS_DOWNLOAD_SPEED, dist.length() * 1000 / downloadDuration)
}
project.repositories.remove(repo)
dist
val startDownloadTime = System.currentTimeMillis()
val dist = configuration.get().files.single()
val downloadDuration = System.currentTimeMillis() - startDownloadTime
if (downloadDuration > 0) {
KotlinBuildStatsService.getInstance()
?.report(NumericalMetrics.ARTIFACTS_DOWNLOAD_SPEED, dist.length() * 1000 / downloadDuration)
}
project.repositories.remove(repo)
dist
} else null
}
init {
@@ -81,6 +84,7 @@ abstract class NodeJsSetupTask : DefaultTask() {
@Suppress("unused")
@TaskAction
fun exec() {
if (!shouldDownload) return
logger.kotlinInfo("Using node distribution from '$nodeJsDist'")
var dirHash: String? = null
@@ -93,7 +97,7 @@ abstract class NodeJsSetupTask : DefaultTask() {
}
val tmpDir = temporaryDir
unpackNodeArchive(nodeJsDist, tmpDir)
unpackNodeArchive(nodeJsDist!!, tmpDir)
if (upToDate && fileHasher.calculateDirHash(tmpDir.resolve(destination.name))!! == dirHash) {
tmpDir.deleteRecursively()
@@ -62,25 +62,28 @@ open class YarnSetupTask : DefaultTask() {
internal lateinit var configuration: Provider<Configuration>
@get:Classpath
val yarnDist: File by lazy {
val repo = project.repositories.ivy { repo ->
repo.name = "Yarn Distributions at ${downloadUrl}"
repo.url = URI(downloadUrl)
repo.patternLayout {
it.artifact("v[revision]/[artifact](-v[revision]).[ext]")
@get:Optional
val yarnDist: File? by lazy {
if (shouldDownload) {
val repo = project.repositories.ivy { repo ->
repo.name = "Yarn Distributions at ${downloadUrl}"
repo.url = URI(downloadUrl)
repo.patternLayout {
it.artifact("v[revision]/[artifact](-v[revision]).[ext]")
}
repo.metadataSources { it.artifact() }
repo.content { it.includeModule("com.yarnpkg", "yarn") }
}
repo.metadataSources { it.artifact() }
repo.content { it.includeModule("com.yarnpkg", "yarn") }
}
val startDownloadTime = System.currentTimeMillis()
val dist = configuration.get().files.single()
val downloadDuration = System.currentTimeMillis() - startDownloadTime
if (downloadDuration > 0) {
KotlinBuildStatsService.getInstance()
?.report(NumericalMetrics.ARTIFACTS_DOWNLOAD_SPEED, dist.length() * 1000 / downloadDuration)
}
project.repositories.remove(repo)
dist
val startDownloadTime = System.currentTimeMillis()
val dist = configuration.get().files.single()
val downloadDuration = System.currentTimeMillis() - startDownloadTime
if (downloadDuration > 0) {
KotlinBuildStatsService.getInstance()
?.report(NumericalMetrics.ARTIFACTS_DOWNLOAD_SPEED, dist.length() * 1000 / downloadDuration)
}
project.repositories.remove(repo)
dist
} else null
}
init {
@@ -91,6 +94,7 @@ open class YarnSetupTask : DefaultTask() {
@TaskAction
fun setup() {
if (!shouldDownload) return
logger.kotlinInfo("Using yarn distribution from '$yarnDist'")
var dirHash: String? = null
@@ -103,7 +107,7 @@ open class YarnSetupTask : DefaultTask() {
}
val tmpDir = temporaryDir
extract(yarnDist, tmpDir) // parent because archive contains name already
extract(yarnDist!!, tmpDir) // parent because archive contains name already
if (upToDate && fileHasher.calculateDirHash(tmpDir.resolve(destination.name))!! == dirHash) {
tmpDir.deleteRecursively()