Pavel Kazlovich
12/08/2025, 4:55 PM@JsModule?
I'm writing an internal library that has a few JS modules accessed via file:@JsModule (the files are tucked into resources) . Library's tests work fine, but the app that uses the published library complains about missing those JS modules. The library is published using maven-publish and I see that the original JS modules are packed into the resulting klib. So I guess library's JS modules are not being copied into app's dist, which leads to @JsModule having no chance to resolve them.
Is there a way to make Gradle copy resources from dependencies into the final dist? Or maybe it's doing something like this already, but the paths used by @JsModule become invalid due to location change? I've seen that some people publish JS modules to NPM and then make their Kotlin libraries depend on that, thus avoiding the whole issue, but I feel that there should be a more straightforward way.Robert Jaros
12/08/2025, 5:14 PMPavel Kazlovich
12/08/2025, 5:15 PMPavel Kazlovich
12/09/2025, 6:57 PMresources.srcDir() for wasmJs target and everything works. It assumes a few things, so it's not very reusable, but it suits me.
val extractWasmResourcesFromAllInternalLibs by tasks.registering(Sync::class) {
val getConfig = {
configurations.getByName("wasmJsRuntimeClasspath")
}
dependsOn(getConfig())
val sourcePaths = getConfig()
.incoming
.artifactView {
lenient(true)
attributes {
attribute(KotlinPlatformType.attribute, KotlinPlatformType.wasm)
}
componentFilter { componentIdentifier ->
componentIdentifier.displayName.startsWith(/* you group here, e.g. "my.team" */)
}
}
.artifacts
.resolvedArtifacts
.map { resolvedArtifactResult ->
resolvedArtifactResult.map {
zipTree(it.file)
.matching {
include(/* pattern for your JS module root folder here, e.g. "src/**" */)
}
}
}
from(sourcePaths)
into(layout.buildDirectory.dir("extracted/jsModules"))
}
kotlin {
sourceSets {
val wasmJsMain by getting {
resources.srcDir(extractWasmResourcesFromAllInternalLibs)
}
}
}CLOVIS
12/09/2025, 8:35 PM(reflection logic was expecting a different class than the one it was getting)Can you send a bit more information? I'd like to fix this if I can
Pavel Kazlovich
12/09/2025, 8:42 PMCLOVIS
12/09/2025, 8:43 PMPavel Kazlovich
12/09/2025, 8:50 PM