hi, I'm currently porting a lot of js to Kotlin an...
# javascript
b
hi, I'm currently porting a lot of js to Kotlin and still need to do releases with a combined typescript codebase; what is the recommended way to ship a compiled bundle with an existing kotlinjs codebase? I've tried simply shipping it in resources like this:
Copy code
tasks.register<Exec>("installOldJs") {
    inputs.files(layout.projectDirectory.file("./oldsrc/package.json"))
    outputs.dir(layout.projectDirectory.dir("./oldsrc/node_modules"))
    workingDir = layout.projectDirectory.dir("oldsrc/").asFile
    commandLine = listOf("yarn", "install")
}
tasks.register<Exec>("compileOldJs") {
    mustRunAfter("installOldJs")
    inputs.dir(layout.projectDirectory.dir("./oldsrc/src/"))
    outputs.dir(layout.projectDirectory.dir("./oldsrc/dist/"))
    workingDir = layout.projectDirectory.dir("oldsrc/").asFile
    commandLine = listOf("yarn", "run", "build")
}
// inside kotlin block
        val jsMain by getting {
            resources.srcDirs(tasks.named("compileOldJs"))
            dependencies {
                implementation(project.dependencies.enforcedPlatform(libs.kotlin.wrappers))
                implementation(libs.kotlin.wrappers.js)
                implementation(libs.kotlin.plain.objects)
                implementation(libs.kotlinx.html)
                implementation(libs.kotlinx.coroutines.js)
                implementation(libs.jsonschemavalidator.js)
                api(libs.jquery)
            }
        }
but it seems that jsProductionExecutableCompileSync is tripping over the generated sourcemap:
Copy code
Task :jsProductionExecutableCompileSync
Cannot rewrite paths in JavaScript source maps: Unsupported format. Contents should starts with `{"version":3,"file":"...","sources":[...],"sourcesContent":...`. Unknown key "mappings" at line 1 column 44 path $.mappings in `{"version":3,
1
a
@Ilya Goncharov [JB] ^^
b
maybe looks like an issue where the source map is not correctly resolved by the main bundle file name?
i
Hi, we indeed have source map rewriter, we need it because in our Kotlin source maps we need to change relative paths because we change location of file. I think we can consider such case as a bug, because
js.map
file in resources should be okay. But for now, I think you can use one of following ways: 1. Use your NPM package as a file dependency of Kotlin project. You can just use
implementation(npm(file(…))
2. Use output of your
compileOldJs
task as input to tasks
jsProductionExecutableCompileSync
and
jsDevelopmentExecutableCompileSync
, they have type
IncrementalSyncTask
, and you can touch
task.from.from(tasks.named("compileOldJs"))
b
thank you ilya