I'm using <npm-publish> plugin (by Martynas Petuška) and after I upgraded to Kotlin 1.5.30 the `pack...
j
I'm using npm-publish plugin (by Martynas Petuška) and after I upgraded to Kotlin 1.5.30 the
packages.json
generated has neither
dependencies
nor
bundledDependencies
entries. Do we need to explicitly set those from now on?
b
Which backend do you use?
For IR you need to set binaries.library() in your js target config
Also do you actually have any npm() or devNpm() dependencies declared?
j
I'm using LEGACY
no, I don't have depdencies actually it's pure data crunching in Kotlin
b
Hmm, I kinda dropped legacy support since v2.0.0 (as in stopped explicitly testing it). Are you able to switch to IR backend? If not, please file an issue in GH and I'll have a look over the weekend.
j
thanks, will take a look. There was some reason we were using LEGACY but I can't remember now
b
You should still have stdlib as an implicit dependency then. Weird. Is your project oss for me to have a look at?
j
unfortunately not
I might try to create a small repro project
👍 1
b
Just clone your gradle configs and anonymize relevant bits there. Sources are irrelevant to this issue
P.S. don't be afraid to just @Big Chungus tag me in the future. Always happy to assist.
👍 2
j
I just created a new multiplatform project using IntelliJ CE and followed the https://github.com/mpetuska/npm-publish#setup instructions for the legacy:
Copy code
kotlin {
    ...
    js(LEGACY) {
        browser()
    }
    ...
}
npmPublishing {
    repositories {
        repository("npmjs") {
            registry = uri("<https://registry.npmjs.org>")
            authToken = "asdhkjsdfjvhnsdrishdl"
        }
    }
}
and it turns out that with above there is no
assembleJsNpmPublication
at all. Then, if I add
binaries.executable()
to the js lambda:
Copy code
js(LEGACY) {
        browser()
        binaries.executable()
    }
I get the
assembleJsNpmPublication
gradle task but there are no dependencies in the generated
packages.json
Not sure if this information is useful... Meanwhile I'll look into use the IR backend
I've been investigating a bit more and with Kotlin 1.5.21 I see the following behaviour: • The
package.json
inside
<root_folder>/build/js/package.json
contains a single entry in
workspaces
with value
packages/<project_name-module_name>
• Then in the
<root_folder>/build/js/packages/<project_name-module_name>/package.json
there's indeed all the required npm
dependencies
using the
file:/...
format. In Kotlin 1.5.30+ the behaviour is: • The
package.json
inside
<root_folder>/build/js/package.json
contains multiple entries each pointing to the dependencies
Copy code
"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 https://github.com/mpetuska/npm-publish/blob/master/src/main/kotlin/task/NpmPackageAssembleTask.kt#L107 needs to be adapted to this new 1.5.30+ behaviour.
b
Good spot! Care to raise a PR or an issue?
j
I can create and issue. If I would do a PR it would need to handle both 1.5.21 and 1.5.30+ behaviour, wouldn't it?
b
No, just 1.5.31 is sufficient. I'm evolving the plugin in a look-ahead manner. Meaning a specific version focuses on the latest available Kotlin version support (specified in release notes)
I'm a one man team behind it, and simply don't have the capacity to ensure backwards compatibility
j
ok (btw, you might want to update the Kotlin version in the release notes
Versions
section of the last release https://github.com/mpetuska/npm-publish/releases/tag/v2.1.1)
b
Done! That was a messy release 😹
Wait, 1.5.21 was actually correct as it was the kotlin version used to build the plugin (gradle limitations). But I see how that might be confusing...
j
aahhh
my bad
apologies I indeed got confused
Issue created: https://github.com/mpetuska/npm-publish/issues/30 I'll take a look at doing a PR but can't promise when (if at all) will be ready
b
Ping me if you do start working on a pr. Otherwise I'll look into it during the weekend
j
I can use one hour now and maybe tomorrow a few more hours. Let's see how far I get. I'll set a reminder to let you know how it goes before the weekend
b
Thanks
j
This gets tricky... In a project with more than one Kotlin JS/multiplatform module the
build/js/package.json
now contains all the
workspaces
for all the modules. Even though not all dependencies are used in all the modules 😕
b
Can you not solve this with when statements accounting for each case?
j
not sure I follow... Within
File.copyKotlinDependencies()
I don't see how to get the dependencies declared by the current module to be able to discern which one of the
workspaces
I should copy to the
node_modules
folder...
b
Replace that single method with three tailored for each usecase and invoke them via when statement
j
hmmm still don't understand what you mean... This is my `build/js/package.json`:
Copy code
{
  "name": "sim_shared",
  "version": "unspecified",
  "private": true,
  "workspaces": [
    "packages/sim_shared-sim_formatting",
    "packages/sim_shared-sim_shared",
    "packages_imported/kotlin/1.5.31",
    "packages_imported/kotlin-test-js-runner/1.5.31",
    "packages_imported/kotlin-test/1.5.31",
    "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-DateTime-library-kotlinx-datetime-js-legacy/0.2.1"
  ],
  "resolutions": {},
  "devDependencies": {},
  "dependencies": {},
  "peerDependencies": {},
  "optionalDependencies": {},
  "bundledDependencies": []
}
and then I have the first kotlin js module `build/js/packages/sim_shared-sim_formatting/package.json`:
Copy code
{
  "name": "sim_shared-sim_formatting",
  "version": "0.7.0-SNAPSHOT",
  "main": "kotlin/sim_shared-sim_formatting.js",
  "devDependencies": {},
  "dependencies": {},
  "peerDependencies": {},
  "optionalDependencies": {},
  "bundledDependencies": []
}
and finally a second kotlin js module `build/js/packages/sim_shared-sim_shared/package.json`:
Copy code
{
  "name": "sim_shared-sim_shared",
  "version": "0.7.0-SNAPSHOT",
  "main": "kotlin/sim_shared-sim_shared.js",
  "devDependencies": {},
  "dependencies": {},
  "peerDependencies": {},
  "optionalDependencies": {},
  "bundledDependencies": []
}
when I call
./gradlew clean assembleJsNpmPublication
I don't see how to know which workspace belongs to which module. The top-level package.json already has all of the workspaces:
Copy code
./gradlew clean assembleJsNpmPublication

> Task :sim_formatting:assembleJsNpmPublication
copyKotlinDependencies: workspaces: [packages/sim_shared-sim_formatting, packages/sim_shared-sim_shared, packages_imported/kotlin/1.5.31, packages_imported/kotlin-test-js-runner/1.5.31, packages_imported/kotlin-test/1.5.31, 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-DateTime-library-kotlinx-datetime-js-legacy/0.2.1]

> Task :sim_shared:assembleJsNpmPublication
copyKotlinDependencies: workspaces: [packages/sim_shared-sim_formatting, packages/sim_shared-sim_shared, packages_imported/kotlin/1.5.31, packages_imported/kotlin-test-js-runner/1.5.31, packages_imported/kotlin-test/1.5.31, 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-DateTime-library-kotlinx-datetime-js-legacy/0.2.1]
and
sim_formatting
should only have dependency to Kotlin 1.5.31 (no dependency to kotlinx serialization)
b
Hmm, actually I think you can just get rid of that and instead look into publicPackageJson task output
I was meaning to hook into that for a while now
j
ok... this is now getting trickier for me. I'm not familiar with that. I'll try to take a look tomorrow and report back. Thanks!
This is the branch I've been working on https://github.com/jush/npm-publish/tree/fix/missing_bundled_dependencies_%2330 It doesn't handle the multiple modules issue I mentioned above. I tried to find a way but I don't know how to do it. Hopefully you can find a way to address that.
just wanted to let you know that I haven't gotten any further so hopefully you can figure out something during the weekend. Feel free to ping me if you want me to test something.
b
No worries. I'll see what I can do over the weekend. Thanks for all the detailed reports. That's a huge help already!
👍 1
j
Martynas, did you have a chance to take a look at this issue?
b
Unfortunately no, got other priorities to sort you last weekend. I'll try to squeeze this in as soon as I get a chance
j
no worries. I will then try to deploy something internally meanwhile
b
Best option for you long term would be to switch to IR backend as it'll become the default soonish
j
it was also failing to bundle the deps for me with IR 🤔 but maybe I did something else wrong
b
What error are you getting with IR?
j
No error, just that the dependencies were not bundled (I was using a fresh project for testing that)
b
And those shouldn't
Kotlin.js deps are embedded within generated js file. Only npm deps are in package.json