diff --git a/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/KotlinJpsBuildTest.kt b/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/KotlinJpsBuildTest.kt index 7f1bfb74d83..a6a20a64457 100644 --- a/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/KotlinJpsBuildTest.kt +++ b/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/KotlinJpsBuildTest.kt @@ -366,6 +366,18 @@ open class KotlinJpsBuildTest : AbstractKotlinJpsBuildTestCase() { 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() { initProject(JS_STDLIB) buildAllModules().assertSuccessful() diff --git a/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt b/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt index 3983f00687a..e8a34aa3a40 100644 --- a/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt +++ b/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt @@ -648,10 +648,21 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) { val compilerSettings = JpsKotlinCompilerSettings.getCompilerSettings(representativeModule) val k2JsArguments = JpsKotlinCompilerSettings.getK2JsCompilerArguments(representativeModule) - val sourceRoots = representativeModule.contentRootsList.urls - .map { URI.create(it) } - .filter { it.scheme == "file" } - .map { File(it.path) } + // Compiler starts to produce path relative to base dirs in source maps if at least one statement is true: + // 1) base dirs are specified; + // 2) prefix is specified (i.e. non-empty) + // 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 file = getOutputMetaFile(it, false) diff --git a/jps-plugin/testData/general/KotlinJavaScriptProjectWithSourceMapRelativePaths/kotlinProject.ipr b/jps-plugin/testData/general/KotlinJavaScriptProjectWithSourceMapRelativePaths/kotlinProject.ipr new file mode 100644 index 00000000000..8ad5a239b86 --- /dev/null +++ b/jps-plugin/testData/general/KotlinJavaScriptProjectWithSourceMapRelativePaths/kotlinProject.ipr @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/jps-plugin/testData/general/KotlinJavaScriptProjectWithSourceMapRelativePaths/src/pkg/test1.kt b/jps-plugin/testData/general/KotlinJavaScriptProjectWithSourceMapRelativePaths/src/pkg/test1.kt new file mode 100644 index 00000000000..112bd39189a --- /dev/null +++ b/jps-plugin/testData/general/KotlinJavaScriptProjectWithSourceMapRelativePaths/src/pkg/test1.kt @@ -0,0 +1,7 @@ +package pkg + +var log = "" + +fun foo(x: String) { + log += "$x;" +} \ No newline at end of file