Support Kotlin/JS DCE in new MPP

Issue #KT-27196 Fixed
This commit is contained in:
Sergey Igushkin
2018-09-27 00:39:04 +03:00
parent 499146db0e
commit 2441df820b
9 changed files with 152 additions and 11 deletions
@@ -846,4 +846,20 @@ class NewMultiplatformIT : BaseGradleIT() {
}
}
}
@Test
fun testJsDceInMpp() = with(Project("new-mpp-js-dce", gradleVersion)) {
build("runRhino") {
assertSuccessful()
assertTasksExecuted(":mainProject:runDceNodeJsKotlin")
val pathPrefix = "mainProject/build/kotlin-js-min/nodeJs/main"
assertFileExists("$pathPrefix/exampleapp.js.map")
assertFileExists("$pathPrefix/examplelib.js.map")
assertFileContains("$pathPrefix/exampleapp.js.map", "\"../../../../src/nodeJsMain/kotlin/exampleapp/main.kt\"")
assertFileExists("$pathPrefix/kotlin.js")
assertTrue(fileInWorkingDir("$pathPrefix/kotlin.js").length() < 500 * 1000, "Looks like kotlin.js file was not minified by DCE")
}
}
}
@@ -0,0 +1,33 @@
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: 'kotlin-multiplatform'
repositories {
mavenLocal()
mavenCentral()
}
kotlin.targets.fromPreset(kotlin.presets.js, 'nodeJs')
dependencies {
nodeJsMainApi "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
}
compileKotlinNodeJs.kotlinOptions.outputFile = "${buildDir}/examplelib.js"
compileKotlinNodeJs.kotlinOptions.sourceMap = true
nodeJsJar {
from buildDir
include "**/*.js"
include "**/*.js.map"
}
nodeJsJar.dependsOn(compileKotlinNodeJs)
@@ -0,0 +1,44 @@
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: "kotlin-multiplatform"
apply plugin: "kotlin-dce-js"
repositories {
mavenLocal()
mavenCentral()
}
kotlin.targets.fromPreset(kotlin.presets.js, 'nodeJs')
dependencies {
nodeJsImplementation project(":libraryProject")
nodeJsImplementation "org.jetbrains.kotlin:kotlin-stdlib-js"
nodeJsImplementation "org.mozilla:rhino:1.7.7.1"
}
compileKotlinNodeJs.kotlinOptions.sourceMap = true
compileKotlinNodeJs.kotlinOptions.outputFile = "${buildDir}/exampleapp.js"
compileKotlinNodeJs.kotlinOptions.suppressWarnings = true
compileKotlinNodeJs.kotlinOptions.verbose = true
runDceNodeJsKotlin.keep("exampleapp.exampleapp.status")
task runRhino(type: JavaExec) {
classpath = kotlin.targets.nodeJs.compilations.main.runtimeDependencyFiles
workingDir = "${buildDir}"
main = 'org.mozilla.javascript.tools.shell.Main'
args = ["-opt", "-1",
"-f", "kotlin-js-min/nodeJs/main/kotlin.js",
"-f", "kotlin-js-min/nodeJs/main/examplelib.js",
"-f", "kotlin-js-min/nodeJs/main/exampleapp.js",
"-f", "../check.js"]
}
runRhino.dependsOn(runDceNodeJsKotlin)
@@ -0,0 +1,6 @@
(function() {
var status = exampleapp.exampleapp.status;
if (status !== "foo") {
throw new Error("Unexpected status: " + status);
}
})();
@@ -0,0 +1,9 @@
package exampleapp
import examplelib.*
var status = "failure"
fun main(args: Array<String>) {
status = foo()
}
@@ -0,0 +1 @@
include 'mainProject', 'libraryProject'