[Gradle, JS] Not resolve configuration with nodejs and yarn if it should not be downloaded
This commit is contained in:
+32
-2
@@ -1045,14 +1045,44 @@ class GeneralKotlin2JsGradlePluginIT : KGPBaseTest() {
|
|||||||
build("checkDownloadedFolder")
|
build("checkDownloadedFolder")
|
||||||
|
|
||||||
build("checkIfLastModifiedNotNow", "--rerun-tasks")
|
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")
|
@DisplayName("Yarn.lock persistence")
|
||||||
@GradleTest
|
@GradleTest
|
||||||
fun testYarnLockStore(gradleVersion: GradleVersion) {
|
fun testYarnLockStore(gradleVersion: GradleVersion) {
|
||||||
project("cleanTask", gradleVersion) {
|
project("nodeJsDownload", gradleVersion) {
|
||||||
buildGradle.modify(::transformBuildScriptWithPluginsDsl)
|
|
||||||
build("assemble") {
|
build("assemble") {
|
||||||
assertFileExists(projectPath.resolve("kotlin-js-store").resolve("yarn.lock"))
|
assertFileExists(projectPath.resolve("kotlin-js-store").resolve("yarn.lock"))
|
||||||
assert(
|
assert(
|
||||||
|
|||||||
+15
@@ -0,0 +1,15 @@
|
|||||||
|
plugins {
|
||||||
|
id("org.jetbrains.kotlin.js")
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenLocal()
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
js {
|
||||||
|
nodejs()
|
||||||
|
}
|
||||||
|
}
|
||||||
+11
@@ -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>
|
||||||
+10
@@ -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!")
|
||||||
|
}
|
||||||
+23
-19
@@ -50,26 +50,29 @@ abstract class NodeJsSetupTask : DefaultTask() {
|
|||||||
internal lateinit var configuration: Provider<Configuration>
|
internal lateinit var configuration: Provider<Configuration>
|
||||||
|
|
||||||
@get:Classpath
|
@get:Classpath
|
||||||
val nodeJsDist: File by lazy {
|
@get:Optional
|
||||||
val repo = project.repositories.ivy { repo ->
|
val nodeJsDist: File? by lazy {
|
||||||
repo.name = "Node Distributions at ${downloadBaseUrl}"
|
if (shouldDownload) {
|
||||||
repo.url = URI(downloadBaseUrl)
|
val repo = project.repositories.ivy { repo ->
|
||||||
|
repo.name = "Node Distributions at ${downloadBaseUrl}"
|
||||||
|
repo.url = URI(downloadBaseUrl)
|
||||||
|
|
||||||
repo.patternLayout {
|
repo.patternLayout {
|
||||||
it.artifact("v[revision]/[artifact](-v[revision]-[classifier]).[ext]")
|
it.artifact("v[revision]/[artifact](-v[revision]-[classifier]).[ext]")
|
||||||
|
}
|
||||||
|
repo.metadataSources { it.artifact() }
|
||||||
|
repo.content { it.includeModule("org.nodejs", "node") }
|
||||||
}
|
}
|
||||||
repo.metadataSources { it.artifact() }
|
val startDownloadTime = System.currentTimeMillis()
|
||||||
repo.content { it.includeModule("org.nodejs", "node") }
|
val dist = configuration.get().files.single()
|
||||||
}
|
val downloadDuration = System.currentTimeMillis() - startDownloadTime
|
||||||
val startDownloadTime = System.currentTimeMillis()
|
if (downloadDuration > 0) {
|
||||||
val dist = configuration.get().files.single()
|
KotlinBuildStatsService.getInstance()
|
||||||
val downloadDuration = System.currentTimeMillis() - startDownloadTime
|
?.report(NumericalMetrics.ARTIFACTS_DOWNLOAD_SPEED, dist.length() * 1000 / downloadDuration)
|
||||||
if (downloadDuration > 0) {
|
}
|
||||||
KotlinBuildStatsService.getInstance()
|
project.repositories.remove(repo)
|
||||||
?.report(NumericalMetrics.ARTIFACTS_DOWNLOAD_SPEED, dist.length() * 1000 / downloadDuration)
|
dist
|
||||||
}
|
} else null
|
||||||
project.repositories.remove(repo)
|
|
||||||
dist
|
|
||||||
}
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
@@ -81,6 +84,7 @@ abstract class NodeJsSetupTask : DefaultTask() {
|
|||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
@TaskAction
|
@TaskAction
|
||||||
fun exec() {
|
fun exec() {
|
||||||
|
if (!shouldDownload) return
|
||||||
logger.kotlinInfo("Using node distribution from '$nodeJsDist'")
|
logger.kotlinInfo("Using node distribution from '$nodeJsDist'")
|
||||||
|
|
||||||
var dirHash: String? = null
|
var dirHash: String? = null
|
||||||
@@ -93,7 +97,7 @@ abstract class NodeJsSetupTask : DefaultTask() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val tmpDir = temporaryDir
|
val tmpDir = temporaryDir
|
||||||
unpackNodeArchive(nodeJsDist, tmpDir)
|
unpackNodeArchive(nodeJsDist!!, tmpDir)
|
||||||
|
|
||||||
if (upToDate && fileHasher.calculateDirHash(tmpDir.resolve(destination.name))!! == dirHash) {
|
if (upToDate && fileHasher.calculateDirHash(tmpDir.resolve(destination.name))!! == dirHash) {
|
||||||
tmpDir.deleteRecursively()
|
tmpDir.deleteRecursively()
|
||||||
|
|||||||
+23
-19
@@ -62,25 +62,28 @@ open class YarnSetupTask : DefaultTask() {
|
|||||||
internal lateinit var configuration: Provider<Configuration>
|
internal lateinit var configuration: Provider<Configuration>
|
||||||
|
|
||||||
@get:Classpath
|
@get:Classpath
|
||||||
val yarnDist: File by lazy {
|
@get:Optional
|
||||||
val repo = project.repositories.ivy { repo ->
|
val yarnDist: File? by lazy {
|
||||||
repo.name = "Yarn Distributions at ${downloadUrl}"
|
if (shouldDownload) {
|
||||||
repo.url = URI(downloadUrl)
|
val repo = project.repositories.ivy { repo ->
|
||||||
repo.patternLayout {
|
repo.name = "Yarn Distributions at ${downloadUrl}"
|
||||||
it.artifact("v[revision]/[artifact](-v[revision]).[ext]")
|
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() }
|
val startDownloadTime = System.currentTimeMillis()
|
||||||
repo.content { it.includeModule("com.yarnpkg", "yarn") }
|
val dist = configuration.get().files.single()
|
||||||
}
|
val downloadDuration = System.currentTimeMillis() - startDownloadTime
|
||||||
val startDownloadTime = System.currentTimeMillis()
|
if (downloadDuration > 0) {
|
||||||
val dist = configuration.get().files.single()
|
KotlinBuildStatsService.getInstance()
|
||||||
val downloadDuration = System.currentTimeMillis() - startDownloadTime
|
?.report(NumericalMetrics.ARTIFACTS_DOWNLOAD_SPEED, dist.length() * 1000 / downloadDuration)
|
||||||
if (downloadDuration > 0) {
|
}
|
||||||
KotlinBuildStatsService.getInstance()
|
project.repositories.remove(repo)
|
||||||
?.report(NumericalMetrics.ARTIFACTS_DOWNLOAD_SPEED, dist.length() * 1000 / downloadDuration)
|
dist
|
||||||
}
|
} else null
|
||||||
project.repositories.remove(repo)
|
|
||||||
dist
|
|
||||||
}
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
@@ -91,6 +94,7 @@ open class YarnSetupTask : DefaultTask() {
|
|||||||
|
|
||||||
@TaskAction
|
@TaskAction
|
||||||
fun setup() {
|
fun setup() {
|
||||||
|
if (!shouldDownload) return
|
||||||
logger.kotlinInfo("Using yarn distribution from '$yarnDist'")
|
logger.kotlinInfo("Using yarn distribution from '$yarnDist'")
|
||||||
|
|
||||||
var dirHash: String? = null
|
var dirHash: String? = null
|
||||||
@@ -103,7 +107,7 @@ open class YarnSetupTask : DefaultTask() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val tmpDir = temporaryDir
|
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) {
|
if (upToDate && fileHasher.calculateDirHash(tmpDir.resolve(destination.name))!! == dirHash) {
|
||||||
tmpDir.deleteRecursively()
|
tmpDir.deleteRecursively()
|
||||||
|
|||||||
Reference in New Issue
Block a user