JS: generate paths in source maps relative to .map file location

See KT-19818
This commit is contained in:
Alexey Andreev
2017-08-29 14:28:15 +03:00
parent 93a3026c6d
commit 9008791a54
31 changed files with 236 additions and 63 deletions
@@ -195,7 +195,7 @@ class Kotlin2JsGradlePluginIT : BaseGradleIT() {
assertFileExists(mapFilePath)
val map = fileInWorkingDir(mapFilePath).readText()
val sourceFilePath = "prefixprefix/example/Dummy.kt"
val sourceFilePath = "prefixprefix/src/main/kotlin/example/Dummy.kt"
assertTrue("Source map should contain reference to $sourceFilePath") { map.contains("\"$sourceFilePath\"") }
}
}
@@ -211,8 +211,8 @@ class Kotlin2JsGradlePluginIT : BaseGradleIT() {
assertFileExists(mapFilePath)
val map = fileInWorkingDir(mapFilePath).readText()
assertTrue("Source map should contain reference to main.kt") { map.contains("\"main.kt\"") }
assertTrue("Source map should contain reference to foo.kt") { map.contains("\"foo.kt\"") }
assertTrue("Source map should contain reference to main.kt") { map.contains("\"./src/main/kotlin/main.kt\"") }
assertTrue("Source map should contain reference to foo.kt") { map.contains("\"./src/main/kotlin/foo.kt\"") }
assertTrue("Source map should contain source of main.kt") { map.contains("\"fun main(args: Array<String>) {\\n") }
assertTrue("Source map should contain source of foo.kt") { map.contains("\"inline fun foo(): String {\\n") }
}
@@ -24,6 +24,7 @@ allprojects {
compileKotlin2Js {
kotlinOptions.freeCompilerArgs = [ "-Xskip-metadata-version-check" ]
kotlinOptions.sourceMap = true
kotlinOptions.sourceMapPrefix = "./"
kotlinOptions.sourceMapEmbedSources = "always"
}
}
@@ -461,11 +461,9 @@ open class Kotlin2JsCompile() : AbstractKotlinCompile<K2JSCompilerArguments>(),
args.friendModules = friendDependency
args.sourceMapBaseDirs = source.orEmpty()
.asSequence()
.filterIsInstance<SourceDirectorySet>()
.flatMap { it.srcDirs.asSequence() }
.joinToString(File.pathSeparator) { it.absolutePath }
if (args.sourceMapBaseDirs == null && !args.sourceMapPrefix.isNullOrEmpty()) {
args.sourceMapBaseDirs = project.projectDir.absolutePath
}
logger.kotlinDebug("compiling with args ${ArgumentUtils.convertArgumentsToStringList(args)}")