@@ -10,28 +10,36 @@ import org.gradle.kotlin.dsl.*
10
10
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsEnvSpec
11
11
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
12
12
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnLockMismatchReport
13
- import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnPlugin
14
- import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnRootEnvSpec
13
+ import org.jetbrains.kotlin.gradle.targets.wasm.nodejs.WasmNodeJsEnvSpec
14
+ import org.jetbrains.kotlin.gradle.targets.wasm.nodejs.WasmNodeJsRootPlugin
15
+ import org.jetbrains.kotlin.gradle.targets.web.nodejs.BaseNodeJsEnvSpec
16
+ import org.jetbrains.kotlin.gradle.targets.web.nodejs.CommonNodeJsRootPlugin
15
17
import org.jetbrains.kotlin.gradle.targets.web.yarn.BaseYarnRootEnvSpec
16
18
import org.jetbrains.kotlin.gradle.targets.web.yarn.CommonYarnPlugin
17
19
import util.other.optionalProperty
18
20
import util.other.spacePassword
19
21
import util.other.useProxyRepositories
20
22
import java.io.File
21
23
22
- fun Project.configureNpm () {
23
- val kotlinMasterBuild by optionalProperty()
24
-
25
- val executeNpmLogin by tasks.registering {
24
+ private inline fun <
25
+ reified Plugin : CommonNodeJsRootPlugin ,
26
+ reified Spec : BaseNodeJsEnvSpec
27
+ > Project.registerExecuteNpmLoginTask (
28
+ target : String ,
29
+ npmInstallTaskName : String ,
30
+ useProxy : Boolean ,
31
+ ) {
32
+ val capitalizedTarget = target.replaceFirstChar { it.titlecase() }
33
+ val task = tasks.register(" execute${capitalizedTarget} NpmLogin" ) {
26
34
if (! useProxyRepositories) {
27
- return @registering
35
+ return @register
28
36
}
29
37
30
38
val registryUrl = " https://packages.jetbrains.team/npm/p/krpc/build-deps/"
31
39
32
40
// To prevent leaking of credentials in VCS on dev machine use the build directory config file
33
- val buildYarnConfigFile = File (project.rootDir, " build/js /.yarnrc" )
34
- val buildNpmConfigFile = File (project.rootDir, " build/js /.npmrc" )
41
+ val buildYarnConfigFile = File (project.rootDir, " build/$target /.yarnrc" )
42
+ val buildNpmConfigFile = File (project.rootDir, " build/$target /.npmrc" )
35
43
36
44
val spacePassword: String? = spacePassword
37
45
@@ -66,20 +74,36 @@ fun Project.configureNpm() {
66
74
outputs.file(buildNpmConfigFile).withPropertyName(" buildOutputNpmFile" )
67
75
}
68
76
69
- val useProxy = useProxyRepositories
70
-
71
- plugins.withType(NodeJsRootPlugin ::class .java).configureEach {
72
- rootProject.extensions.configure<NodeJsEnvSpec > {
77
+ plugins.withType<Plugin >().configureEach {
78
+ rootProject.extensions.configure<Spec > {
73
79
download = true
80
+
74
81
if (useProxy) {
75
82
downloadBaseUrl = " https://packages.jetbrains.team/files/p/krpc/build-deps/"
76
83
}
77
84
}
78
85
79
- tasks.named(" kotlinNpmInstall " ).configure {
80
- dependsOn(executeNpmLogin )
86
+ tasks.named(npmInstallTaskName ).configure {
87
+ dependsOn(task )
81
88
}
82
89
}
90
+ }
91
+
92
+ fun Project.configureNpm () {
93
+ val kotlinMasterBuild by optionalProperty()
94
+ val useProxy = useProxyRepositories
95
+
96
+ registerExecuteNpmLoginTask<NodeJsRootPlugin , NodeJsEnvSpec >(
97
+ target = " js" ,
98
+ npmInstallTaskName = " kotlinNpmInstall" ,
99
+ useProxy = useProxy,
100
+ )
101
+
102
+ registerExecuteNpmLoginTask<WasmNodeJsRootPlugin , WasmNodeJsEnvSpec >(
103
+ target = " wasm" ,
104
+ npmInstallTaskName = " kotlinWasmNpmInstall" ,
105
+ useProxy = useProxy,
106
+ )
83
107
84
108
// necessary for CI js tests
85
109
rootProject.plugins.withType<CommonYarnPlugin > {
0 commit comments