Thread
#feed
    Big Chungus

    Big Chungus

    1 year ago
    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! 🎉
    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

    1 year ago
    Congrats on publishing, Martynas! 🎉 On the topic of source-maps; that’s expected 🙂 The IR compiler doesn’t have support for source maps yet.
    t

    thana

    1 year ago
    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?
    Big Chungus

    Big Chungus

    1 year ago
    Hmm but that's already handled by browserWebpack task? Or is your use-case different?
    t

    thana

    1 year ago
    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 😄
    Big Chungus

    Big Chungus

    1 year ago
    Is your project a library or application?
    t

    thana

    1 year ago
    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
    Big Chungus

    Big Chungus

    1 year ago
    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

    1 year ago
    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
    Big Chungus

    Big Chungus

    1 year ago
    You can get a tarbal by adding the plugin, running assemble and then manually running npm pack on build/publications/npm/js
    t

    thana

    1 year ago
    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 🙂
    Big Chungus

    Big Chungus

    1 year ago
    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.
    t

    thana

    1 year ago
    thank you!
    Big Chungus

    Big Chungus

    1 year ago
    No, thank you! I'm running out of ideas for the plugin and you just gave me one 😉
    t

    thana

    1 year ago
    glad to help 😄
    npm-publish@v1.0.1 gradle plugin is out!
    t

    thana

    1 year ago
    wow thats awesome! thank you. Looks like i should try hard to find time for our upgrading 😄
    @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 :
    files { assemblyDir -> 
                    from("$assemblyDir") {
                        include("**/*.js")
                        exclude("**/*.kjsm")
                    }
                }
    But this didn't do the trick
    Big Chungus

    Big Chungus

    1 year ago
    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

    1 year ago
    @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
    )
    Big Chungus

    Big Chungus

    1 year ago
    It should be picked up automatically from sourceSet!
    Can you share your config or reproducing project?
    t

    thana

    1 year ago
    now i put
    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 😞
    Big Chungus

    Big Chungus

    1 year ago
    Can you not just share your build.gradle.kts?
    Namely kotlin and npmPublish blocks
    t

    thana

    1 year ago
    yes im current censoring it 😄
    message has been deleted
    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.
    Big Chungus

    Big Chungus

    1 year ago
    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

    1 year ago
    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

    1 year ago
    ah you mean
    val jsMain by getting
    vs.
    js().compilations["main"].defaultSourceSet {
    ?
    Big Chungus

    Big Chungus

    1 year ago
    Yes
    t

    thana

    1 year ago
    i'll refactor and try again, thanks for the tip 🙂
    Big Chungus

    Big Chungus

    1 year ago
    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

    1 year ago
    it's really only adding
    dependencies {
                    npm("vertx3-eventbus-client", "^${extra["vertx_version"]}")
                }
    above the
    files
    block
    Big Chungus

    Big Chungus

    1 year ago
    Turns out you;ve found a verry silly bug in dependency resolution 🤦‍♂️ Will release a fix for that in 30mins
    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

    1 year ago
    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
    Big Chungus

    Big Chungus

    1 year ago
    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

    1 year ago
    i see, i'll try again with the new version. thank you 😃
    Big Chungus

    Big Chungus

    1 year ago
    @thana, curious if you managed to get it working with new version without explicitly specifying npm dependencies in npmPublishing?
    t

    thana

    1 year ago
    @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
    Big Chungus

    Big Chungus

    1 year ago
    Are you installing it with
    npm install mypackage
    ? Is
    npm-shrinkwrap.json
    present in the assembled package? Can you share the error?
    t

    thana

    1 year ago
    currently we are simply doing
    npm link
    during development
    Big Chungus

    Big Chungus

    1 year ago
    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

    1 year ago
    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 😉 )
    Big Chungus

    Big Chungus

    1 year ago
    Let me know if I can help. Very curious to get this sorted myself 😄
    t

    thana

    1 year ago
    haha completely understnad this 😄