• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright 2016-2020 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        // 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"
24            }
25        }
26    }
27
28    sourceSets {
29        jsTest.dependencies {
30            api "org.jetbrains.kotlin:kotlin-test-js:$kotlin_version"
31        }
32    }
33}
34
35// When source sets are configured
36apply from: rootProject.file('gradle/test-mocha-js.gradle')
37
38def compileJsLegacy = tasks.hasProperty("compileKotlinJsLegacy")
39        ? compileKotlinJsLegacy
40        : compileKotlinJs
41
42def compileTestJsLegacy = tasks.hasProperty("compileTestKotlinJsLegacy")
43        ? compileTestKotlinJsLegacy
44        : compileTestKotlinJs
45
46compileJsLegacy.configure {
47    kotlinOptions.metaInfo = true
48    kotlinOptions.sourceMap = true
49    kotlinOptions.moduleKind = 'umd'
50
51    kotlinOptions {
52        // drop -js suffix from outputFile
53        def baseName = project.name - "-js"
54        outputFile = new File(outputFile.parent, baseName + ".js")
55    }
56}
57
58compileTestJsLegacy.configure {
59    kotlinOptions.metaInfo = true
60    kotlinOptions.sourceMap = true
61    kotlinOptions.moduleKind = 'umd'
62}
63
64
65task populateNodeModules(type: Copy, dependsOn: compileTestJsLegacy) {
66    // we must copy output that is transformed by atomicfu
67    from(kotlin.js().compilations.main.output.allOutputs)
68    into "$node.nodeModulesDir/node_modules"
69
70    def configuration = configurations.hasProperty("jsLegacyTestRuntimeClasspath")
71            ? configurations.jsLegacyTestRuntimeClasspath
72            : configurations.jsTestRuntimeClasspath
73
74    from(files {
75        configuration.collect { File file ->
76            file.name.endsWith(".jar") ?
77                    zipTree(file.absolutePath).matching {
78                        include '*.js'
79                        include '*.js.map'
80                    } : files()
81        }
82    }.builtBy(configuration))
83}
84
85npmInstall.dependsOn populateNodeModules
86