From d1e665235d7a4190c32361d482e21303ac05768d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martynas=20Petu=C5=A1ka?= Date: Mon, 30 Dec 2024 15:50:02 +0000 Subject: [PATCH] fix: Gradle task dependency graph workaround --- .../src/main/kotlin/NpmPublishPlugin.kt | 12 ++++++++++-- .../src/main/kotlin/config/extension.kt | 14 ++++++++++++-- .../src/main/kotlin/config/kotlinJsTarget.kt | 1 - 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/npm-publish-gradle-plugin/src/main/kotlin/NpmPublishPlugin.kt b/npm-publish-gradle-plugin/src/main/kotlin/NpmPublishPlugin.kt index 36cce8b5..c974a6e5 100644 --- a/npm-publish-gradle-plugin/src/main/kotlin/NpmPublishPlugin.kt +++ b/npm-publish-gradle-plugin/src/main/kotlin/NpmPublishPlugin.kt @@ -3,6 +3,7 @@ package dev.petuska.npm.publish import dev.petuska.npm.publish.config.configure import dev.petuska.npm.publish.config.configureNebulaNode import dev.petuska.npm.publish.extension.NpmPublishExtension +import dev.petuska.npm.publish.task.NodeExecTask import dev.petuska.npm.publish.task.NpmAssembleTask import dev.petuska.npm.publish.task.NpmPackTask import dev.petuska.npm.publish.task.NpmPublishTask @@ -46,10 +47,17 @@ public class NpmPublishPlugin : Plugin { } afterEvaluate { - if (rootProject.tasks.names.contains("kotlinNodeJsSetup")) { - rootProject.tasks.named("kotlinNodeJsSetup").map(NodeJsSetupTask::destination) + if (tasks.names.contains("kotlinNodeJsSetup")) { + tasks.named("kotlinNodeJsSetup") + .map(NodeJsSetupTask::destination) .let(layout::dir) .let(extension.nodeHome::convention) + // Hack to work around all KGP kotlinNodeJsSetup tasks sharing the same output dir. + rootProject.allprojects { subProject -> + tasks.withType(NodeExecTask::class.java) { + it.mustRunAfter(subProject.tasks.withType(NodeJsSetupTask::class.java)) + } + } } tasks.maybeCreate("assemble").apply { group = "build" diff --git a/npm-publish-gradle-plugin/src/main/kotlin/config/extension.kt b/npm-publish-gradle-plugin/src/main/kotlin/config/extension.kt index d4d83fc8..9d00c1ea 100644 --- a/npm-publish-gradle-plugin/src/main/kotlin/config/extension.kt +++ b/npm-publish-gradle-plugin/src/main/kotlin/config/extension.kt @@ -16,8 +16,18 @@ internal fun Project.configure(extension: NpmPublishExtension) { default = providers.environmentVariable("NODE_HOME") ).map(layout.projectDirectory::dir) ) - extension.nodeBin.convention(extension.nodeHome.map { it.file("bin/node") }) - extension.npmBin.convention(extension.nodeHome.map { it.file("bin/npm") }) + extension.nodeBin.convention( + sysProjectEnvPropertyConvention( + "nodeBin", + extension.nodeHome.map { it.file("bin/node").asFile.absolutePath } + ).map(layout.projectDirectory::file) + ) + extension.npmBin.convention( + sysProjectEnvPropertyConvention( + "npmBin", + extension.nodeHome.map { it.file("bin/npm").asFile.absolutePath } + ).map(layout.projectDirectory::file) + ) extension.readme.convention( sysProjectEnvPropertyConvention("readme").map(layout.projectDirectory::file) ) diff --git a/npm-publish-gradle-plugin/src/main/kotlin/config/kotlinJsTarget.kt b/npm-publish-gradle-plugin/src/main/kotlin/config/kotlinJsTarget.kt index fd5cb651..53368ca2 100644 --- a/npm-publish-gradle-plugin/src/main/kotlin/config/kotlinJsTarget.kt +++ b/npm-publish-gradle-plugin/src/main/kotlin/config/kotlinJsTarget.kt @@ -52,7 +52,6 @@ internal fun Project.configure(target: KotlinJsTargetDsl): Unit = with(PluginLog } null -> null - else -> error("Unrecognised Kotlin/JS binary type: ${it::class.java.name}") } } val compileKotlinTask = binary.flatMap(JsIrBinary::linkTask)