Don't expose sourceMapSourceRoots argument to Gradle (JS)
Exposing this property causes IDEA to treat it as a free command line argument, which is undesirable. Support source roots via setting command line arguments inside JS gradle task.
This commit is contained in:
committed by
Alexey Andreev
parent
49b742ab3d
commit
60dd475493
-1
@@ -45,7 +45,6 @@ public class K2JSCompilerArguments extends CommonCompilerArguments {
|
|||||||
@Argument(value = "-source-map-prefix", description = "Prefix for paths in a source map")
|
@Argument(value = "-source-map-prefix", description = "Prefix for paths in a source map")
|
||||||
public String sourceMapPrefix;
|
public String sourceMapPrefix;
|
||||||
|
|
||||||
@GradleOption(DefaultValues.StringNullDefault.class)
|
|
||||||
@Argument(
|
@Argument(
|
||||||
value = "-source-map-source-roots",
|
value = "-source-map-source-roots",
|
||||||
valueDescription = "<path>",
|
valueDescription = "<path>",
|
||||||
|
|||||||
+11
-2
@@ -174,7 +174,16 @@ class Kotlin2JsGradlePluginIT : BaseGradleIT() {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testKotlinJsSourceMap() {
|
fun testKotlinJsSourceMap() {
|
||||||
val project = Project("kotlin2JsProjectWithSourceMap", "2.10")
|
val project = Project("kotlin2JsNoOutputFileProject", "2.10")
|
||||||
|
|
||||||
|
project.setupWorkingDir()
|
||||||
|
|
||||||
|
project.projectDir.getFileByName("build.gradle").modify {
|
||||||
|
it + "\n" +
|
||||||
|
"compileKotlin2Js.kotlinOptions.sourceMap = true\n" +
|
||||||
|
"compileKotlin2Js.kotlinOptions.sourceMapPrefix = \"prefixprefix/\"\n" +
|
||||||
|
"compileKotlin2Js.kotlinOptions.outputFile = \"\${buildDir}/kotlin2js/main/app.js\"\n"
|
||||||
|
}
|
||||||
|
|
||||||
project.build("build") {
|
project.build("build") {
|
||||||
assertSuccessful()
|
assertSuccessful()
|
||||||
@@ -183,7 +192,7 @@ class Kotlin2JsGradlePluginIT : BaseGradleIT() {
|
|||||||
assertFileExists(mapFilePath)
|
assertFileExists(mapFilePath)
|
||||||
val map = fileInWorkingDir(mapFilePath).readText()
|
val map = fileInWorkingDir(mapFilePath).readText()
|
||||||
|
|
||||||
val sourceFilePath = "prefixprefix/example/main.kt"
|
val sourceFilePath = "prefixprefix/example/Dummy.kt"
|
||||||
assertTrue("Source map should contain reference to $sourceFilePath") { map.contains("\"$sourceFilePath\"") }
|
assertTrue("Source map should contain reference to $sourceFilePath") { map.contains("\"$sourceFilePath\"") }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-1
@@ -1,6 +1,8 @@
|
|||||||
package example
|
package example
|
||||||
|
|
||||||
class Dummy {
|
class Dummy {
|
||||||
fun f() {}
|
fun f(): Int {
|
||||||
|
return 23
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
-24
@@ -1,24 +0,0 @@
|
|||||||
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
|
|
||||||
-5
@@ -1,5 +0,0 @@
|
|||||||
package example
|
|
||||||
|
|
||||||
fun main(args: Array<String>) {
|
|
||||||
println("Hello")
|
|
||||||
}
|
|
||||||
-6
@@ -54,12 +54,6 @@ interface KotlinJsOptions : org.jetbrains.kotlin.gradle.dsl.KotlinCommonOptions
|
|||||||
*/
|
*/
|
||||||
var sourceMapPrefix: kotlin.String?
|
var sourceMapPrefix: kotlin.String?
|
||||||
|
|
||||||
/**
|
|
||||||
* Base directories which are used to calculate relative paths to source files in source map
|
|
||||||
* Default value: null
|
|
||||||
*/
|
|
||||||
var sourceMapSourceRoots: kotlin.String?
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate JS files for specific ECMA version
|
* Generate JS files for specific ECMA version
|
||||||
* Possible values: "v5"
|
* Possible values: "v5"
|
||||||
|
|||||||
-7
@@ -64,11 +64,6 @@ internal abstract class KotlinJsOptionsBase : org.jetbrains.kotlin.gradle.dsl.Ko
|
|||||||
get() = sourceMapPrefixField ?: null
|
get() = sourceMapPrefixField ?: null
|
||||||
set(value) { sourceMapPrefixField = value }
|
set(value) { sourceMapPrefixField = value }
|
||||||
|
|
||||||
private var sourceMapSourceRootsField: kotlin.String?? = null
|
|
||||||
override var sourceMapSourceRoots: kotlin.String?
|
|
||||||
get() = sourceMapSourceRootsField ?: null
|
|
||||||
set(value) { sourceMapSourceRootsField = value }
|
|
||||||
|
|
||||||
private var targetField: kotlin.String? = null
|
private var targetField: kotlin.String? = null
|
||||||
override var target: kotlin.String
|
override var target: kotlin.String
|
||||||
get() = targetField ?: "v5"
|
get() = targetField ?: "v5"
|
||||||
@@ -92,7 +87,6 @@ internal abstract class KotlinJsOptionsBase : org.jetbrains.kotlin.gradle.dsl.Ko
|
|||||||
outputFileField?.let { args.outputFile = it }
|
outputFileField?.let { args.outputFile = it }
|
||||||
sourceMapField?.let { args.sourceMap = it }
|
sourceMapField?.let { args.sourceMap = it }
|
||||||
sourceMapPrefixField?.let { args.sourceMapPrefix = it }
|
sourceMapPrefixField?.let { args.sourceMapPrefix = it }
|
||||||
sourceMapSourceRootsField?.let { args.sourceMapSourceRoots = it }
|
|
||||||
targetField?.let { args.target = it }
|
targetField?.let { args.target = it }
|
||||||
typedArraysField?.let { args.typedArrays = it }
|
typedArraysField?.let { args.typedArrays = it }
|
||||||
}
|
}
|
||||||
@@ -111,7 +105,6 @@ internal fun org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments.fil
|
|||||||
outputFile = null
|
outputFile = null
|
||||||
sourceMap = false
|
sourceMap = false
|
||||||
sourceMapPrefix = null
|
sourceMapPrefix = null
|
||||||
sourceMapSourceRoots = null
|
|
||||||
target = "v5"
|
target = "v5"
|
||||||
typedArrays = false
|
typedArrays = false
|
||||||
}
|
}
|
||||||
|
|||||||
-3
@@ -210,9 +210,6 @@ internal class Kotlin2JsSourceSetProcessor(
|
|||||||
|
|
||||||
sourceSet.output.setClassesDir(outputDir)
|
sourceSet.output.setClassesDir(outputDir)
|
||||||
kotlinTask.destinationDir = outputDir
|
kotlinTask.destinationDir = outputDir
|
||||||
|
|
||||||
kotlinTask.kotlinOptions.sourceMapSourceRoots =
|
|
||||||
sourceSet.allSource.srcDirs.joinToString(File.pathSeparator) { it.absolutePath }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+7
-1
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.gradle.tasks
|
|||||||
|
|
||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
import org.gradle.api.Task
|
import org.gradle.api.Task
|
||||||
|
import org.gradle.api.file.SourceDirectorySet
|
||||||
import org.gradle.api.logging.Logger
|
import org.gradle.api.logging.Logger
|
||||||
import org.gradle.api.tasks.Input
|
import org.gradle.api.tasks.Input
|
||||||
import org.gradle.api.tasks.SourceTask
|
import org.gradle.api.tasks.SourceTask
|
||||||
@@ -335,7 +336,6 @@ open class Kotlin2JsCompile() : AbstractKotlinCompile<K2JSCompilerArguments>(),
|
|||||||
val outputFile: String
|
val outputFile: String
|
||||||
get() = kotlinOptions.outputFile ?: defaultOutputFile.canonicalPath
|
get() = kotlinOptions.outputFile ?: defaultOutputFile.canonicalPath
|
||||||
|
|
||||||
|
|
||||||
override fun findKotlinCompilerJar(project: Project): File? =
|
override fun findKotlinCompilerJar(project: Project): File? =
|
||||||
findKotlinJsCompilerJar(project)
|
findKotlinJsCompilerJar(project)
|
||||||
|
|
||||||
@@ -379,6 +379,12 @@ open class Kotlin2JsCompile() : AbstractKotlinCompile<K2JSCompilerArguments>(),
|
|||||||
|
|
||||||
args.friendModules = friendDependency
|
args.friendModules = friendDependency
|
||||||
|
|
||||||
|
args.sourceMapSourceRoots = source.orEmpty()
|
||||||
|
.asSequence()
|
||||||
|
.filterIsInstance<SourceDirectorySet>()
|
||||||
|
.flatMap { it.srcDirs.asSequence() }
|
||||||
|
.joinToString(File.pathSeparator) { it.absolutePath }
|
||||||
|
|
||||||
logger.kotlinDebug("compiling with args ${ArgumentUtils.convertArgumentsToStringList(args)}")
|
logger.kotlinDebug("compiling with args ${ArgumentUtils.convertArgumentsToStringList(args)}")
|
||||||
|
|
||||||
val messageCollector = GradleMessageCollector(logger)
|
val messageCollector = GradleMessageCollector(logger)
|
||||||
|
|||||||
Reference in New Issue
Block a user