[Gradle, JS] Add typescript optionally

This commit is contained in:
Ilya Goncharov
2022-10-07 13:56:08 +02:00
committed by Space Team
parent 8363b0e9cf
commit 5a7b4294c5
4 changed files with 20 additions and 3 deletions
@@ -187,4 +187,8 @@ constructor(
override fun useEsModules() { override fun useEsModules() {
error("ES modules are not supported in legacy JS compiler. Please, use IR one instead.") error("ES modules are not supported in legacy JS compiler. Please, use IR one instead.")
} }
override fun generateTypeScriptDefinitions() {
project.logger.warn("Legacy compiler does not support generation of TypeScript Definitions")
}
} }
@@ -55,6 +55,8 @@ interface KotlinJsTargetDsl : KotlinTarget {
fun useCommonJs() fun useCommonJs()
fun useEsModules() fun useEsModules()
fun generateTypeScriptDefinitions()
val binaries: KotlinJsBinaryContainer val binaries: KotlinJsBinaryContainer
@Deprecated( @Deprecated(
@@ -384,4 +384,17 @@ constructor(
sourceMap = true sourceMap = true
sourceMapEmbedSources = "never" sourceMapEmbedSources = "never"
} }
override fun generateTypeScriptDefinitions() {
compilations
.all {
binaries
.withType(JsIrBinary::class.java)
.all {
it.linkTask.configure { linkTask ->
linkTask.compilerOptions.freeCompilerArgs.add(GENERATE_D_TS)
}
}
}
}
} }
@@ -61,15 +61,13 @@ internal open class KotlinJsIrLinkConfig(
configureOptions( configureOptions(
compilation, compilation,
ENABLE_DCE, ENABLE_DCE,
GENERATE_D_TS,
MINIMIZED_MEMBER_NAMES MINIMIZED_MEMBER_NAMES
) )
} }
KotlinJsBinaryMode.DEVELOPMENT -> { KotlinJsBinaryMode.DEVELOPMENT -> {
configureOptions( configureOptions(
compilation, compilation
GENERATE_D_TS
) )
} }
else -> throw InvalidUserDataException( else -> throw InvalidUserDataException(