Hi everybody! I have a KMP library project with 2 ...
# javascript
c
Hi everybody! I have a KMP library project with 2 KMP modules. One contains the actual code of the library, the other one is a test ui module. The second depends on the first. When I run the
jsBrowserProductionLibraryDistribution
gradle task of the first module, I will get a generated package in the
projectRoot/build/js
folder which contains multiple packages (as you can see in the picture) for both modules. So I have 2 questions: • If I called
jsBrowserProductionLibraryDistribution
only on the first module, why do I get a package also for the second (test ui)? • Is there a way to avoid generating a
<packageName>-test
package for the modules?
c
build/js/packages/<name of module>
is the actual Yarn workspace for that module. Kotlin must always generate one for all modules, no matter if it's published or not. Otherwise, you wouldn't be able to use NPM dependencies or even run tests!
c
Sorry if it's a stupid question, I'm not a web dev but, why I wouldn't be able to use NPM dependencies? My expectation was if I want to create a js library from the first module and publish it to an npm registry it shouldn't have any relation to the tests and the other module. If I don't include the other module in the settings.gradle it won't generate the 2 other folders. just the
my_lib
and
my_lib-test
folders. Why can't I achieve the same result by running only
jsBrowserProductionLibraryDistribution
on the first module?
c
If I don't include the other module in the settings.gradle it won't generate the 2 other folders.
From Yarn's point of view, this is the same as deleting the project entirely.
build/js/packages
isn't some kind of "exported data" that is run specifically for modules you want to export. It's the real Yarn/NPM project that lives underneath the build. That's the working directory in which webpack, your test framework, etc are executed. If you remove it, you can't use anything from the JS ecosystem anymore, since there is no JS anymore. It doesn't have anything to do with publishing libraries.
c
So for publishing the library I should find another way, right?
c
I don't really know what you're trying to do, so it's hard to help. What I can say is that it's normal (and necessary) that all modules appear in
build/js/packages
.
c
Im trying to create an npm package from the js source set of my kmp project, and I want to publish it to an npm registry. Until now I published it like this: • run
jsBrowserProductionLibraryDistribution
• add an .npmrc and a modified package.json file to the
build/js
folder • run npm publish in the
build/js
folder However I noticed that it contains files from other modules that I don't need in the consumer application. So as I see I have 2 options: 1. exclude unnecessary files 2. finding another way to create a more optimal npm package
I just realized that I can publish what I have in the
moduleName/build/dist/productionLibrary
folder.
c
Yes,
dist/productionLibrary
is what you're supposed to publish. At least, it's my understanding, I've not published libraries to NPM so far.