Ido Flax
05/29/2024, 8:26 AMIdo Flax
05/29/2024, 8:27 AM.
├── 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
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:
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)Edoardo Luppi
05/29/2024, 9:19 AMIdo Flax
05/29/2024, 7:10 PM