Vsevolod Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 1 | /* |
Vsevolod Tolstopyatov | 41a2e30 | 2021-02-04 07:16:48 -0800 | [diff] [blame] | 2 | * Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. |
Vsevolod Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 3 | */ |
| 4 | |
| 5 | apply from: rootProject.file('gradle/node-js.gradle') |
| 6 | |
| 7 | kotlin { |
Ilya Goncharov | 6391089 | 2020-05-28 17:58:48 +0300 | [diff] [blame] | 8 | js { |
Victor Turansky | a11e185 | 2021-02-16 12:52:07 +0300 | [diff] [blame] | 9 | moduleName = project.name |
Ilya Goncharov | 6391089 | 2020-05-28 17:58:48 +0300 | [diff] [blame] | 10 | |
Ilya Goncharov | 6391089 | 2020-05-28 17:58:48 +0300 | [diff] [blame] | 11 | // In 1.4.x it has in `both` and `legacy` mode and js() is of type `KotlinJsTarget` |
| 12 | // `irTarget` is non-null in `both` mode |
| 13 | // and contains appropriate `irTarget` with type `KotlinJsIrTarget` |
| 14 | // `irTarget` is null in `legacy` mode |
Victor Turansky | a11e185 | 2021-02-16 12:52:07 +0300 | [diff] [blame] | 15 | if (it.irTarget != null) { |
Ilya Goncharov | 6391089 | 2020-05-28 17:58:48 +0300 | [diff] [blame] | 16 | irTarget.nodejs() |
| 17 | irTarget.compilations['main']?.dependencies { |
| 18 | api "org.jetbrains.kotlinx:atomicfu-js:$atomicfu_version" |
Svyatoslav Kuzmich | fa97af2 | 2020-03-11 18:56:26 +0300 | [diff] [blame] | 19 | } |
| 20 | } |
Vsevolod Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 21 | } |
| 22 | |
| 23 | sourceSets { |
Vsevolod Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 24 | jsTest.dependencies { |
| 25 | api "org.jetbrains.kotlin:kotlin-test-js:$kotlin_version" |
| 26 | } |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | // When source sets are configured |
| 31 | apply from: rootProject.file('gradle/test-mocha-js.gradle') |
| 32 | |
Ilya Goncharov | 6391089 | 2020-05-28 17:58:48 +0300 | [diff] [blame] | 33 | def compileJsLegacy = tasks.hasProperty("compileKotlinJsLegacy") |
| 34 | ? compileKotlinJsLegacy |
| 35 | : compileKotlinJs |
| 36 | |
| 37 | def compileTestJsLegacy = tasks.hasProperty("compileTestKotlinJsLegacy") |
| 38 | ? compileTestKotlinJsLegacy |
| 39 | : compileTestKotlinJs |
| 40 | |
| 41 | compileJsLegacy.configure { |
Vsevolod Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 42 | kotlinOptions.metaInfo = true |
| 43 | kotlinOptions.sourceMap = true |
| 44 | kotlinOptions.moduleKind = 'umd' |
| 45 | |
| 46 | kotlinOptions { |
| 47 | // drop -js suffix from outputFile |
| 48 | def baseName = project.name - "-js" |
Vsevolod Tolstopyatov | c9ab4fd | 2021-07-08 12:12:48 +0300 | [diff] [blame] | 49 | outputFile = new File(outputFileProperty.get().parent, baseName + ".js") |
Vsevolod Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 50 | } |
| 51 | } |
| 52 | |
Ilya Goncharov | 6391089 | 2020-05-28 17:58:48 +0300 | [diff] [blame] | 53 | compileTestJsLegacy.configure { |
Vsevolod Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 54 | kotlinOptions.metaInfo = true |
| 55 | kotlinOptions.sourceMap = true |
| 56 | kotlinOptions.moduleKind = 'umd' |
| 57 | } |
| 58 | |
Svyatoslav Kuzmich | fa97af2 | 2020-03-11 18:56:26 +0300 | [diff] [blame] | 59 | |
Ilya Goncharov | 6391089 | 2020-05-28 17:58:48 +0300 | [diff] [blame] | 60 | task populateNodeModules(type: Copy, dependsOn: compileTestJsLegacy) { |
Roman Elizarov | 504c876 | 2019-04-24 12:04:02 +0300 | [diff] [blame] | 61 | // we must copy output that is transformed by atomicfu |
Ilya Goncharov | 6391089 | 2020-05-28 17:58:48 +0300 | [diff] [blame] | 62 | from(kotlin.js().compilations.main.output.allOutputs) |
Vsevolod Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 63 | into "$node.nodeModulesDir/node_modules" |
| 64 | |
Ilya Goncharov | 6391089 | 2020-05-28 17:58:48 +0300 | [diff] [blame] | 65 | def configuration = configurations.hasProperty("jsLegacyTestRuntimeClasspath") |
| 66 | ? configurations.jsLegacyTestRuntimeClasspath |
Svyatoslav Kuzmich | fa97af2 | 2020-03-11 18:56:26 +0300 | [diff] [blame] | 67 | : configurations.jsTestRuntimeClasspath |
| 68 | |
Vsevolod Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 69 | from(files { |
| 70 | configuration.collect { File file -> |
| 71 | file.name.endsWith(".jar") ? |
| 72 | zipTree(file.absolutePath).matching { |
| 73 | include '*.js' |
| 74 | include '*.js.map' |
| 75 | } : files() |
| 76 | } |
| 77 | }.builtBy(configuration)) |
| 78 | } |
| 79 | |
| 80 | npmInstall.dependsOn populateNodeModules |