Hello. Kotlin/js Noob here. I’m building an IJ pla...
# javascript
i
Hello. Kotlin/js Noob here. I’m building an IJ platform plugin / VScode extension, where i want to share code between the two, so i have a “common” multiplatform module, with jvm and js targets. I’m trying to understand how to add manage TS dependencies. Continuing in thread ->
Basically project structure is like this:
Copy code
.
├── common <- (kmp - jvm, js)
├── intellij-platform <- (jvm)
├── vscode <- (js)
│   └── node_modules
├── deps <- (idea cache dir)
│   └── ideaIU-2024.1.1
The common module needs to have dependencies on IJ plartform core jars (com.intellij.psi, com.intellij.lang, etc) and on vscode types (@types/vscode) I add the ij platfrom libs from the deps dir (which works) and i’m trying to add the vscode dependencies from node_modules, or from npm but both don’t seem to work
Copy code
kotlin {
    jvm {
        jvmToolchain(libs.versions.java.get().toInt())
    }
    js(IR) {
        moduleName = "substrate-common"
        nodejs {
            @OptIn(ExperimentalDistributionDsl::class)
            distribution {
                outputDirectory.set(layout.buildDirectory.dir("dist"))
            }
        }
        compilations["main"].apply {
            packageJson {
                this.version = project.version.toString()
            }
        }
        useCommonJs()
        binaries.executable()
        generateTypeScriptDefinitions()
        browser {
            commonWebpackConfig {
                cssSupport {
                    enabled.set(true)
                }
            }
        }
    }
    sourceSets {
        commonMain {
            dependencies {
                implementation(libs.kotlin)
            }
        }
        val jvmMain by getting {
            dependencies {
                addIjPlatformDeps()
            }
        }
        val jsMain by getting {
            dependencies {
                implementation(npm("@types/vscode", "^1.89.0"))
                // or this below
                //implementation(npm(directory = file("../vscode/node_modules"), name = "@types/vscode"))
            }
        }
    }
}
tasks.withType<KotlinJsIrLink> {
    compilerOptions.moduleKind.set(MODULE_COMMONJS)
}
tasks.withType<Jar>().configureEach {
    from(sourceSets.map { it.resources })
}

fun KotlinDependencyHandler.addIjPlatformDeps() {
    val platformDeps =
        dependencyCacheDir.resolve("${platformType.ideName}-${project.baseVersion}").resolve("lib")
    logger.quiet("platformDeps: ${platformDeps.absolutePath}")
    implementation(
        files(platformDeps.listFiles { dir, name ->
            name.endsWith(".jar")
        })
    )
}
I don’t get any error during the build but i don’t know if the npm deps are actually added or not, or if i don’t know how to import them in a kotlin file running
./gradlew common:dependencies
shows this:
Copy code
jsMainImplementation (n)
\--- @types/vscode:^1.89.0 (n)
But i don’t see the type i’m expecting to see (
module:vscode.Range
) available (when writing in the common:jsMain source files)
e
I'll try to find some time to explain everything later today. This is also a good idea for a video I was planning to record to then publish on YT.
🙏 1
K 1
i
I’m eagerly waiting…