/* * Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ apply from: rootProject.file('gradle/node-js.gradle') kotlin { js { moduleName = project.name // In 1.4.x it has in `both` and `legacy` mode and js() is of type `KotlinJsTarget` // `irTarget` is non-null in `both` mode // and contains appropriate `irTarget` with type `KotlinJsIrTarget` // `irTarget` is null in `legacy` mode if (it.irTarget != null) { irTarget.nodejs() irTarget.compilations['main']?.dependencies { api "org.jetbrains.kotlinx:atomicfu-js:$atomicfu_version" } } } sourceSets { jsTest.dependencies { api "org.jetbrains.kotlin:kotlin-test-js:$kotlin_version" } } } // When source sets are configured apply from: rootProject.file('gradle/test-mocha-js.gradle') def compileJsLegacy = tasks.hasProperty("compileKotlinJsLegacy") ? compileKotlinJsLegacy : compileKotlinJs def compileTestJsLegacy = tasks.hasProperty("compileTestKotlinJsLegacy") ? compileTestKotlinJsLegacy : compileTestKotlinJs compileJsLegacy.configure { kotlinOptions.metaInfo = true kotlinOptions.sourceMap = true kotlinOptions.moduleKind = 'umd' kotlinOptions { // drop -js suffix from outputFile def baseName = project.name - "-js" outputFile = new File(outputFileProperty.get().parent, baseName + ".js") } } compileTestJsLegacy.configure { kotlinOptions.metaInfo = true kotlinOptions.sourceMap = true kotlinOptions.moduleKind = 'umd' } task populateNodeModules(type: Copy, dependsOn: compileTestJsLegacy) { // we must copy output that is transformed by atomicfu from(kotlin.js().compilations.main.output.allOutputs) into node.nodeProjectDir.dir("node_modules") def configuration = configurations.hasProperty("jsLegacyTestRuntimeClasspath") ? configurations.jsLegacyTestRuntimeClasspath : configurations.jsTestRuntimeClasspath from(files { configuration.collect { File file -> file.name.endsWith(".jar") ? zipTree(file.absolutePath).matching { include '*.js' include '*.js.map' } : files() } }.builtBy(configuration)) } npmInstall.dependsOn populateNodeModules