[Gradle, JS] Fix destination dir for link tasks
- Add test on empty output with empty inputs
This commit is contained in:
+40
@@ -29,6 +29,44 @@ class Kotlin2JsIrGradlePluginIT : AbstractKotlin2JsGradlePluginIT(true) {
|
||||
assert(dts.readText().contains("function bar(): string"))
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCleanOutputWithEmptySources() {
|
||||
with(Project("kotlin-js-nodejs-project", GradleVersionRequired.AtLeast("5.2"))) {
|
||||
setupWorkingDir()
|
||||
gradleBuildScript().modify(::transformBuildScriptWithPluginsDsl)
|
||||
gradleSettingsScript().modify(::transformBuildScriptWithPluginsDsl)
|
||||
|
||||
build(
|
||||
"build",
|
||||
options = defaultBuildOptions().copy(jsCompilerType = JsCompilerType.ir)
|
||||
) {
|
||||
assertSuccessful()
|
||||
|
||||
assertTasksExecuted(":compileProductionKotlinJs")
|
||||
|
||||
assertFileExists("build/js/packages/kotlin-js-nodejs/kotlin/kotlin-js-nodejs.js")
|
||||
}
|
||||
|
||||
File("${projectDir.canonicalPath}/src").deleteRecursively()
|
||||
|
||||
gradleBuildScript().appendText(
|
||||
"""${"\n"}
|
||||
tasks {
|
||||
compileProductionKotlinJs {
|
||||
type = org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrType.DEVELOPMENT
|
||||
}
|
||||
}
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
build("build") {
|
||||
assertSuccessful()
|
||||
|
||||
assertNoSuchFile("build/js/packages/kotlin-js-nodejs/kotlin/")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Kotlin2JsGradlePluginIT : AbstractKotlin2JsGradlePluginIT(false) {
|
||||
@@ -547,4 +585,6 @@ abstract class AbstractKotlin2JsGradlePluginIT(private val irBackend: Boolean) :
|
||||
assertFileExists("app/build/distributions/index.html")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
plugins {
|
||||
kotlin("js").version("<pluginMarkerVersion>")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(kotlin("stdlib-js"))
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
jcenter()
|
||||
}
|
||||
|
||||
kotlin {
|
||||
target {
|
||||
useCommonJs()
|
||||
produceExecutable()
|
||||
nodejs {
|
||||
}
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
pluginManagement {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
gradlePluginPortal()
|
||||
}
|
||||
}
|
||||
|
||||
rootProject.name = "kotlin-js-nodejs"
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package com.example
|
||||
|
||||
fun best(): Int {
|
||||
return 42
|
||||
}
|
||||
|
||||
fun simpleBest(): Int {
|
||||
return 73
|
||||
}
|
||||
+8
-3
@@ -41,6 +41,7 @@ import org.jetbrains.kotlin.gradle.scripting.internal.ScriptingGradleSubplugin
|
||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrCompilation
|
||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrLink
|
||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrType
|
||||
import org.jetbrains.kotlin.gradle.targets.js.npm.npmProject
|
||||
import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget
|
||||
import org.jetbrains.kotlin.gradle.tasks.*
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
@@ -106,11 +107,14 @@ internal abstract class KotlinSourceSetProcessor<T : AbstractKotlinCompile<*>>(
|
||||
kotlinCompilation.output.addClassesDir { project.files(task.map { it.destinationDir }) }
|
||||
}
|
||||
|
||||
protected fun registerKotlinCompileTask(name: String = kotlinCompilation.compileKotlinTaskName): TaskProvider<out T> {
|
||||
protected fun registerKotlinCompileTask(
|
||||
name: String = kotlinCompilation.compileKotlinTaskName,
|
||||
compileDestinationDir: File = defaultKotlinDestinationDir
|
||||
): TaskProvider<out T> {
|
||||
logger.kotlinDebug("Creating kotlin compile task $name")
|
||||
|
||||
KotlinCompileTaskData.register(name, kotlinCompilation).apply {
|
||||
destinationDir.set(project.provider { defaultKotlinDestinationDir })
|
||||
destinationDir.set(project.provider { compileDestinationDir })
|
||||
}
|
||||
|
||||
return doRegisterTask(project, name) {
|
||||
@@ -374,7 +378,8 @@ internal class KotlinJsIrSourceSetProcessor(
|
||||
compilation.developmentLinkTaskName
|
||||
).onEach { taskName ->
|
||||
registerKotlinCompileTask(
|
||||
taskName
|
||||
taskName,
|
||||
compilation.npmProject.dist
|
||||
)
|
||||
}.forEach { taskName ->
|
||||
project.tasks.named(taskName).configure {
|
||||
|
||||
+5
-1
@@ -52,8 +52,11 @@ open class NpmProject(val compilation: KotlinJsCompilation) {
|
||||
val packageJsonTask: KotlinPackageJsonTask
|
||||
get() = project.tasks.getByName(packageJsonTaskName) as KotlinPackageJsonTask
|
||||
|
||||
val dist: File
|
||||
get() = dir.resolve(DIST_FOLDER)
|
||||
|
||||
val main: String
|
||||
get() = "kotlin/$name.js"
|
||||
get() = "$DIST_FOLDER/$name.js"
|
||||
|
||||
val externalsDirRoot: File
|
||||
get() = project.buildDir.resolve("externals").resolve(name)
|
||||
@@ -115,5 +118,6 @@ open class NpmProject(val compilation: KotlinJsCompilation) {
|
||||
companion object {
|
||||
const val PACKAGE_JSON = "package.json"
|
||||
const val NODE_MODULES = "node_modules"
|
||||
const val DIST_FOLDER = "kotlin"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user