Skip to content

Commit 8d07d36

Browse files
turanskyqwwdfsad
authored andcommitted
Use new Kotlin/JS plugin (Kotlin#1983)
* Use new Kotlin/JS plugin * Support legacy DCE mode for 1.4-M2
1 parent d224640 commit 8d07d36

File tree

4 files changed

+15
-32
lines changed

4 files changed

+15
-32
lines changed

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ configure(subprojects.findAll { it.name != coreModule && it.name != rootModule }
252252
}
253253

254254
// Redefine source sets because we are not using 'kotlin/main/fqn' folder convention
255-
configure(subprojects.findAll { !sourceless.contains(it.name) && it.name != "benchmarks" && it.name != coreModule }) {
255+
configure(subprojects.findAll { !sourceless.contains(it.name) && it.name != "benchmarks" && it.name != 'example-frontend-js' && it.name != coreModule }) {
256256
sourceSets {
257257
main.kotlin.srcDirs = ['src']
258258
test.kotlin.srcDirs = ['test']

gradle/compile-js.gradle

+10-3
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,29 @@
44

55
// Platform-specific configuration to compile JS modules
66

7-
apply plugin: 'kotlin2js'
7+
apply plugin: 'org.jetbrains.kotlin.js'
8+
9+
kotlin.sourceSets {
10+
main.kotlin.srcDirs = ['src']
11+
test.kotlin.srcDirs = ['test']
12+
main.resources.srcDirs = ['resources']
13+
test.resources.srcDirs = ['test-resources']
14+
}
815

916
dependencies {
1017
compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
1118
testCompile "org.jetbrains.kotlin:kotlin-test-js:$kotlin_version"
1219
}
1320

14-
tasks.withType(compileKotlin2Js.getClass()) {
21+
tasks.withType(compileKotlinJs.getClass()) {
1522
kotlinOptions {
1623
moduleKind = "umd"
1724
sourceMap = true
1825
metaInfo = true
1926
}
2027
}
2128

22-
compileKotlin2Js {
29+
compileKotlinJs {
2330
kotlinOptions {
2431
// drop -js suffix from outputFile
2532
def baseName = project.name - "-js"

js/example-frontend-js/build.gradle

+3-28
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,19 @@
55
apply plugin: 'kotlin-dce-js'
66
apply from: rootProject.file('gradle/node-js.gradle')
77

8-
// Workaround resolving new Gradle metadata with kotlin2js
9-
// TODO: Remove once KT-37188 is fixed
10-
try {
11-
def jsCompilerType = Class.forName("org.jetbrains.kotlin.gradle.targets.js.KotlinJsCompilerAttribute")
12-
def jsCompilerAttr = Attribute.of("org.jetbrains.kotlin.js.compiler", jsCompilerType)
13-
project.dependencies.attributesSchema.attribute(jsCompilerAttr)
14-
configurations {
15-
matching {
16-
it.name.endsWith("Classpath")
17-
}.forEach {
18-
it.attributes.attribute(jsCompilerAttr, jsCompilerType.legacy)
19-
}
20-
}
21-
} catch (java.lang.ClassNotFoundException e) {
22-
// org.jetbrains.kotlin.gradle.targets.js.JsCompilerType is missing in 1.3.x
23-
// But 1.3.x doesn't generate Gradle metadata, so this workaround is not needed
24-
}
25-
268
dependencies {
279
compile "org.jetbrains.kotlinx:kotlinx-html-js:$html_version"
2810
}
2911

30-
compileKotlin2Js {
12+
compileKotlinJs {
3113
kotlinOptions {
3214
main = "call"
3315
}
3416
}
3517

36-
task bundle(type: NpmTask, dependsOn: [npmInstall, runDceKotlinJs]) {
18+
task bundle(type: NpmTask, dependsOn: [npmInstall, build]) {
3719
inputs.files(fileTree("$buildDir/kotlin-js-min/main"))
20+
inputs.files(fileTree("$buildDir/kotlin-js-min/legacy/main"))
3821
inputs.files(fileTree(file("src/main/web")))
3922
inputs.file("npm/webpack.config.js")
4023
outputs.dir("$buildDir/dist")
@@ -44,11 +27,3 @@ task bundle(type: NpmTask, dependsOn: [npmInstall, runDceKotlinJs]) {
4427
task start(type: NpmTask, dependsOn: bundle) {
4528
args = ["run", "start"]
4629
}
47-
48-
// we have not tests but kotlin-dce-js still tries to work with them and crashed.
49-
// todo: Remove when KT-22028 is fixed
50-
afterEvaluate {
51-
if (tasks.findByName('unpackDependenciesTestKotlinJs')) {
52-
tasks.unpackDependenciesTestKotlinJs.enabled = false
53-
}
54-
}

js/example-frontend-js/npm/webpack.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ module.exports = {
3838
resolve: {
3939
modules: [
4040
path.resolve(__dirname, "kotlin-js-min/main"),
41+
path.resolve(__dirname, "kotlin-js-min/legacy/main"),
4142
path.resolve(__dirname, "../src/main/web/")
4243
]
4344
},

0 commit comments

Comments
 (0)