@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.gradle.targets.js.yarn
8
8
import org.gradle.api.Plugin
9
9
import org.gradle.api.Project
10
10
import org.gradle.api.plugins.BasePlugin
11
+ import org.gradle.api.tasks.TaskProvider
11
12
import org.jetbrains.kotlin.gradle.targets.js.MultiplePluginDeclarationDetector
12
13
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
13
14
import org.jetbrains.kotlin.gradle.targets.js.npm.RequiresNpmDependencies
@@ -44,30 +45,10 @@ open class YarnPlugin : Plugin<Project> {
44
45
task.description = " Create root package.json"
45
46
46
47
task.mustRunAfter(rootClean)
47
-
48
- // Yes, we need to break Task Configuration Avoidance here
49
- // In case when we need to create package.json's files and execute kotlinNpmInstall,
50
- // We need to configure all RequiresNpmDependencies tasks to install them,
51
- // Because we need to persist yarn.lock
52
- // We execute this block in configure phase of rootPackageJson to be sure,
53
- // That Task Configuration Avoidance will not be broken for tasks not related with NPM installing
54
- // https://youtrack.jetbrains.com/issue/KT-48241
55
- project.allprojects
56
- .forEach {
57
- val fn: (Project ) -> Unit = {
58
- it.tasks.implementing(RequiresNpmDependencies ::class )
59
- .forEach {}
60
- }
61
- if (it.state.executed) {
62
- fn(it)
63
- } else {
64
- it.afterEvaluate {
65
- fn(it)
66
- }
67
- }
68
- }
69
48
}
70
49
50
+ configureRequiresNpmDependencies(project, rootPackageJson)
51
+
71
52
val kotlinNpmInstall = tasks.named(KotlinNpmInstallTask .NAME )
72
53
kotlinNpmInstall.configure {
73
54
it.dependsOn(rootPackageJson)
@@ -109,6 +90,42 @@ open class YarnPlugin : Plugin<Project> {
109
90
}
110
91
}
111
92
93
+ // Yes, we need to break Task Configuration Avoidance here
94
+ // In case when we need to create package.json's files and execute kotlinNpmInstall,
95
+ // We need to configure all RequiresNpmDependencies tasks to install them,
96
+ // Because we need to persist yarn.lock
97
+ // We execute this block in configure phase of rootPackageJson to be sure,
98
+ // That Task Configuration Avoidance will not be broken for tasks not related with NPM installing
99
+ // https://youtrack.jetbrains.com/issue/KT-48241
100
+ private fun configureRequiresNpmDependencies (
101
+ project : Project ,
102
+ rootPackageJson : TaskProvider <RootPackageJsonTask >
103
+ ) {
104
+ val fn: (Project ) -> Unit = {
105
+ it.tasks.implementing(RequiresNpmDependencies ::class )
106
+ .forEach {}
107
+ }
108
+ rootPackageJson.configure {
109
+ project.allprojects
110
+ .forEach { project ->
111
+ if (it.state.executed) {
112
+ fn(project)
113
+ }
114
+ }
115
+ }
116
+
117
+ project.allprojects
118
+ .forEach {
119
+ if (! it.state.executed) {
120
+ it.afterEvaluate { project ->
121
+ rootPackageJson.configure {
122
+ fn(project)
123
+ }
124
+ }
125
+ }
126
+ }
127
+ }
128
+
112
129
companion object {
113
130
fun apply (project : Project ): YarnRootExtension {
114
131
val rootProject = project.rootProject
0 commit comments