• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3 */
4
5apply from: rootProject.file('gradle/node-js.gradle')
6
7kotlin {
8    js {
9        moduleName = project.name
10
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
15        if (it.irTarget != null) {
16            irTarget.nodejs()
17            irTarget.compilations['main']?.dependencies {
18                api "org.jetbrains.kotlinx:atomicfu-js:$atomicfu_version"
19            }
20        }
21    }
22
23    sourceSets {
24        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
33def compileJsLegacy = tasks.hasProperty("compileKotlinJsLegacy")
34        ? compileKotlinJsLegacy
35        : compileKotlinJs
36
37def compileTestJsLegacy = tasks.hasProperty("compileTestKotlinJsLegacy")
38        ? compileTestKotlinJsLegacy
39        : compileTestKotlinJs
40
41compileJsLegacy.configure {
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"
49        outputFile = new File(outputFileProperty.get().parent, baseName + ".js")
50    }
51}
52
53compileTestJsLegacy.configure {
54    kotlinOptions.metaInfo = true
55    kotlinOptions.sourceMap = true
56    kotlinOptions.moduleKind = 'umd'
57}
58
59
60task populateNodeModules(type: Copy, dependsOn: compileTestJsLegacy) {
61    // we must copy output that is transformed by atomicfu
62    from(kotlin.js().compilations.main.output.allOutputs)
63    into node.nodeProjectDir.dir("node_modules")
64
65    def configuration = configurations.hasProperty("jsLegacyTestRuntimeClasspath")
66            ? configurations.jsLegacyTestRuntimeClasspath
67            : configurations.jsTestRuntimeClasspath
68
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
80npmInstall.dependsOn populateNodeModules
81