Skip to content

Commit 866d680

Browse files
committed
Fix wasm npm install
1 parent e7e34b1 commit 866d680

File tree

4 files changed

+885
-784
lines changed

4 files changed

+885
-784
lines changed

docs/environment.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,28 @@ Here is a 'simple' guide for solving problems:
363363
- Try different IDE version (last resort)
364364
- Docker
365365
- `Cannot connect to the Docker daemon` - open `Docker Desktop`
366+
- Kotlin/Js or Kotlin/Wasm
367+
- `kotlinUpgradeYarnLock` or `kotlinUpgradeWasmYarnLock` (and also `kotlinNpmInstall` or `kotlinWasmNpmInstall`)
368+
have a funny tendency to fail sometimes, and you don't know why.
369+
I'll tell you!
370+
We use proxy repos, and sometimes dependencies get downloaded from the wrong source.
371+
Make sure ALL urls in `.lock` files start with `https://packages.jetbrains.team/npm/p/krpc/build-deps/`.
372+
If something doesn't work, your steps are:
373+
- Delete `.lock` file
374+
- Delete `<REPO_ROOT>/build/js` / `<REPO_ROOT>/build/wasm`
375+
- Run `kotlinUpgradeYarnLock` / `kotlinUpgradeWasmYarnLock`
376+
- If the problem persists:
377+
- Check that `<REPO_ROOT>/build/<target>/.npmrc` AND `<REPO_ROOT>/build/<target>/.yarnrc` are present
378+
- Check that `.yarnrc` contains one line: `registry: "https://packages.jetbrains.team/npm/p/krpc/build-deps/"`
379+
- Check that `.npmrc` contains following lines:
380+
- `registry="https://packages.jetbrains.team/npm/p/krpc/build-deps/"`
381+
- `always-auth=true`
382+
- `save-exact=true`
383+
- `//packages.jetbrains.team/npm/p/krpc/build-deps/:_authToken=<your_auth_token>`,
384+
where `<your_auth_token>` is from [proxy-repositories.md](proxy-repositories.md) guide.
385+
- Check that `<USER_HOME>/.npmrc` / `<USER_HOME>/.yarnrc` doesn't interfere
386+
- Use `/Users/<USER>/.gradle/nodejs/node-v22.0.0-darwin-arm64/bin/node /Users/<USER>/.gradle/yarn/yarn-v1.22.17/bin/yarn.js --ignore-engines --verbose --ignore-scripts`
387+
command to debug. Replace versions of tools if needed.
366388

367389
Something doesn't work, and you are sure it's not your fault? Report it appropriately! Don't be lazy.
368390

@@ -377,7 +399,8 @@ all included builds (not subprojects) must reflect the change.
377399
- `checkLegacyAbi` / `updateLegacyAbi` - ABI checks.
378400
See https://kotlinlang.org/docs/whatsnew22.html#binary-compatibility-validation-included-in-kotlin-gradle-plugin.
379401
Former BCV: https://github.com/Kotlin/binary-compatibility-validator
380-
- `kotlinUpgradeYarnLock` - update [kotlin-js-store](../kotlin-js-store) contents, usually after Kotlin version update.
402+
- `kotlinUpgradeYarnLock` / `kotlinWasmUpgradeYarnLock` - update [kotlin-js-store](../kotlin-js-store) contents,
403+
usually after Kotlin version update.
381404
- `updateDocsChangelog` - put modified [CONTRIBUTING.md](../CONTRIBUTING.md) into [topics](pages/kotlinx-rpc/topics)
382405
- `detekt` - run detekt checks.
383406
- `verifyPlatformTable` / `dumpPlatformTable` - Update [platforms.topic](pages/kotlinx-rpc/topics/platforms.topic)

gradle-conventions/src/main/kotlin/util/tasks/npm.kt

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,36 @@ import org.gradle.kotlin.dsl.*
1010
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsEnvSpec
1111
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
1212
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
1517
import org.jetbrains.kotlin.gradle.targets.web.yarn.BaseYarnRootEnvSpec
1618
import org.jetbrains.kotlin.gradle.targets.web.yarn.CommonYarnPlugin
1719
import util.other.optionalProperty
1820
import util.other.spacePassword
1921
import util.other.useProxyRepositories
2022
import java.io.File
2123

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") {
2634
if (!useProxyRepositories) {
27-
return@registering
35+
return@register
2836
}
2937

3038
val registryUrl = "https://packages.jetbrains.team/npm/p/krpc/build-deps/"
3139

3240
// 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")
3543

3644
val spacePassword: String? = spacePassword
3745

@@ -66,20 +74,36 @@ fun Project.configureNpm() {
6674
outputs.file(buildNpmConfigFile).withPropertyName("buildOutputNpmFile")
6775
}
6876

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> {
7379
download = true
80+
7481
if (useProxy) {
7582
downloadBaseUrl = "https://packages.jetbrains.team/files/p/krpc/build-deps/"
7683
}
7784
}
7885

79-
tasks.named("kotlinNpmInstall").configure {
80-
dependsOn(executeNpmLogin)
86+
tasks.named(npmInstallTaskName).configure {
87+
dependsOn(task)
8188
}
8289
}
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+
)
83107

84108
// necessary for CI js tests
85109
rootProject.plugins.withType<CommonYarnPlugin> {

0 commit comments

Comments
 (0)