https://kotlinlang.org logo
c

czyzby

02/10/2018, 9:28 PM
Would anyone mind taking a look at my multiplatform JVM/JS project attempt? I wonder if I got the configuration right. https://github.com/czyzby/kotlin-multiplatform-example
a

anton.bannykh

02/12/2018, 9:30 AM
Hi! At glance I can only see one issue: using
unpackDependenciesTestKotlinJs
. It was a task generated by the kotlin-dce-js plugin. We've removed it in
1.2.20
(Sorry =( )
What you can do now is just always use DCE
It will copy all the dependencies into build/kotlin-js-min (or build/kotlin-min-js, I a bit hazy on that)
So you won't need populateNodeModules task anymore
Setting is to true make the DCE tool to skip the minification altogether and just to the copying.
c

czyzby

02/12/2018, 6:51 PM
@anton.bannykh Is there a way to make DCE copy
meta.js
files as well? My tests fail without that.
@anton.bannykh DCE strips this call:
Kotlin.defineModule('client', _);
from all JS libraries and I'm unable to run the tests.
There's also seem to be no way to create a custom DCE task...
Copy code
task customDce(type: org.jetbrains.kotlin.gradle.tasks.KotlinJsDce, dependsOn: compileKotlin2Js) {
    classpath = configurations.compile
    source compileKotlin2Js.outputFile
    dceOptions {
        devMode = true
        outputDirectory = "$build/node_modules/"
    }
    destinationDir = "$build/node_modules/"
}
This throws an exception, because
destinationDir
is unknown. If I remove the
destinationDir
line, it complains about missing
destinationDir
property. ><
I'm going to stick with
populateNodeModules
for now.
a

anton.bannykh

02/13/2018, 11:25 AM
@czyzby DCE is supposed to be run just before bundle your entire application for production use. Both problems (missing meta.js and missing Kotlin.defineModule) suggest you are trying to use the DCE output as a compile-time dependency. Which is not the intended application of the DCE tool.
@czyzby You can use the DCE output at runtime for various reasons (convenience, making sure DCE produces correct code, etc) though
As for the last one I think you could do the following:
Copy code
task customDce(dependsOn: [compileKotlin2Js, runDceKotlinJs]) {
  runDceKotlinJs.dceOptions {
    devMode = true
    outputDirectory = "$build/node_modules/"
  }
}
c

czyzby

02/13/2018, 4:27 PM
@anton.bannykh Not quite, you'd have to put the
runDceKotlinJs.dceOptions
in `doLast`/`doFirst`, I think. And this prevents from using the original
runDceKotlinJs
without dev mode in the same pipeline as
customDce
, which is something I wanted to avoid.
Anyway, I wanted to replace
populateNodeModules
with DCE, but since even in
devMode
it strips module registration, I simply cannot.
a

anton.bannykh

02/13/2018, 4:46 PM
@czyzby Well, I have a working configuration similar to that. Also I was told doFirst is already too late to change dce options. But then again, I am not a Gradle guru by no means 😃
BTW having populateNodeModules task is by no means a bad solution. In my experience its only drawback is that it might scare people a bit 😃
Still, what do you mean by "using the original
runDceKotlinJs
without dev mode in the same pipeline as `customDce`"? Do you want to use them both during the same build?
Oh, and by "stripping module registration" do you mean removing
Kotlin.defineModule
by any chance? In that case please note that's a marker function, it doesn't do anything: https://github.com/JetBrains/kotlin/blob/7bee2ceac7a63ea1bbecc47de1c40aa31a95ea72/js/js.libraries/src/js/markerFunctions.js#L21
It's only use is to provide a hint to the inliner during compilation
So it shouldn't matter at runtime
Well, it DCE remove actual commonjs exports - that's a bug, we should fix it.
Also could you double check that DCE alters the js files in devMode? Because it really shouldn't. If it does, most likely the devMode wasn't enabled at all.
c

czyzby

02/13/2018, 7:51 PM
@anton.bannykh I already deleted my DCE-based config, but I was getting
module not defined
errors all over the tests.
When I copied files from
populateNodeModules
manually into the DCE output folder (without running DCE, of course) and rerun the tests, everything was working as expected.
I honestly don't think I have the configuration saved, but I can try setting up a separate branch in the multiplatform example project if that helps. Or just paste a snippet with what I've done.
I basically changed
'build/node_modules/*.js',
in Karma config to two output folders from the DCE tasks and run both in dev mode.
a

anton.bannykh

02/14/2018, 11:40 AM
@czyzby I'll try to look into your project later this week. My gut feeling is that it should be possible to use the DCE tool for that. But like I said it is perfectly fine to have populateNodeModules task. 😃 I am just trying to understand whether DCE tool is working as intended and how it could be applied to various use-cases. 😃