Libraries in “Kotlin -> Javascript” projects.
The purpose of this message is to share some thoughts about current state of supporting libraries for developing Javascript applications using Kotlin.
For now there is only one such library --- kotlin-jslib.jar, which contains subset of standard kotlin library, translated to Javascript.
The first step in order to extend support for different libraries of these kind is to implement the following requirements.
Library is a jar-archive, which contains kotlin sources (in the future it will be replaced with serialized descriptors in binary format) and javascript files (result of translation).
META-INF/MANIFEST.MF contains some specific attributes in order to determine the kind of library and javascript module name.
CLI & buildtools
Console compiler has -libraryFiles option, which value is a comma-separated list of paths to jar-files or folders. It is assumed that each folder is really an expanded version of some valid jar-archive library, in particular, it should contain manifest file META-INF/MANIFEST.MF.
Libraries could also be specified as dependencies for maven project and added to IntelliJ IDEA project.
IMPORTANT NOTE: console compiler, ant kotlin2js task and kotlin maven plugin doesn’t copy javascript files from libraries, their work is only to translate given kotlin files to Javascript (though this decision should be investigated).
Console compiler and build tools will support an option for generating meta information.
IntelliJ IDEA
It is possible to configure the following additional option for Kotlin Compiler in IntelliJ IDEA ( Settings/Build, Execution, Deployment/Compiler/Kotlin Compiler/Kotlin to Javascript section):
output directory for runtime library files (default value is “lib”, relative to the directory which contains output file).
When IntelliJ IDEA compiles project, each library processed in turn, and all javascript files are copied to output directory for runtime files.
For each library we have semantically two step process:
1) recursively copy js files from library directory or archive except META-INF directory with saving directory structure;
2), recursively copy js files from META-INF/resources subdirectory of library directory or archive with saving directory structure. This could be useful for JVM-based containers (see http://www.webjars.org/documentation#servlet3).
The next step is to implement binary serialization for descriptors. Also there is a possibility to include descriptor metadata into corresponding javascript file, so the whole library could be distributed as one javascript file.
Questions and comments are welcomed.