Javascript module name

Hi,
Is there some known rule that is used to determine the ‘name’ of the javascript module that is created when building a kotlin Javascript (standalone or multiplatform) module.

It seems that there is no consistency.
When I build my own kotlin multiplatform modules they all end up with a very consistent name,
{group}-{name}”
However, other modules seem to have names that do not follow this pattern. E.g

“org.jetbrains.kotlin:kotlin-stdlib-js” -> “kotlin”
“org.jetbrains.kotlinx:kotlinx-coroutines-core-js” -> “kotlinx-coroutines-core”
“org.jetbrains.kotlinx:kotlinx-io-js” -> “kotlinx-io”
“org.jetbrains.kotlinx:atomicfu-js” to “kotlinx-atomicfu”
“ktor-client-websockets-js” -> “ktor-ktor-client-websockets”

and really weirdly!!
“org.jetbrains.kotlinx:kotlinx-coroutines-io” -> “kotlinx-io-kotlinx-coroutines-io”

I am integrating kotlin generated JS modules into an angular project, but it would be much easier if the naming was consistent, or at least if there was a way to easily compute the JS module name from the gradle dependency.

Hello,
Could you please provide more information about your case? If you consume your Kotlin/JS module from your Angular application, why do you need module names of other libraries but not your one only?
You can require only your module, and then, when you module will require e.g kotlin it will find it.
Additionally, you can bundle all your js dependencies into one bundle via webpack with library mode (https://webpack.js.org/configuration/output/#outputlibrary)

well, the use case is irrelevant to the questions.

  1. why is the naming inconsistent
  2. how do I predict/compute/discover the names

however, if you are interested in the specifics of why,
I am generating a package.json and .d.ts file for each module so that I get correct type information in the angular build. To do this, I need to know the names of the modules.

org.jetbrains.kotlin.js can create pseudo npm modules for gradle dependencies. So it create package.json with actual names.
You can check build/js/packages_imported folder for dependencies, which you depends on in gradle. And you can create package.json file with valid names for it (or maybe you can even use it instead of generating new). For you module you can check build/js/packages/ folder, where you find your module with package.json for it

many thanks very much for the pointer, I have checked it out.

Unfortunately, I can’t see how to get it to help. the folders and files in the build/js/packages/ folder
already use the strange names…i.e. packages_imported/kotlinx-io-kotlinx-coroutines-io

so I am still lacking the information that says how the gradle dependency name maps to the js module name.

(I am quite puzzled why this is not standard, I would have thought it just makes sense to stick to the gradle {group}-{name} pattern and not allow for some other strange name.

gradle 6.0.1
kotlin 1.3.60

OK so I dived into the kotlin source code to try and figure this out.
It seems that the class ‘org.jetbrains.kotlin.gradle.targets.js.npm.GradleNodeModuleBuilder’ is responsible for creating the “create pseudo npm modules”. It does a bit of zipfile magic to read a package.json file before unpacking the jar. However, often (normally) there is no package.json file in the {module}-js.jar file.
In which case it artificially creates a package.json from just the module name and version

(This should really be reported as a bug seeing as it may not be unique!)

val packageJson = srcPackageJsonFile?.reader()?.use {
            Gson().fromJson(it, PackageJson::class.java)
        } ?: PackageJson(dependency.moduleName, dependency.moduleVersion)

Clearly, the group name is not used here.
and this code

val dir = importedPackageDir(container, packageJson.name, packageJson.version)

is responsible for the directory into which the module is unpacked (fun makeNodeModule)
In this case…the group name is simply not used!

what I am still unsure about is why, for some modules, kotlin uses the group name, and for some it does not!