Support generation of relative path in JS source maps in JPS builder
See KT-20820
This commit is contained in:
@@ -366,6 +366,18 @@ open class KotlinJpsBuildTest : AbstractKotlinJpsBuildTestCase() {
|
|||||||
assertTrue("Source map for stdlib should be copied to $librarySourceMapFile", librarySourceMapFile.exists())
|
assertTrue("Source map for stdlib should be copied to $librarySourceMapFile", librarySourceMapFile.exists())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun testKotlinJavaScriptProjectWithSourceMapRelativePaths() {
|
||||||
|
initProject(JS_STDLIB)
|
||||||
|
buildAllModules().assertSuccessful()
|
||||||
|
|
||||||
|
val sourceMapContent = File(getOutputDir(PROJECT_NAME), "$PROJECT_NAME.js.map").readText()
|
||||||
|
val expectedPath = "../../../src/pkg/test1.kt"
|
||||||
|
assertTrue("Source map file should contain relative path ($expectedPath)", sourceMapContent.contains("\"$expectedPath\""))
|
||||||
|
|
||||||
|
val librarySourceMapFile = File(getOutputDir(PROJECT_NAME), "lib/kotlin.js.map")
|
||||||
|
assertTrue("Source map for stdlib should be copied to $librarySourceMapFile", librarySourceMapFile.exists())
|
||||||
|
}
|
||||||
|
|
||||||
fun testKotlinJavaScriptProjectWithTwoModules() {
|
fun testKotlinJavaScriptProjectWithTwoModules() {
|
||||||
initProject(JS_STDLIB)
|
initProject(JS_STDLIB)
|
||||||
buildAllModules().assertSuccessful()
|
buildAllModules().assertSuccessful()
|
||||||
|
|||||||
@@ -648,10 +648,21 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
|
|||||||
val compilerSettings = JpsKotlinCompilerSettings.getCompilerSettings(representativeModule)
|
val compilerSettings = JpsKotlinCompilerSettings.getCompilerSettings(representativeModule)
|
||||||
val k2JsArguments = JpsKotlinCompilerSettings.getK2JsCompilerArguments(representativeModule)
|
val k2JsArguments = JpsKotlinCompilerSettings.getK2JsCompilerArguments(representativeModule)
|
||||||
|
|
||||||
val sourceRoots = representativeModule.contentRootsList.urls
|
// Compiler starts to produce path relative to base dirs in source maps if at least one statement is true:
|
||||||
.map { URI.create(it) }
|
// 1) base dirs are specified;
|
||||||
.filter { it.scheme == "file" }
|
// 2) prefix is specified (i.e. non-empty)
|
||||||
.map { File(it.path) }
|
// Otherwise compiler produces paths relative to source maps location.
|
||||||
|
// We don't have UI to configure base dirs, but we have UI to configure prefix.
|
||||||
|
// If prefix is not specified (empty) in UI, we want to produce paths relative to source maps location
|
||||||
|
val sourceRoots = if (k2JsArguments.sourceMapPrefix.isNullOrBlank()) {
|
||||||
|
emptyList()
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
representativeModule.contentRootsList.urls
|
||||||
|
.map { URI.create(it) }
|
||||||
|
.filter { it.scheme == "file" }
|
||||||
|
.map { File(it.path) }
|
||||||
|
}
|
||||||
|
|
||||||
val friendPaths = KotlinBuilderModuleScriptGenerator.getProductionModulesWhichInternalsAreVisible(representativeTarget).mapNotNull {
|
val friendPaths = KotlinBuilderModuleScriptGenerator.getProductionModulesWhichInternalsAreVisible(representativeTarget).mapNotNull {
|
||||||
val file = getOutputMetaFile(it, false)
|
val file = getOutputMetaFile(it, false)
|
||||||
|
|||||||
Vendored
+17
@@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="CompilerConfiguration">
|
||||||
|
<option name="DEFAULT_COMPILER" value="Javac" />
|
||||||
|
</component>
|
||||||
|
<component name="Kotlin2JsCompilerArguments">
|
||||||
|
<option name="sourceMap" value="true" />
|
||||||
|
</component>
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/kotlinProject.iml" filepath="$PROJECT_DIR$/kotlinProject.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" assert-keyword="true" jdk-15="true" project-jdk-name="IDEA_JDK" project-jdk-type="JavaSDK">
|
||||||
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
Vendored
+7
@@ -0,0 +1,7 @@
|
|||||||
|
package pkg
|
||||||
|
|
||||||
|
var log = ""
|
||||||
|
|
||||||
|
fun foo(x: String) {
|
||||||
|
log += "$x;"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user