Skip to content

Commit 8fa4574

Browse files
committed
Added proxy repository settings for Npm and Yarn
1 parent 6d9cf61 commit 8fa4574

File tree

2 files changed

+102
-1
lines changed

2 files changed

+102
-1
lines changed

build.gradle.kts

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
*/
44

55
import org.jetbrains.kotlin.gradle.plugin.getKotlinPluginVersion
6+
import util.getSpacePassword
7+
import util.getSpaceUsername
68
import util.kotlinVersionParsed
79
import util.libs
810

@@ -64,7 +66,57 @@ if (kotlinVersion != kotlinGPVersion) {
6466
error("KGP version mismatch. Project version: $kotlinVersion, KGP version: $kotlinGPVersion")
6567
}
6668

69+
val executeNpmLogin by tasks.registering {
70+
val registryUrl = "https://packages.jetbrains.team/npm/p/krpc/build-deps/"
71+
72+
// To prevent leaking of credentials in VCS on dev machine use the build directory config file
73+
val buildYarnConfigFile = File(project.rootDir, "build/js/.yarnrc")
74+
val buildYarnYmlConfigFile = File(project.rootDir, "build/js/.yarnrc.yml")
75+
76+
val spaceUsername: String? = getSpaceUsername()
77+
val spacePassword: String? = getSpacePassword()
78+
79+
doLast {
80+
if (spaceUsername == null || spacePassword == null) {
81+
return@doLast
82+
}
83+
84+
if (spacePassword.split(".").size != 3) {
85+
error("Unexpected Space Token format")
86+
}
87+
88+
val outputYarnYmlText = """
89+
npmRegistryServer: "$registryUrl"
90+
npmAlwaysAuth: true
91+
npmAuthToken: "$spacePassword"
92+
""".trimIndent()
93+
94+
buildYarnConfigFile.createNewFile()
95+
buildYarnConfigFile.writeText("registry: $registryUrl")
96+
buildYarnYmlConfigFile.createNewFile()
97+
buildYarnYmlConfigFile.writeText(outputYarnYmlText)
98+
}
99+
100+
outputs.file(buildYarnConfigFile).withPropertyName("buildOutputYarnFile")
101+
outputs.file(buildYarnYmlConfigFile).withPropertyName("buildOutputYarnYmlFile")
102+
}
103+
104+
plugins.withType(org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin::class.java).configureEach {
105+
rootProject.extensions.configure(org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension::class.java) {
106+
download = true
107+
downloadBaseUrl = "https://packages.jetbrains.team/files/p/krpc/build-deps/"
108+
}
109+
110+
tasks.named("kotlinNpmInstall").configure {
111+
dependsOn(executeNpmLogin)
112+
}
113+
}
114+
67115
// necessary for CI js tests
68116
rootProject.plugins.withType<org.jetbrains.kotlin.gradle.targets.js.yarn.YarnPlugin> {
69-
rootProject.the<org.jetbrains.kotlin.gradle.targets.js.yarn.YarnRootExtension>().ignoreScripts = false
117+
rootProject.extensions.configure<org.jetbrains.kotlin.gradle.targets.js.yarn.YarnRootExtension> {
118+
ignoreScripts = false
119+
download = true
120+
downloadBaseUrl = "https://packages.jetbrains.team/files/p/krpc/build-deps/"
121+
}
70122
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
@file:Suppress("DuplicatedCode")
6+
7+
package util
8+
9+
import org.gradle.api.Project
10+
import java.io.File
11+
12+
fun Project.logAbsentProperty(name: String): Nothing? {
13+
logger.info("Property '$name' is not present.")
14+
15+
return null
16+
}
17+
18+
fun Project.getLocalProperties(): java.util.Properties {
19+
return java.util.Properties().apply {
20+
val propertiesDir = File(
21+
rootDir.path
22+
.removeSuffix("/gradle-conventions")
23+
.removeSuffix("/gradle-conventions-settings")
24+
.removeSuffix("/ksp-plugin")
25+
.removeSuffix("/compiler-plugin")
26+
.removeSuffix("/gradle-plugin")
27+
)
28+
val localFile = File(propertiesDir, "local.properties")
29+
if (localFile.exists()) {
30+
localFile.inputStream().use { load(it) }
31+
}
32+
}
33+
}
34+
35+
fun Project.getSpaceUsername(): String? {
36+
val username = "kotlinx.rpc.team.space.username"
37+
return getLocalProperties()[username] as String?
38+
?: providers.gradleProperty(username).orNull
39+
?: System.getenv(username)?.ifEmpty { null }
40+
?: logAbsentProperty(username)
41+
}
42+
43+
fun Project.getSpacePassword(): String? {
44+
val password = "kotlinx.rpc.team.space.password"
45+
return getLocalProperties()[password] as String?
46+
?: providers.gradleProperty(password).orNull
47+
?: System.getenv(password)?.ifEmpty { null }
48+
?: logAbsentProperty(password)
49+
}

0 commit comments

Comments
 (0)