How to set the package name of a compiled Js module

I am compiling some modules from kotlin to javascript but using the in javascript looks a bit ugly since I have to go into the whole scope of the organization domain to get the necessary class
Is there any solution please? I always have to use

let package= require("packageName").com.company.package.ClassName

I would like to set the package name in order to access directly to the class eg:

let package= require("packageName").ClassName```

Simply, in your Kotlin module, move all your files to the top level src/kotlin folder, instead of being in src/kotlin/com/company/package, and also remove the package com.company.package at the top of each file.

Hello,

While it works well, moving all classes from their packages to the root package leads to too much mess in the library structure to me.

I tried a workaround to do so : create src/jsMain/resources/index.js with the following content :

module.exports = Object.assign({}, ...function _flatten(o) {
    return [].concat(...Object.keys(o)
        .map(k => typeof o[k] === 'object' ?
            _flatten(o[k]) :
            ({[k]: o[k]})))
}(require('./myLibrary')))

but while it works well, it makes the module definition (myLibrary.d.js) outdated, and so autocompletion in tools like VSCode no more work.

I’m wondering whether there is a built-in feature to do that instead ?

Hi,

I have exactly the same problem. My kotlin code is both used from the JVM and the browser, so I need to maintain a package hierarchy for my classes and use a package name that is consistant with my JVM code base (let’s say com.example.myproject). As this is fine for the JVM, it is really ugly to have this prefix in my JavaScript code.

I would expect a JsPackageName annotation or any other mechanism to customize the name of the generated JS package.
Isn’t there an existing solution?