blob: c6fc757c7dc3ad776c9a2a717b3c7e71bc4e2ff3 [file] [log] [blame]
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +03001/*
Vsevolod Tolstopyatov41a2e302021-02-04 07:16:48 -08002 * Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +03003 */
4
5apply from: rootProject.file('gradle/node-js.gradle')
6
7kotlin {
Ilya Goncharov63910892020-05-28 17:58:48 +03008 js {
Victor Turanskya11e1852021-02-16 12:52:07 +03009 moduleName = project.name
Ilya Goncharov63910892020-05-28 17:58:48 +030010
Ilya Goncharov63910892020-05-28 17:58:48 +030011 // 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 Turanskya11e1852021-02-16 12:52:07 +030015 if (it.irTarget != null) {
Ilya Goncharov63910892020-05-28 17:58:48 +030016 irTarget.nodejs()
17 irTarget.compilations['main']?.dependencies {
18 api "org.jetbrains.kotlinx:atomicfu-js:$atomicfu_version"
Svyatoslav Kuzmichfa97af22020-03-11 18:56:26 +030019 }
20 }
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +030021 }
22
23 sourceSets {
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +030024 jsTest.dependencies {
25 api "org.jetbrains.kotlin:kotlin-test-js:$kotlin_version"
26 }
27 }
28}
29
30// When source sets are configured
31apply from: rootProject.file('gradle/test-mocha-js.gradle')
32
Ilya Goncharov63910892020-05-28 17:58:48 +030033def compileJsLegacy = tasks.hasProperty("compileKotlinJsLegacy")
34 ? compileKotlinJsLegacy
35 : compileKotlinJs
36
37def compileTestJsLegacy = tasks.hasProperty("compileTestKotlinJsLegacy")
38 ? compileTestKotlinJsLegacy
39 : compileTestKotlinJs
40
41compileJsLegacy.configure {
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +030042 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 Tolstopyatovc9ab4fd2021-07-08 12:12:48 +030049 outputFile = new File(outputFileProperty.get().parent, baseName + ".js")
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +030050 }
51}
52
Ilya Goncharov63910892020-05-28 17:58:48 +030053compileTestJsLegacy.configure {
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +030054 kotlinOptions.metaInfo = true
55 kotlinOptions.sourceMap = true
56 kotlinOptions.moduleKind = 'umd'
57}
58
Svyatoslav Kuzmichfa97af22020-03-11 18:56:26 +030059
Ilya Goncharov63910892020-05-28 17:58:48 +030060task populateNodeModules(type: Copy, dependsOn: compileTestJsLegacy) {
Roman Elizarov504c8762019-04-24 12:04:02 +030061 // we must copy output that is transformed by atomicfu
Ilya Goncharov63910892020-05-28 17:58:48 +030062 from(kotlin.js().compilations.main.output.allOutputs)
Steve Elliottca095be2022-07-25 14:26:10 +000063 into node.nodeProjectDir.dir("node_modules")
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +030064
Ilya Goncharov63910892020-05-28 17:58:48 +030065 def configuration = configurations.hasProperty("jsLegacyTestRuntimeClasspath")
66 ? configurations.jsLegacyTestRuntimeClasspath
Svyatoslav Kuzmichfa97af22020-03-11 18:56:26 +030067 : configurations.jsTestRuntimeClasspath
68
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +030069 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
80npmInstall.dependsOn populateNodeModules