Skip to content

Commit e10c87f

Browse files
committed
Added proxy repository settings for Npm and Yarn
1 parent 8c371f3 commit e10c87f

File tree

2 files changed

+101
-1
lines changed

2 files changed

+101
-1
lines changed

build.gradle.kts

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

55
import org.jetbrains.kotlin.gradle.plugin.getKotlinPluginVersion
6+
import util.kotlinVersionParsed
67
import util.libs
78

89
plugins {
@@ -58,7 +59,57 @@ if (kotlinVersionFull != kotlinGPVersion) {
5859
error("KGP version mismatch. Project version: $kotlinVersionFull, KGP version: $kotlinGPVersion")
5960
}
6061

62+
val executeNpmLogin by tasks.registering {
63+
val registryUrl = "https://packages.jetbrains.team/npm/p/krpc/build-deps/"
64+
65+
// To prevent leaking of credentials in VCS on dev machine use the build directory config file
66+
val buildYarnConfigFile = File(project.rootDir, "build/js/.yarnrc")
67+
val buildYarnYmlConfigFile = File(project.rootDir, "build/js/.yarnrc.yml")
68+
69+
val spaceUsername: String? = getSpaceUsername()
70+
val spacePassword: String? = getSpacePassword()
71+
72+
doLast {
73+
if (spaceUsername == null || spacePassword == null) {
74+
return@doLast
75+
}
76+
77+
if (spacePassword.split(".").size != 3) {
78+
error("Unexpected Space Token format")
79+
}
80+
81+
val outputYarnYmlText = """
82+
npmRegistryServer: "$registryUrl"
83+
npmAlwaysAuth: true
84+
npmAuthToken: "$spacePassword"
85+
""".trimIndent()
86+
87+
buildYarnConfigFile.createNewFile()
88+
buildYarnConfigFile.writeText("registry: $registryUrl")
89+
buildYarnYmlConfigFile.createNewFile()
90+
buildYarnYmlConfigFile.writeText(outputYarnYmlText)
91+
}
92+
93+
outputs.file(buildYarnConfigFile).withPropertyName("buildOutputYarnFile")
94+
outputs.file(buildYarnYmlConfigFile).withPropertyName("buildOutputYarnYmlFile")
95+
}
96+
97+
plugins.withType(org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin::class.java).configureEach {
98+
rootProject.extensions.configure(org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension::class.java) {
99+
download = true
100+
downloadBaseUrl = "https://packages.jetbrains.team/files/p/krpc/build-deps/"
101+
}
102+
103+
tasks.named("kotlinNpmInstall").configure {
104+
dependsOn(executeNpmLogin)
105+
}
106+
}
107+
61108
// necessary for CI js tests
62109
rootProject.plugins.withType<org.jetbrains.kotlin.gradle.targets.js.yarn.YarnPlugin> {
63-
rootProject.the<org.jetbrains.kotlin.gradle.targets.js.yarn.YarnRootExtension>().ignoreScripts = false
110+
rootProject.extensions.configure<org.jetbrains.kotlin.gradle.targets.js.yarn.YarnRootExtension> {
111+
ignoreScripts = false
112+
download = true
113+
downloadBaseUrl = "https://packages.jetbrains.team/files/p/krpc/build-deps/"
114+
}
64115
}
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)