Skip to content

Commit ae8f2e8

Browse files
ilgonmicrecheej
authored andcommitted
Adopt Kotlin/JS for 1.4-M2 (Kotlin#2060)
* Prepare for 1.4-M2 Kotlin/JS * Compatibility with 1.3.70 * Fix check for irTarget
1 parent 3583147 commit ae8f2e8

File tree

4 files changed

+55
-28
lines changed

4 files changed

+55
-28
lines changed

gradle/compile-js-multiplatform.gradle

+30-15
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,22 @@
55
apply from: rootProject.file('gradle/node-js.gradle')
66

77
kotlin {
8-
targets {
9-
fromPreset(presets.js, 'js') {
10-
// Enable built-in test runner only for IR target.
11-
// These runners don't support changing js module name change.
12-
if (js.hasProperty("irTarget") && irTarget != null) {
13-
irTarget.nodejs()
14-
irTarget.compilations['main']?.dependencies {
15-
api "org.jetbrains.kotlinx:atomicfu-js:$atomicfu_version"
16-
}
8+
js {
9+
// In 1.3.7x js() has not member `moduleName`
10+
// In 1.4.x it has and allow to safety set compiler output file name and does not break test integration
11+
if (it.hasProperty("moduleName")) {
12+
moduleName = project.name
13+
}
14+
15+
// In 1.3.7x js() has not member `irTarget`
16+
// In 1.4.x it has in `both` and `legacy` mode and js() is of type `KotlinJsTarget`
17+
// `irTarget` is non-null in `both` mode
18+
// and contains appropriate `irTarget` with type `KotlinJsIrTarget`
19+
// `irTarget` is null in `legacy` mode
20+
if (it.hasProperty("irTarget") && it.irTarget != null) {
21+
irTarget.nodejs()
22+
irTarget.compilations['main']?.dependencies {
23+
api "org.jetbrains.kotlinx:atomicfu-js:$atomicfu_version"
1724
}
1825
}
1926
}
@@ -32,7 +39,15 @@ kotlin {
3239
// When source sets are configured
3340
apply from: rootProject.file('gradle/test-mocha-js.gradle')
3441

35-
compileKotlinJs {
42+
def compileJsLegacy = tasks.hasProperty("compileKotlinJsLegacy")
43+
? compileKotlinJsLegacy
44+
: compileKotlinJs
45+
46+
def compileTestJsLegacy = tasks.hasProperty("compileTestKotlinJsLegacy")
47+
? compileTestKotlinJsLegacy
48+
: compileTestKotlinJs
49+
50+
compileJsLegacy.configure {
3651
kotlinOptions.metaInfo = true
3752
kotlinOptions.sourceMap = true
3853
kotlinOptions.moduleKind = 'umd'
@@ -44,20 +59,20 @@ compileKotlinJs {
4459
}
4560
}
4661

47-
compileTestKotlinJs {
62+
compileTestJsLegacy.configure {
4863
kotlinOptions.metaInfo = true
4964
kotlinOptions.sourceMap = true
5065
kotlinOptions.moduleKind = 'umd'
5166
}
5267

5368

54-
task populateNodeModules(type: Copy, dependsOn: compileTestKotlinJs) {
69+
task populateNodeModules(type: Copy, dependsOn: compileTestJsLegacy) {
5570
// we must copy output that is transformed by atomicfu
56-
from(kotlin.targets.js.compilations.main.output.allOutputs)
71+
from(kotlin.js().compilations.main.output.allOutputs)
5772
into "$node.nodeModulesDir/node_modules"
5873

59-
def configuration = configurations.hasProperty("legacyjsTestRuntimeClasspath")
60-
? configurations.legacyjsTestRuntimeClasspath
74+
def configuration = configurations.hasProperty("jsLegacyTestRuntimeClasspath")
75+
? configurations.jsLegacyTestRuntimeClasspath
6176
: configurations.jsTestRuntimeClasspath
6277

6378
from(files {

gradle/publish-npm-js.gradle

+5-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ def npmDeployDir = file("$buildDir/npm")
2020
def authToken = prop("kotlin.npmjs.auth.token", "")
2121
def dryRun = prop("dryRun", "false")
2222

23+
def jsLegacy = kotlin.targets.hasProperty("jsLegacy")
24+
? kotlin.targets.jsLegacy
25+
: kotlin.targets.js
26+
2327
// Note: publish transformed files using dependency on sourceSets.main.output
2428
task preparePublishNpm(type: Copy) {
2529
from(npmTemplateDir) {
@@ -30,7 +34,7 @@ task preparePublishNpm(type: Copy) {
3034
}
3135
}
3236
// we must publish output that is transformed by atomicfu
33-
from(kotlin.targets.js.compilations.main.output.allOutputs)
37+
from(jsLegacy.compilations.main.output.allOutputs)
3438
into npmDeployDir
3539
}
3640

gradle/test-mocha-js.gradle

+19-11
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,24 @@ task installDependenciesMochaNode(type: NpmTask, dependsOn: [npmInstall]) {
1212
if (project.hasProperty("teamcity")) args += ["mocha-teamcity-reporter@$mocha_teamcity_reporter_version"]
1313
}
1414

15+
def compileJsLegacy = tasks.hasProperty("compileKotlinJsLegacy")
16+
? compileKotlinJsLegacy
17+
: compileKotlinJs
18+
19+
def compileTestJsLegacy = tasks.hasProperty("compileTestKotlinJsLegacy")
20+
? compileTestKotlinJsLegacy
21+
: compileTestKotlinJs
22+
1523
// todo: use atomicfu-transformed test files here (not critical)
16-
task testMochaNode(type: NodeTask, dependsOn: [compileTestKotlinJs, installDependenciesMochaNode]) {
24+
task testMochaNode(type: NodeTask, dependsOn: [compileTestJsLegacy, installDependenciesMochaNode]) {
1725
script = file("$node.nodeModulesDir/node_modules/mocha/bin/mocha")
18-
args = [compileTestKotlinJs.outputFile, '--require', 'source-map-support/register']
26+
args = [compileTestJsLegacy.outputFile, '--require', 'source-map-support/register']
1927
if (project.hasProperty("teamcity")) args += ['--reporter', 'mocha-teamcity-reporter']
2028
}
2129

22-
def legacyjsTestTask = project.tasks.findByName('legacyjsTest') ? legacyjsTest : jsTest
30+
def jsLegacyTestTask = project.tasks.findByName('jsLegacyTest') ? jsLegacyTest : jsTest
2331

24-
legacyjsTestTask.dependsOn testMochaNode
32+
jsLegacyTestTask.dependsOn testMochaNode
2533

2634
// -- Testing with Mocha under headless Chrome
2735

@@ -38,7 +46,7 @@ task installDependenciesMochaChrome(type: NpmTask, dependsOn: [npmInstall]) {
3846

3947
def mochaChromeTestPage = file("$buildDir/test-page.html")
4048

41-
task prepareMochaChrome(dependsOn: [compileTestKotlinJs, installDependenciesMochaChrome]) {
49+
task prepareMochaChrome(dependsOn: [compileTestJsLegacy, installDependenciesMochaChrome]) {
4250
outputs.file(mochaChromeTestPage)
4351
}
4452

@@ -56,8 +64,8 @@ prepareMochaChrome.doLast {
5664
<script>mocha.setup('bdd');</script>
5765
<script src="$node.nodeModulesDir/node_modules/kotlin/kotlin.js"></script>
5866
<script src="$node.nodeModulesDir/node_modules/kotlin-test/kotlin-test.js"></script>
59-
<script src="$compileKotlinJs.outputFile"></script>
60-
<script src="$compileTestKotlinJs.outputFile"></script>
67+
<script src="$compileJsLegacy.outputFile"></script>
68+
<script src="$compileTestJsLegacy.outputFile"></script>
6169
<script>mocha.run();</script>
6270
</body>
6371
</html>
@@ -66,7 +74,7 @@ prepareMochaChrome.doLast {
6674

6775
task testMochaChrome(type: NodeTask, dependsOn: prepareMochaChrome) {
6876
script = file("$node.nodeModulesDir/node_modules/mocha-headless-chrome/bin/start")
69-
args = [compileTestKotlinJs.outputFile, '--file', mochaChromeTestPage]
77+
args = [compileTestJsLegacy.outputFile, '--file', mochaChromeTestPage]
7078
if (project.hasProperty("teamcity")) args += ['--reporter', 'mocha-teamcity-reporter']
7179
}
7280

@@ -85,11 +93,11 @@ task installDependenciesMochaJsdom(type: NpmTask, dependsOn: [npmInstall]) {
8593
if (project.hasProperty("teamcity")) args += ["mocha-teamcity-reporter@$mocha_teamcity_reporter_version"]
8694
}
8795

88-
task testMochaJsdom(type: NodeTask, dependsOn: [compileTestKotlinJs, installDependenciesMochaJsdom]) {
96+
task testMochaJsdom(type: NodeTask, dependsOn: [compileTestJsLegacy, installDependenciesMochaJsdom]) {
8997
script = file("$node.nodeModulesDir/node_modules/mocha/bin/mocha")
90-
args = [compileTestKotlinJs.outputFile, '--require', 'source-map-support/register', '--require', 'jsdom-global/register']
98+
args = [compileTestJsLegacy.outputFile, '--require', 'source-map-support/register', '--require', 'jsdom-global/register']
9199
if (project.hasProperty("teamcity")) args += ['--reporter', 'mocha-teamcity-reporter']
92100
}
93101

94-
legacyjsTestTask.dependsOn testMochaJsdom
102+
jsLegacyTestTask.dependsOn testMochaJsdom
95103

js/example-frontend-js/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ apply from: rootProject.file('gradle/node-js.gradle')
88
// Workaround resolving new Gradle metadata with kotlin2js
99
// TODO: Remove once KT-37188 is fixed
1010
try {
11-
def jsCompilerType = Class.forName("org.jetbrains.kotlin.gradle.targets.js.JsCompilerType")
11+
def jsCompilerType = Class.forName("org.jetbrains.kotlin.gradle.targets.js.KotlinJsCompilerAttribute")
1212
def jsCompilerAttr = Attribute.of("org.jetbrains.kotlin.js.compiler", jsCompilerType)
1313
project.dependencies.attributesSchema.attribute(jsCompilerAttr)
1414
configurations {

0 commit comments

Comments
 (0)