Does anybody have experience making a Kotlin JS+IR...
# javascript
r
Does anybody have experience making a Kotlin JS+IR share “resources” with a downstream Kotlin JS+IR project? Trying to clean something up here and any clues could be useful
kind of a gradle question specific to the Kotlin JS or Kotlin multiplatform ecosystem, so 🤷
b
Should work out of the box if the consumer is kjs project (as opposed to plain js)
Did you try to inspect generated klib to see if resources are packed?
r
I did not! interesting
I’m guessing the challenge will be the “appropriate” way to programmatically access those resources then
as I’m normed on doing that in a more js way than a traditional kotlin way
b
Is it nodejs or browser based?
r
haha
i’m using hte library in two places, so… yes
but the important one is browser
b
In any case, you should be able to "import/require" them as in normal js project. Make sure you have appropriate webpack loaders, though
r
ok, that’s where I tend to have trouble finding them, or maybe getting the require path correct for them
r
hm… do you know where those resources are supposed to show up before webpack process? I’m not sure I’m finding them
b
To find a correct path, find your extracted module in rootProjectDir/build/js/packages... And then use relative path from imported module's package.json
r
good lead, thanks. 🙂
b
I've just checked on my own project and resources are definitely packed into klib
t
r
interesting - it appears that the module contains the information, but depending on the module in a javascript project isn’t enough to unpack the kotlin directory. This seems likely because i’m using the IR compiler (which means the builder can do things like skip bundling each module as a js lib).
b
Hmm. As a hack, you could pack that module as js with github.com/mpetuska/npm-publish and then depend on it as npm dependency
r
yeah since they’re clearly in the klib i’m writing a task that unzips them into the processedResources directory
that should work
👍 1
relatedly, trying to reliably get the files as inputs for the copy task has become the thread that unfurls my gradle build 🙃. it seems like it should be so straightforward…
b
How come?
Always been super easy
Can you share some code?
r
I couldn’t seem to get access to them by the “implementation” configuration (though there may be better ways), so I made a new configuration that extends implementation. and this sort of works, but triggers a number of configuration time awkwardness in my multiproject. I can definitely affect that in various ways, but it seems awfully fussy
Copy code
val dependencyResources by creating(Copy::class) {
    dependsOn(clientDependencies)
    clientDependencies.files.forEach {
        if (it.exists()) {
            from(zipTree(it).matching {
                exclude(
                    "default",
                    "more stuff here"
                )
            })
        }
    }
}
this is missing two lines, but those are in there, I tried to clean it up slightly to share
Copy code
duplicatesStrategy = DuplicatesStrategy.WARN
into("$buildDir/processedResources/js/main")
after some fussing later, I found that the “jsDefault” configuration meets my needs. looks all clear. thanks for the chats all 🙂
🎉 1