From 1618143efde19be40462e5fb52d74780eef13cb0 Mon Sep 17 00:00:00 2001 From: Ilya Goncharov Date: Wed, 4 Dec 2024 12:03:33 +0000 Subject: [PATCH] [Wasm] Output module name for web targets with Provider API ^KT-71362 fixed Co-authored-by: Adam Semenenko --- .../kotlin/gradle/Kotlin2JsGradlePluginIT.kt | 23 ++++++++ .../kotlin/gradle/KotlinWasmGradlePluginIT.kt | 23 ++++++++ .../api/all/kotlin-gradle-plugin.api | 7 ++- .../gradle/targets/js/KotlinJsCompilation.kt | 56 +++++++------------ .../targets/js/dsl/KotlinJsTargetDsl.kt | 8 +++ .../kotlin/gradle/targets/js/ir/JsBinaries.kt | 6 +- .../gradle/targets/js/ir/KotlinJsIrTarget.kt | 55 +++++++++++------- .../targets/js/ir/KotlinJsIrTargetPreset.kt | 2 + .../targets/js/ir/KotlinWasmTargetPreset.kt | 2 + .../js/ir/NodeJsEnvironmentConfigurator.kt | 2 +- .../gradle/targets/js/npm/NpmProject.kt | 4 +- .../resolver/KotlinCompilationNpmResolver.kt | 10 ---- .../js/npm/resolver/KotlinRootNpmResolver.kt | 2 +- .../targets/js/testing/KotlinWasmNode.kt | 13 ++--- .../configuration/Kotlin2JsCompileConfig.kt | 2 +- .../configuration/KotlinJsIrLinkConfig.kt | 2 +- 16 files changed, 131 insertions(+), 86 deletions(-) diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/Kotlin2JsGradlePluginIT.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/Kotlin2JsGradlePluginIT.kt index db8f4818c0a94..b26cce8540c61 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/Kotlin2JsGradlePluginIT.kt +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/Kotlin2JsGradlePluginIT.kt @@ -1717,4 +1717,27 @@ class Kotlin2JsIrGradlePluginIT : KGPBaseTest() { } } } + + @DisplayName("Changed output module name") + @GradleTest + fun testChangedOutputModuleName(gradleVersion: GradleVersion) { + project("kotlin-js-browser-project", gradleVersion) { + val moduleName = "hello" + subProject("app").buildGradleKts.modify { + it.replace( + "target {", + """ + target { + outputModuleName.set("$moduleName") + """.trimIndent() + ) + } + + build("assemble") { + assertFileExists( + subProject("app").projectPath.resolve("build/compileSync/js/main/productionExecutable/kotlin/$moduleName.mjs") + ) + } + } + } } diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/KotlinWasmGradlePluginIT.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/KotlinWasmGradlePluginIT.kt index 54c626bdb707e..410e7b34d412b 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/KotlinWasmGradlePluginIT.kt +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/KotlinWasmGradlePluginIT.kt @@ -371,4 +371,27 @@ class KotlinWasmGradlePluginIT : KGPBaseTest() { } } } + + @DisplayName("Changed output module name") + @GradleTest + fun testChangedOutputModuleName(gradleVersion: GradleVersion) { + project("wasm-browser-simple-project", gradleVersion) { + val moduleName = "hello" + buildGradleKts.modify { + it.replace( + "wasmJs {", + """ + wasmJs { + outputModuleName.set("$moduleName") + """.trimIndent() + ) + } + + build("assemble") { + assertFileExists( + projectPath.resolve("build/compileSync/wasmJs/main/productionExecutable/kotlin/$moduleName.mjs") + ) + } + } + } } diff --git a/libraries/tools/kotlin-gradle-plugin/api/all/kotlin-gradle-plugin.api b/libraries/tools/kotlin-gradle-plugin/api/all/kotlin-gradle-plugin.api index f39fae5e6b1e5..ece6fa4789b8e 100644 --- a/libraries/tools/kotlin-gradle-plugin/api/all/kotlin-gradle-plugin.api +++ b/libraries/tools/kotlin-gradle-plugin/api/all/kotlin-gradle-plugin.api @@ -1851,9 +1851,11 @@ public class org/jetbrains/kotlin/gradle/plugin/mpp/KotlinJsCompilation : org/je public fun getCompileTaskProvider ()Lorg/gradle/api/tasks/TaskProvider; public final fun getCompilerOptions ()Lorg/jetbrains/kotlin/gradle/plugin/HasCompilerOptions; public final fun getNpmAggregatedConfigurationName ()Ljava/lang/String; - public final fun getOutputModuleName ()Lorg/gradle/api/provider/Property; + public final fun getOutputModuleName ()Lorg/gradle/api/provider/Provider; public fun getProcessResourcesTaskName ()Ljava/lang/String; public final fun getPublicPackageJsonConfigurationName ()Ljava/lang/String; + public synthetic fun getTarget ()Lorg/jetbrains/kotlin/gradle/plugin/KotlinTarget; + public fun getTarget ()Lorg/jetbrains/kotlin/gradle/targets/js/ir/KotlinJsIrTarget; public final fun packageJson (Lgroovy/lang/Closure;)V public final fun packageJson (Lorg/gradle/api/Action;)V } @@ -3447,6 +3449,7 @@ public abstract interface class org/jetbrains/kotlin/gradle/targets/js/dsl/Kotli public abstract fun getBinaries ()Lorg/jetbrains/kotlin/gradle/targets/js/ir/KotlinJsBinaryContainer; public abstract fun getCompilations ()Lorg/gradle/api/NamedDomainObjectContainer; public abstract fun getModuleName ()Ljava/lang/String; + public abstract fun getOutputModuleName ()Lorg/gradle/api/provider/Property; public abstract fun getTestRuns ()Lorg/gradle/api/NamedDomainObjectContainer; public abstract fun passAsArgumentToMainFunction (Ljava/lang/String;)V public abstract fun produceExecutable ()V @@ -5001,7 +5004,7 @@ public final class org/jetbrains/kotlin/gradle/targets/js/npm/resolver/KotlinCom public final fun getProjectResolver ()Lorg/jetbrains/kotlin/gradle/targets/js/npm/resolver/KotlinProjectNpmResolver; public final fun getPublicPackageJsonTaskHolder ()Lorg/gradle/api/tasks/TaskProvider; public final fun getRootResolver ()Lorg/jetbrains/kotlin/gradle/targets/js/npm/resolver/KotlinRootNpmResolver; - public final fun getTarget ()Lorg/jetbrains/kotlin/gradle/plugin/KotlinTarget; + public final fun getTarget ()Lorg/jetbrains/kotlin/gradle/targets/js/ir/KotlinJsIrTarget; public final fun setRootResolver (Lorg/jetbrains/kotlin/gradle/targets/js/npm/resolver/KotlinRootNpmResolver;)V public fun toString ()Ljava/lang/String; } diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/KotlinJsCompilation.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/KotlinJsCompilation.kt index 6b4b169da12e8..1f36cc148d5c8 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/KotlinJsCompilation.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/KotlinJsCompilation.kt @@ -11,7 +11,6 @@ package org.jetbrains.kotlin.gradle.plugin.mpp import groovy.lang.Closure import org.gradle.api.Action import org.gradle.api.attributes.AttributeContainer -import org.gradle.api.provider.Property import org.gradle.api.provider.Provider import org.gradle.api.tasks.TaskProvider import org.jetbrains.kotlin.cli.common.arguments.K2JsArgumentConstants @@ -21,14 +20,13 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinJsOptions import org.jetbrains.kotlin.gradle.plugin.DeprecatedHasCompilerOptions import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType +import org.jetbrains.kotlin.gradle.plugin.KotlinTarget import org.jetbrains.kotlin.gradle.plugin.mpp.compilationImpl.KotlinCompilationImpl import org.jetbrains.kotlin.gradle.targets.js.ir.JsBinary import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsBinaryContainer import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget import org.jetbrains.kotlin.gradle.targets.js.npm.PackageJson import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile -import org.jetbrains.kotlin.gradle.utils.propertyWithConvention -import org.jetbrains.kotlin.util.capitalizeDecapitalize.toLowerCaseAsciiOnly import javax.inject.Inject open class KotlinJsCompilation @Inject internal constructor( @@ -36,6 +34,9 @@ open class KotlinJsCompilation @Inject internal constructor( ) : DeprecatedAbstractKotlinCompilationToRunnableFiles(compilation), HasBinaries { + override val target: KotlinJsIrTarget + get() = super.target as KotlinJsIrTarget + @Deprecated( "To configure compilation compiler options use 'compileTaskProvider':\ncompilation.compileTaskProvider.configure{\n" + " compilerOptions {}\n}" @@ -51,39 +52,10 @@ open class KotlinJsCompilation @Inject internal constructor( compilation.target.project.objects.domainObjectSet(JsBinary::class.java) ) - val outputModuleName: Property = compilation.project.objects.propertyWithConvention(buildNpmProjectName()) - - private fun buildNpmProjectName(): String { - val project = target.project - - val compilationName = if (compilation.name != KotlinCompilation.MAIN_COMPILATION_NAME) { - compilation.name - } else null - - val rootProjectName = project.rootProject.name - - val localName = if (project != project.rootProject) { - (rootProjectName + project.path).replace(":", "-") - } else rootProjectName - - val targetName = if (target.name.isNotEmpty() && target.name.toLowerCaseAsciiOnly() != "js") { - target.name - .replace(DECAMELIZE_REGEX) { - it.groupValues - .drop(1) - .joinToString(prefix = "-", separator = "-") - } - .toLowerCaseAsciiOnly() - } else null - - return sequenceOf( - localName, - targetName, - compilationName - ) - .filterNotNull() - .joinToString("-") - } + val outputModuleName: Provider = target.outputModuleName + .map { targetModuleName -> + buildNpmProjectName(targetModuleName, compilationName) + } @Deprecated("Use compilationName instead", ReplaceWith("compilationName")) val compilationPurpose: String get() = compilationName @@ -128,7 +100,17 @@ open class KotlinJsCompilation @Inject internal constructor( } private companion object { - private val DECAMELIZE_REGEX = "([A-Z])".toRegex() + private fun buildNpmProjectName(targetPart: String, compilationName: String): String { + val filteredCompilationName = if (compilationName != KotlinCompilation.MAIN_COMPILATION_NAME) { + compilationName + } else null + + return listOfNotNull( + targetPart, + filteredCompilationName + ) + .joinToString("-") + } } } diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/dsl/KotlinJsTargetDsl.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/dsl/KotlinJsTargetDsl.kt index 0bebdc8a78e66..9739e78dadaa2 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/dsl/KotlinJsTargetDsl.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/dsl/KotlinJsTargetDsl.kt @@ -8,6 +8,7 @@ package org.jetbrains.kotlin.gradle.targets.js.dsl import org.gradle.api.Action import org.gradle.api.GradleException import org.gradle.api.NamedDomainObjectContainer +import org.gradle.api.provider.Property import org.jetbrains.kotlin.gradle.InternalKotlinGradlePluginApi import org.jetbrains.kotlin.gradle.dsl.HasConfigurableKotlinCompilerOptions import org.jetbrains.kotlin.gradle.dsl.KOTLIN_JS_DCE_TOOL_DEPRECATION_MESSAGE @@ -56,8 +57,15 @@ interface KotlinJsTargetDsl : HasBinaries, HasConfigurableKotlinCompilerOptions { + @Deprecated("Use outputModuleName with Provider API instead") var moduleName: String? + /** + * Represents the name of the output module for a Kotlin/JS and Kotlin/Wasm target. + * This property allows customization of output filenames + */ + val outputModuleName: Property + fun browser() = browser { } fun browser(body: KotlinJsBrowserDsl.() -> Unit) fun browser(fn: Action) { diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/ir/JsBinaries.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/ir/JsBinaries.kt index e7ff883727e20..e9d173158c830 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/ir/JsBinaries.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/ir/JsBinaries.kt @@ -147,7 +147,7 @@ sealed class JsIrBinary( ) val target: KotlinJsIrTarget - get() = compilation.target as KotlinJsIrTarget + get() = compilation.target val project: Project get() = target.project @@ -159,7 +159,7 @@ sealed class JsIrBinary( it.libraries.from(project.filesProvider { compilation.runtimeDependencyFiles }) } configAction.configureTask { task -> - val targetCompilerOptions = (compilation.target as KotlinJsIrTarget).compilerOptions + val targetCompilerOptions = compilation.target.compilerOptions KotlinJsCompilerOptionsHelper.syncOptionsAsConvention( targetCompilerOptions, task.compilerOptions @@ -211,7 +211,7 @@ internal fun TaskProvider.configureOptimizeTask(binary: WasmBinary ) } - val target = binary.compilation.target as KotlinJsIrTarget + val target = binary.compilation.target val compilation = binary.compilation if (compilation.isMain() && binary.mode == KotlinJsBinaryMode.PRODUCTION) { diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/ir/KotlinJsIrTarget.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/ir/KotlinJsIrTarget.kt index cbe4c29cecd59..4fe868518841d 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/ir/KotlinJsIrTarget.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/ir/KotlinJsIrTarget.kt @@ -7,15 +7,12 @@ package org.jetbrains.kotlin.gradle.targets.js.ir import org.gradle.api.NamedDomainObjectContainer import org.gradle.api.Project +import org.gradle.api.provider.Property import org.gradle.api.tasks.TaskProvider import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl import org.jetbrains.kotlin.gradle.dsl.* -import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation +import org.jetbrains.kotlin.gradle.plugin.* import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation.Companion.MAIN_COMPILATION_NAME -import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType -import org.jetbrains.kotlin.gradle.plugin.KotlinTargetComponent -import org.jetbrains.kotlin.gradle.plugin.KotlinTargetWithTests -import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider import org.jetbrains.kotlin.gradle.plugin.mpp.* import org.jetbrains.kotlin.gradle.plugin.mpp.resources.publication.setUpResourcesVariant import org.jetbrains.kotlin.gradle.targets.js.JsAggregatingExecutionSource @@ -29,7 +26,7 @@ import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsPlugin import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin import org.jetbrains.kotlin.gradle.targets.js.npm.NpmResolverPlugin import org.jetbrains.kotlin.gradle.targets.js.typescript.TypeScriptValidationTask -import org.jetbrains.kotlin.gradle.tasks.* +import org.jetbrains.kotlin.gradle.tasks.registerTask import org.jetbrains.kotlin.gradle.utils.* import org.jetbrains.kotlin.util.capitalizeDecapitalize.capitalizeAsciiOnly import org.jetbrains.kotlin.util.capitalizeDecapitalize.toLowerCaseAsciiOnly @@ -66,20 +63,11 @@ constructor( override var wasmTargetType: KotlinWasmTargetType? = null internal set - override var moduleName: String? = null + @Deprecated("Use outputModuleName with Provider API instead") + override var moduleName: String? + get() = outputModuleName.get() set(value) { - field = value - compilations.all { compilation -> - val compilationName = if (compilation.name != MAIN_COMPILATION_NAME) { - compilation.name - } else null - - val name = sequenceOf(moduleName, compilationName) - .filterNotNull() - .joinToString("-") - - compilation.outputModuleName.set(name) - } + outputModuleName.set(value) } override val kotlinComponents: Set by lazy { @@ -351,6 +339,35 @@ constructor( .apply { configureJsDefaultOptions() } + + internal companion object { + private val DECAMELIZE_REGEX = "([A-Z])".toRegex() + + internal fun buildNpmProjectName(project: Project, targetName: String): String { + val rootProjectName = project.rootProject.name + + val localName = if (project != project.rootProject) { + (rootProjectName + project.path).replace(":", "-") + } else rootProjectName + + val targetPartName = if (targetName.isNotEmpty() && targetName.toLowerCaseAsciiOnly() != "js") { + targetName + .replace(DECAMELIZE_REGEX) { + it.groupValues + .drop(1) + .joinToString(prefix = "-", separator = "-") + } + .toLowerCaseAsciiOnly() + } else null + + return sequenceOf( + localName, + targetPartName + ) + .filterNotNull() + .joinToString("-") + } + } } fun KotlinJsIrTarget.wasmDecamelizedDefaultNameOrNull(): String? = if (platformType == KotlinPlatformType.wasm) { diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/ir/KotlinJsIrTargetPreset.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/ir/KotlinJsIrTargetPreset.kt index 1677fd0323ab0..fe19b07cc81e2 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/ir/KotlinJsIrTargetPreset.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/ir/KotlinJsIrTargetPreset.kt @@ -14,6 +14,7 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinCompilationFactory import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinOnlyTarget import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinOnlyTargetPreset import org.jetbrains.kotlin.gradle.plugin.statistics.KotlinJsIrTargetMetrics +import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget.Companion.buildNpmProjectName @DeprecatedTargetPresetApi open class KotlinJsIrTargetPreset( @@ -29,6 +30,7 @@ open class KotlinJsIrTargetPreset( override fun instantiateTarget(name: String): KotlinJsIrTarget { return project.objects.newInstance(KotlinJsIrTarget::class.java, project, platformType).apply { this.isMpp = this@KotlinJsIrTargetPreset.isMpp + this.outputModuleName.convention(buildNpmProjectName(project, name)) KotlinJsIrTargetMetrics.collectMetrics( isBrowserConfigured = isBrowserConfigured, isNodejsConfigured = isNodejsConfigured, diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/ir/KotlinWasmTargetPreset.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/ir/KotlinWasmTargetPreset.kt index 5313a5a04a4c6..5787af1411286 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/ir/KotlinWasmTargetPreset.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/ir/KotlinWasmTargetPreset.kt @@ -13,6 +13,7 @@ import org.jetbrains.kotlin.gradle.plugin.diagnostics.reportDiagnosticOncePerBui import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinCompilationFactory import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinOnlyTargetPreset import org.jetbrains.kotlin.gradle.targets.js.KotlinWasmTargetType +import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget.Companion.buildNpmProjectName import org.jetbrains.kotlin.util.capitalizeDecapitalize.capitalizeAsciiOnly import org.jetbrains.kotlin.util.capitalizeDecapitalize.toLowerCaseAsciiOnly @@ -26,6 +27,7 @@ class KotlinWasmTargetPreset( override fun instantiateTarget(name: String): KotlinJsIrTarget { val irTarget = project.objects.newInstance(KotlinJsIrTarget::class.java, project, KotlinPlatformType.wasm) irTarget.isMpp = true + irTarget.outputModuleName.convention(buildNpmProjectName(project, name)) irTarget.wasmTargetType = targetType return irTarget diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/ir/NodeJsEnvironmentConfigurator.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/ir/NodeJsEnvironmentConfigurator.kt index f7fed7c880913..14e6c828444d4 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/ir/NodeJsEnvironmentConfigurator.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/ir/NodeJsEnvironmentConfigurator.kt @@ -35,7 +35,7 @@ class NodeJsEnvironmentConfigurator(subTarget: KotlinJsIrSubTarget) : sourceMapStackTraces = false } - val inputFile = if ((compilation.target as KotlinJsIrTarget).wasmTargetType == KotlinWasmTargetType.WASI) { + val inputFile = if (compilation.target.wasmTargetType == KotlinWasmTargetType.WASI) { if (binary is ExecutableWasm && binary.mode == KotlinJsBinaryMode.PRODUCTION) { dependsOn(binary.optimizeTask) binary.mainOptimizedFile diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/npm/NpmProject.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/npm/NpmProject.kt index 4694657e766fd..661360a215031 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/npm/NpmProject.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/npm/NpmProject.kt @@ -10,7 +10,6 @@ import org.gradle.api.file.Directory import org.gradle.api.file.RegularFile import org.gradle.api.provider.Provider import org.gradle.process.ExecSpec -import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation import org.jetbrains.kotlin.gradle.plugin.mpp.disambiguateName import org.jetbrains.kotlin.gradle.plugin.mpp.fileExtension @@ -20,7 +19,6 @@ import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsPlugin.Companion.kotl import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin.Companion.kotlinNodeJsRootExtension import org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinPackageJsonTask import org.jetbrains.kotlin.gradle.utils.getFile -import org.jetbrains.kotlin.util.capitalizeDecapitalize.toLowerCaseAsciiOnly import java.io.File import java.io.Serializable @@ -59,7 +57,7 @@ open class NpmProject(@Transient val compilation: KotlinJsIrCompilation) : Seria } val target: KotlinJsTargetDsl - get() = compilation.target as KotlinJsTargetDsl + get() = compilation.target val project: Project get() = target.project diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/npm/resolver/KotlinCompilationNpmResolver.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/npm/resolver/KotlinCompilationNpmResolver.kt index b60cf4cfa1f8d..abaf347c65600 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/npm/resolver/KotlinCompilationNpmResolver.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/npm/resolver/KotlinCompilationNpmResolver.kt @@ -258,16 +258,6 @@ class KotlinCompilationNpmResolver( dependency: ResolvedDependency, componentIdentifier: ProjectComponentIdentifier, ) { - check(target is KotlinJsIrTarget) { - """ - Composite builds for Kotlin/JS are supported only for IR compiler. - Use kotlin.js.compiler=ir in gradle.properties or - js(IR) { - ... - } - """.trimIndent() - } - (componentIdentifier as DefaultProjectComponentIdentifier).let { identifier -> val includedBuild = project.gradle.includedBuild(identifier.identityPath.topRealPath().name!!) internalCompositeDependencies.add( diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/npm/resolver/KotlinRootNpmResolver.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/npm/resolver/KotlinRootNpmResolver.kt index 2f4f920622e3c..1ba17977e03ef 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/npm/resolver/KotlinRootNpmResolver.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/npm/resolver/KotlinRootNpmResolver.kt @@ -69,7 +69,7 @@ class KotlinRootNpmResolver internal constructor( for (npmResolver in mainCompilations) { val compilation = npmResolver.compilation if (compilation.platformType == KotlinPlatformType.wasm) { - val jsTarget = compilation.target as KotlinJsIrTarget + val jsTarget = compilation.target if (jsTarget.wasmTargetType == KotlinWasmTargetType.JS) { check(!containsWasmJs) { errorMessage } containsWasmJs = true diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/testing/KotlinWasmNode.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/testing/KotlinWasmNode.kt index dd2450a1aee08..3779164876437 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/testing/KotlinWasmNode.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/testing/KotlinWasmNode.kt @@ -14,9 +14,7 @@ import org.jetbrains.kotlin.gradle.targets.js.KotlinWasmTargetType import org.jetbrains.kotlin.gradle.targets.js.RequiredKotlinJsDependency import org.jetbrains.kotlin.gradle.targets.js.internal.parseNodeJsStackTraceAsJvm import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrCompilation -import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsPlugin.Companion.kotlinNodeJsEnvSpec -import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin.Companion.kotlinNodeJsRootExtension import org.jetbrains.kotlin.gradle.targets.js.npm.npmProject import org.jetbrains.kotlin.gradle.targets.js.writeWasmUnitTestRunner @@ -34,14 +32,13 @@ internal class KotlinWasmNode(kotlinJsTest: KotlinJsTest) : KotlinJsTestFramewor private val projectLayout = kotlinJsTest.project.layout override val workingDir: Provider = - (compilation.target as KotlinJsIrTarget).wasmTargetType.let { wasmTargetType -> - if (wasmTargetType != KotlinWasmTargetType.WASI) { - compilation.npmProject.dir - } else { - projectLayout.dir(kotlinJsTest.inputFileProperty.asFile.map { it.parentFile }) - } + if (compilation.target.wasmTargetType != KotlinWasmTargetType.WASI) { + compilation.npmProject.dir + } else { + projectLayout.dir(kotlinJsTest.inputFileProperty.asFile.map { it.parentFile }) } + override val executable: Provider = nodeJs.executable override fun createTestExecutionSpec( diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/tasks/configuration/Kotlin2JsCompileConfig.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/tasks/configuration/Kotlin2JsCompileConfig.kt index cca01f0ada371..be6b008effa7e 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/tasks/configuration/Kotlin2JsCompileConfig.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/tasks/configuration/Kotlin2JsCompileConfig.kt @@ -86,7 +86,7 @@ internal open class BaseKotlin2JsCompileConfig( if (compilation.platformType == KotlinPlatformType.wasm) { add(WASM_BACKEND) - val wasmTargetType = ((compilation.origin as KotlinJsIrCompilation).target as KotlinJsIrTarget).wasmTargetType!! + val wasmTargetType = (compilation.origin as KotlinJsIrCompilation).target.wasmTargetType!! val targetValue = if (wasmTargetType == KotlinWasmTargetType.WASI) "wasm-wasi" else "wasm-js" add("$WASM_TARGET=$targetValue") } diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/tasks/configuration/KotlinJsIrLinkConfig.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/tasks/configuration/KotlinJsIrLinkConfig.kt index 06c3d1266d10c..aa559fab49d24 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/tasks/configuration/KotlinJsIrLinkConfig.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/tasks/configuration/KotlinJsIrLinkConfig.kt @@ -99,7 +99,7 @@ internal open class KotlinJsIrLinkConfig( if (compilation.platformType == KotlinPlatformType.wasm) { add(WASM_BACKEND) - val wasmTargetType = ((compilation.origin as KotlinJsIrCompilation).target as KotlinJsIrTarget).wasmTargetType!! + val wasmTargetType = (compilation.origin as KotlinJsIrCompilation).target.wasmTargetType!! val targetValue = if (wasmTargetType == KotlinWasmTargetType.WASI) "wasm-wasi" else "wasm-js" add("$WASM_TARGET=$targetValue") }