Hi :wave: . I'm struggling a bit with execution environments. I just got `Please choose a JavaScript...
m
Hi 👋 . I'm struggling a bit with execution environments. I just got
Please choose a JavaScript environment to build distributions and run tests.
. I understand the need to specify browser or nodejs for running tests but how does that impact building distribution? I'm building a lib and I would expect the lib to be consumed from both browser and nodejs project so it feels weird having to chose one there.
b
That's impossible with kotlin js unfortunately
It must be either browser or node, but not both
👀 1
m
Wait so how do I make it so that both types of consumers can use my lib?
Should I duplicate the publication somewhow?
b
Not sure it's even possible, since kjs isn't es6 compatible.
blob thinking upside down 2
You might try to build a lib for browser yet consume it from nodejs project. Might work depending on what native APIs you use
m
Another strange thing. Looking at the Gradle metadata for okio , nothing tells if it's browser or node. So I'm guessing it will just throw at compile time because of ... something??
Might work depending on what native APIs you use
Ah, maybe that's what's happening with okio. It's "just" plain js without any specific API so consuming from both is working?
I'm going to try to run a diff between
browser.klib
and
node.klib
see what changes.
(there are no separate Gradle tasks for browser vs node so I suspect it should be identical)
b
There are when you register either
m
There are differences?
Copy code
$ diff -s browser.klib node.klib 
Files browser.klib and node.klib are identical
Which makes sense because I called
jsIrJar
b
Names differ at least
m
I made the rename myself to avoid having them overwriting each other
b
jsBrowserProductionExecutable vs jsNodeProductionExecutable
☝️ 1
m
(
cp apollo-api/build/libs/apollo-api-jsir-3.0.0-alpha08-SNAPSHOT.klib browser.klib
)
Yup, I suspect it's an "executable" thing
But for libs, I don't need "executable"
u
you can make your project multiplatform and add a node and a browser target
m
@uli my problem is that tests do not run on browser (because they use
http
)
So I'm tempted to just use
nodejs()
. The wording of this initial message confused but I think it's fine as I don't care about the main executable
👍 1