https://kotlinlang.org logo
#feed
Title
b

Big Chungus

10/22/2020, 5:11 PM
npm-publish@v1.0.0 gradle plugin is out! The main highlights of this release: • Kotlin/JS dependency (non-npm) bundling • IR compiler support • Typescript declaration packaging (via IR compiler) Give it a go! 🎉
🎉 3
👍 3
An interesting thing I've observed is that with IR mode you don't get js sourcemaps, but looks like all the kotlin/js dependencies are dce'd and bundled inside the main output file. Whereas with Legacy mode you do get sourcemaps, but kotlin/JS debendencies are not bundled within the main file and are left to be bundled separetely.
s

Sebastian Aigner

10/22/2020, 8:06 PM
Congrats on publishing, Martynas! 🎉 On the topic of source-maps; that’s expected 🙂 The IR compiler doesn’t have support for source maps yet.
👍 1
🏳️‍🌈 1
t

thana

10/23/2020, 6:40 AM
is is possible to just create a "fat-jar-style" npm package with your plugin? I.e. a
.tar
file containing all the kotlin-dependencies as well as the
.js
files created from other modules of our multi-module MPP?
b

Big Chungus

10/23/2020, 7:07 AM
Hmm but that's already handled by browserWebpack task? Or is your use-case different?
t

thana

10/23/2020, 7:08 AM
to be honest i don't know what the platform starting from 1.4 already is able to do for me. i'm afraid of upgrading because doing the packaging manually was a hard task before :-D
b

Big Chungus

10/23/2020, 7:11 AM
Is your project a library or application?
t

thana

10/23/2020, 7:13 AM
kinda both 😉 we have a backend application, cross compile parts of it to js and provide it as a library to our typescript developers... so in effect i guess 'library' is the correct answer to your question
b

Big Chungus

10/23/2020, 7:15 AM
Why not publish it to private repo, then?
Surely makes it easier to hand over than sending tarballs
But if you really need a fat tarball, please create an issue on the repo describing your use-case. Happy to add it into next release (sometime next week)
t

thana

10/23/2020, 7:21 AM
in the beginning wethought that would make development easier, if the fe developers can
npm link
a single file. but actually it's a good idea we should evaluate again
b

Big Chungus

10/23/2020, 7:25 AM
You can get a tarbal by adding the plugin, running assemble and then manually running npm pack on build/publications/npm/js
t

thana

10/23/2020, 7:28 AM
wow that's cool. i will try that as soon as i find time again to work on the upgrade of the project and will give you feedback whether it worked out or not 🙂
b

Big Chungus

10/23/2020, 7:37 AM
Keep in mind that resulting tarball will not be a full fat tarball, because when you link it it will still download npm dependencies. It only bundles kotlin dependencies since most of them are not on npm
But pack gradle task is probably convenient enough to add to the plugin. Will spit something out for that next week.
❤️ 1
t

thana

10/23/2020, 7:43 AM
thank you!
b

Big Chungus

10/23/2020, 7:44 AM
No, thank you! I'm running out of ideas for the plugin and you just gave me one ;)
t

thana

10/23/2020, 7:44 AM
glad to help 😄
b

Big Chungus

10/23/2020, 8:10 AM
npm-publish@v1.0.1 gradle plugin is out!
t

thana

10/26/2020, 1:27 PM
wow thats awesome! thank you. Looks like i should try hard to find time for our upgrading :-D
@Big Chungus i finally got there. upgraded everything to 1.4.10 and now trying to build the tgz. First question arising: is there a way to customize the default publication? or the other way round: when decalring a custom publication how do i manage to depend on all the generated js files? by default it doesn even compile any kotlin code to put into the tgz...
ah now that i asked the question i realize what
jsOne
in the example does - and exactly what i asked for
@Big Chungus is there a way to exlude
.kjsm
files from the tgz? i tried it with :
Copy code
files { assemblyDir -> 
                from("$assemblyDir") {
                    include("**/*.js")
                    exclude("**/*.kjsm")
                }
            }
But this didn't do the trick
b

Big Chungus

11/21/2020, 3:40 PM
Hmm, this shouldve done the trick
Oh wait, you can either include or exclude in gradle CopySpec, I'm affraid
Hold on. I know what's up. AssemblyDir varialble holds the destination of your assemply, not where the files are comming from. It should work as you expect if you just keep exclude or include statements without from statement
I'd recommend just keeping exclude
t

thana

11/21/2020, 7:05 PM
@Big Chungus oh yes that works much better. thanks! Another question just arising: do i alway have to re-decalre the npm dependencies inside the publication? (already have it defined for the js sourceset, but it's not mention in the
package.json
)
b

Big Chungus

11/21/2020, 7:22 PM
It should be picked up automatically from sourceSet!
Can you share your config or reproducing project?
t

thana

11/21/2020, 7:27 PM
now i put
Copy code
dependencies {
                    this["vertx3-eventbus-client"] = "^${extra["vertx_version"]}"
                }
into the
packageJson
block finally it appeard ni the
package.json
sharnig the project is not possible unfortunately as it is an internal custimer project 😞
b

Big Chungus

11/21/2020, 7:28 PM
Can you not just share your build.gradle.kts?
Namely kotlin and npmPublish blocks
t

thana

11/21/2020, 7:28 PM
yes im current censoring it :D
👍 1
message has been deleted
Copy code
kotlin {
    targets {
        jvm {}
        js {
            useCommonJs()
            nodejs {
                testTask {
                    useMocha()
                }
            }
        }
    }

    sourceSets {
        commonMain {
            dependencies {
                implementation(project(":sharedKernel"))
                implementation("com.module:shared-kernel:${extra["shared_kernel_version"]}")
                implementation(project(":uuidGeneration"))
                implementation(project(":eventsourcing"))
                implementation(project(":message-bus"))
                implementation(project(":analyse"))
                implementation(project(":mppCollection"))

                implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:${extra["coroutines_version"]}")
                implementation("io.github.microutils:kotlin-logging-common:${extra["kotlin_logging_version"]}")
            }
        }
        commonTest {
            dependencies {
                implementation("org.junit.jupiter:junit-jupiter:${extra["junit_version"]}")
                implementation("org.jetbrains.kotlin:kotlin-test-common:${extra["kotlin_version"]}")
                implementation("org.jetbrains.kotlin:kotlin-test-annotations-common:${extra["kotlin_version"]}")
                implementation("com.willowtreeapps.assertk:assertk:${extra["assertk_version"]}")
                implementation("io.mockk:mockk-common:${extra["mockk_version"]}")
            }
        }

        js().compilations["main"].defaultSourceSet {
            dependencies {
                implementation("io.github.microutils:kotlin-logging-js:${extra["kotlin_logging_version"]}")
                implementation(npm("vertx3-eventbus-client", "^${extra["vertx_version"]}"))
            }
        }
        js().compilations["test"].defaultSourceSet {
            dependencies {
                implementation("org.jetbrains.kotlin:kotlin-test-js:${extra["kotlin_version"]}")
                implementation("com.willowtreeapps.assertk:assertk-js:${extra["assertk_version"]}")
            }
        }
        jvm().compilations["main"].defaultSourceSet {
            dependencies {
                implementation(project(":security"))
                implementation(project(":db-migration"))
                implementation(project(":event-publisher"))

                implementation("org.apache.commons:commons-csv:${extra["apache_commons_csv"]}")
                implementation("org.springframework.boot:spring-boot-starter-web")
                implementation("org.springframework.boot:spring-boot-starter-security")
                implementation("org.springframework.boot:spring-boot-starter-cache")
                implementation("org.springframework.boot:spring-boot-starter-data-jpa")
                implementation("org.springframework.boot:spring-boot-starter-actuator")
                implementation("org.springframework.boot:spring-boot-starter-mail")
                implementation("org.springframework.boot:spring-boot-starter-webflux")
                implementation("org.projectreactor:reactor-spring:${extra["reactor_spring_version"]}")

                implementation("io.pebbletemplates:pebble:${extra["pebble_version"]}")

                implementation("org.jetbrains.kotlinx:kotlinx-coroutines-slf4j:${extra["coroutines_version"]}")
                implementation("io.github.microutils:kotlin-logging:${extra["kotlin_logging_version"]}")
                implementation("com.google.code.gson:gson:${extra["gson_version"]}")

                implementation("org.apache.commons:commons-text:${extra["apache_commons_text_version"]}")

                implementation("com.fasterxml.jackson.module:jackson-module-kotlin:${extra["jackson_version"]}")

                implementation("org.jooq:jooq:${project.extra["jooq_version"]}")
                implementation("org.postgresql:postgresql:${extra["postgres_database_version"]}")

                implementation("io.vertx:vertx-core:${extra["vertx_version"]}")
                implementation("io.vertx:vertx-web:${extra["vertx_version"]}")
                implementation("io.vertx:vertx-micrometer-metrics:${extra["vertx_version"]}")
                implementation("io.micrometer:micrometer-registry-elastic")

            }
        }
        jvm().compilations["test"].defaultSourceSet {
            dependencies {
                implementation("io.mockk:mockk:${extra["mockk_version"]}")
                implementation("org.jetbrains.kotlin:kotlin-test-junit5:${extra["kotlin_version"]}")
                implementation("org.springframework.boot:spring-boot-starter-test") {
                    exclude(group = "org.junit.vintage")
                }
                implementation("com.willowtreeapps.assertk:assertk-jvm:${extra["assertk_version"]}")
                implementation("org.opentest4j:opentest4j:${extra["opentest4j_version"]}")
                implementation("io.mockk:mockk:${extra["mockk_version"]}")
                implementation("io.vertx:vertx-unit:${extra["vertx_version"]}")
                implementation("au.com.dius:pact-jvm-provider-junit5:${extra["pact_version"]}")
                implementation("au.com.dius:pact-jvm-provider-junit5-spring:${extra["pact_version"]}")
                implementation("org.awaitility:awaitility:${extra["awaitility_version"]}")
                implementation("org.awaitility:awaitility-kotlin:${extra["awaitility_version"]}")

                implementation("org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:${extra["coroutines_version"]}")

                runtimeOnly("org.testcontainers:junit-jupiter:${extra["testcontainers_version"]}")
                runtimeOnly("org.testcontainers:postgresql:${extra["testcontainers_version"]}")
            }
        }
    }
}
npmPublishing {
    access = RESTRICTED
    version = "1.0.0"

    publications {
        val js by getting {
            moduleName = "modulename"
            destinationDir = file("$buildDir${extra["file_separator"]}fbeExport")


            files { assemblyDir ->
                exclude("**/*.kjsm")
                exclude("**/*.meta.js")
                exclude("**/*.map")
            }
            packageJson {

                dependencies {
                    this["vertx3-eventbus-client"] = "^${extra["vertx_version"]}"
                }

                private = true
                license = "UNLICENSED"
                author {
                    name = "company"
                    url = "<http://company.de/>"
                }
                bundledDependencies {
                    -"assertk.*".toRegex()
                    -"opentest4k.*".toRegex()
                }
            }
        }
    }
}
As you can see i do now have a
dependencies
block inside
packageJson
i tried it with a
dependies
block one level up, too, which didn't do the trick either.
b

Big Chungus

11/21/2020, 7:35 PM
Very odd. That npm dependency should've been picked up automatically
Might be due to the way you declare your dependencies
It's unusual
t

thana

11/21/2020, 7:36 PM
really? how does the usual way look like?
that sanbox module has more example setups
for all of them all dependencies are manages automatically
t

thana

11/21/2020, 7:41 PM
ah you mean
val jsMain by getting
vs.
js().compilations["main"].defaultSourceSet {
?
b

Big Chungus

11/21/2020, 7:42 PM
Yes
t

thana

11/21/2020, 7:43 PM
i'll refactor and try again, thanks for the tip 🙂
b

Big Chungus

11/21/2020, 7:44 PM
What's odd is that it didn't work for you with top level dependencies block in npmPublishing config. Can you send me that config so I could investigate what's up Tomorrow?
Or even raise an issue on the repo if you have time
t

thana

11/21/2020, 7:51 PM
it's really only adding
Copy code
dependencies {
                npm("vertx3-eventbus-client", "^${extra["vertx_version"]}")
            }
above the
files
block
b

Big Chungus

11/22/2020, 3:25 PM
Turns out you;ve found a verry silly bug in dependency resolution 🤦‍♂️ Will release a fix for that in 30mins
😀 1
1.0.3 fixes this 🙂
With 1.0.3 you should be able to remove all dependency configs other than one in sourceSet
t

thana

11/23/2020, 8:19 AM
I realized that our frontend cannot use the generated npm package: some of the
bundledDependencies
cannot be resolved, others have wriong names, some are missing... Do you think it would be easier, to simply use the output of
jsBrowserDevelopmentWebpack
(if available)? I currently think this will be the way to go in ouer case: generate bundle, add a matching package.json -> done
b

Big Chungus

11/23/2020, 9:22 AM
Should work fine by just adding 1.0.3
Using bundle is suboptimal, because it might potentially bring unwanted and non-tree-shakeable dependencies thus bloating your final bundle
As for bundledDependencies, it's due to known bugs in both, npm and yarn that prevents installing packages with bundledDependencies. npm-shrinkwrap generated by this plugin fixes that for npm, but i'm affraid yarn is not gonna work with bundledDependencies 😕
Note that you can install with both package managers if you do that from the tarball generated by
pack
task
So you could just distribute the tarball and ask your frontend devs to install it from that
Or just use npm
t

thana

11/23/2020, 9:34 AM
i see, i'll try again with the new version. thank you :)
b

Big Chungus

11/24/2020, 11:58 AM
@thana, curious if you managed to get it working with new version without explicitly specifying npm dependencies in npmPublishing?
t

thana

11/24/2020, 12:13 PM
@Big Chungus yes, the dependencies are now part of the package.json. But unfortunately it doesnt work yet, due to npm wont resolve the bundledDependencies. Im trying to catch one of our frontend devs to have a llok with me on that issue
b

Big Chungus

11/24/2020, 12:17 PM
Are you installing it with
npm install mypackage
? Is
npm-shrinkwrap.json
present in the assembled package? Can you share the error?
t

thana

11/24/2020, 12:33 PM
currently we are simply doing
npm link
during development
b

Big Chungus

11/24/2020, 12:34 PM
Ah, never tested that with bundledDependencies. Any chance you can try with npm install? Even if it's not published but a tarball generated by
pack
gradle task
t

thana

11/24/2020, 12:34 PM
the
npm-shrinkwrap.json
is present. please let me look on it with one of our devs first - i have only rudimentary knowledge on npm. i'll inform you then what the real problem was (probably its just my ignorance 😉 )
👍 1
b

Big Chungus

11/24/2020, 12:35 PM
Let me know if I can help. Very curious to get this sorted myself 😄
t

thana

11/24/2020, 12:36 PM
haha completely understnad this 😄
8 Views