Add support for JS source map source roots to Gradle plugin

This commit is contained in:
Alexey Andreev
2017-06-13 14:16:08 +03:00
parent 62fb149f08
commit cfd3b137d8
4 changed files with 49 additions and 0 deletions
@@ -6,6 +6,7 @@ import org.junit.Test
import java.io.File
import java.util.zip.ZipFile
import kotlin.test.assertEquals
import kotlin.test.assertTrue
class Kotlin2JsGradlePluginIT : BaseGradleIT() {
@Test
@@ -170,4 +171,20 @@ class Kotlin2JsGradlePluginIT : BaseGradleIT() {
assertSuccessful()
}
}
@Test
fun testKotlinJsSourceMap() {
val project = Project("kotlin2JsProjectWithSourceMap", "2.10")
project.build("build") {
assertSuccessful()
val mapFilePath = "build/kotlin2js/main/app.js.map"
assertFileExists(mapFilePath)
val map = fileInWorkingDir(mapFilePath).readText()
val sourceFilePath = "prefixprefix/example/main.kt"
assertTrue("Source map should contain reference to $sourceFilePath") { map.contains("\"$sourceFilePath\"") }
}
}
}
@@ -0,0 +1,24 @@
buildscript {
repositories {
mavenLocal()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: "kotlin2js"
repositories {
mavenLocal()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
}
compileKotlin2Js.kotlinOptions.sourceMap = true
compileKotlin2Js.kotlinOptions.sourceMapPrefix = "prefixprefix/"
compileKotlin2Js.kotlinOptions.outputFile = "${buildDir}/kotlin2js/main/app.js"
compileKotlin2Js.kotlinOptions.suppressWarnings = true
compileKotlin2Js.kotlinOptions.verbose = true
@@ -0,0 +1,5 @@
package example
fun main(args: Array<String>) {
println("Hello")
}
@@ -210,6 +210,9 @@ internal class Kotlin2JsSourceSetProcessor(
sourceSet.output.setClassesDir(outputDir)
kotlinTask.destinationDir = outputDir
kotlinTask.kotlinOptions.sourceMapSourceRoots =
sourceSet.allSource.srcDirs.joinToString(File.pathSeparator) { it.absolutePath }
}
}