Missing bundled dependencies when using Kotlin 1.5.30+
Closed this issue · 18 comments
It seems that Kotlin 1.5.30+ has changed the behaviour regarding the way dependencies are declared in the package.json
.
With Kotlin 1.5.21 I see the following behaviour:
- The
package.json
inside<root_folder>/build/js/package.json
contains a single entry inworkspaces
with valuepackages/<project_name-module_name>
- Then in the
<root_folder>/build/js/packages/<project_name-module_name>/package.json
there's indeed all the required npmdependencies
using thefile:/...
format.
In Kotlin 1.5.30+ the behaviour seems to be:
- The
package.json
inside<root_folder>/build/js/package.json
contains multiple entries each pointing to the dependencies
"workspaces": [
"packages/<project_name-module_name>",
"packages_imported/kotlinx-serialization-kotlinx-serialization-json-js-legacy/1.3.0",
"packages_imported/kotlinx-serialization-kotlinx-serialization-core-js-legacy/1.3.0",
"packages_imported/kotlin/1.5.31",
"packages_imported/Kotlin-DateTime-library-kotlinx-datetime-js-legacy/0.2.1",
"packages_imported/kotlin-test-js-runner/1.5.31",
"packages_imported/kotlin-test/1.5.31"
],
- Then in the
<root_folder>/build/js/packages/<project_name-module_name>/package.json
there's no dependencies at all.
So I guess that the plugin code src/main/kotlin/task/NpmPackageAssembleTask.kt#L107 needs to be adapted to this new 1.5.30+ behaviour
The issue is then that the package.json
generated by the plugin does not contain any bundled dependency.
Apologies for the radio silence, but this might actually be a desired behaviour. With 1.5.3x, kotlin changed how dependencies are declared/bundled for IR backend. Since then, all non-npm dependencies (e.g. ktor) are no longer declared in the package.json, but actually get bundled inside the output js binary. Therefore npm-publish plugin only captures npm dependencies when working with IR compilation.
@jush could you outline your setup please? Exact kotlin version, JS backend mode, npm-publish config...
Have a look at the pack
output for this sandbox module (as it has both, npm and kotlin dependencies)
Thanks @mpetuska for coming back to this issue.
I've changed jobs and unfortunately I don't have access anymore to that project.
I'll close this one. Feel free to re-open if you still think it's useful.
I couldn't reproduce it myself so let's just wait and see if anyone else reports it.
Hey there @mpetuska I seem to be struggling with the same issue, the bundle is not having dependencies at all, I am using newest kotlin 1.6.20-M1 (because some things in M1 needed that version). You can find the project here: https://github.com/LukasAnda/Transkribe and actual code is on devel branch
@LukasAnda I see that you're using binaries.executable() as well as LEGACY mode. Can you try switching to binaries.library() and IR mode?
Hey there, as for binaries.library() I can try, but I can't do IR mode since CliKt is not yet compatible with IR, see this issue: https://github.com/ajalt/clikt/blob/027e90cf6903453bc23ae7cbea273777e1bed852/clikt/build.gradle.kts#L25-L35
I want to publish to npm as an executable, will library() work for that?
This plugin no longer aims to support legacy mode. However if you really feel that you cannot avoid implied legacy mode due to clikt dependency, I could make an exception and try to push a hotfix for this case.
Hmm, I've just checked on kamp.ml and clikt does not have any js artefacts. Are you sure it supports js?
Well, they mentioned that they are waiting for one bugfix in Kotlin.js and then they will move to IR but I don't know when that will happen, it's a bug from 1.4.0. So, if you have the time and resources, I'd gladly appreciate if you could fix it for legacy builds and hopefully over time I could switch to IR.
Hmm, I've just checked on kamp.ml and clikt does not have any js artefacts. Are you sure it supports js?
And yes, they support JS, but only the Legacy at the moment
Ok, so I finally had a chance to have another look at this and unfortunately there's nothing I can do to fix this on the plugin side as there's no reliable way to distinguish relevant kotlin-only dependencies anymore. My suggestions are to either switch to IR backend if you can or downgrade to last working kotlin version 1.5.21
Both these options are really not working for me :/ IR backend would be nice but CliKt is not supporting it. And I am unable to use any Kotlin below 1.5.21 because I am on Macbook M1 :/
Yeah, I figured. Sorry you got blocked like that.
Not sure how much help this will be for you, but here are some tips you could try on your particular project to get it working (much easier to do since you have full control over the project and can make assumptions).
- Add all you non-npm dependencies as bundledDependencies manually in npm publication config
- Hook into
assemble<name>NpmPublication
task and add a copy action at the end to copy over relevant extracted js files of those dependencies into publication's node_modules - Enable shrinkwrap.json in your publication config
I can try, I'll look into that later
Or, if possible, would you mind submitting a pull request on my repository?