[Gradle, JS] root package json must run after simple package jsons

KT-34832
This commit is contained in:
Ilya Goncharov
2020-04-23 17:21:17 +03:00
parent 39e1635c41
commit f87f32c5a8
4 changed files with 8 additions and 10 deletions
@@ -17,7 +17,7 @@ open class PackageJsonDukatTask : AbstractDukatTask() {
@get:Internal @get:Internal
val dts by lazy { val dts by lazy {
val resolvedCompilation = nodeJs.npmResolutionManager.installIfNeeded()[project][compilation] val resolvedCompilation = nodeJs.npmResolutionManager.requireInstalled()[project][compilation]
val dtsResolver = DtsResolver(resolvedCompilation.npmProject) val dtsResolver = DtsResolver(resolvedCompilation.npmProject)
dtsResolver.getAllDts(resolvedCompilation.externalNpmDependencies) dtsResolver.getAllDts(resolvedCompilation.externalNpmDependencies)
} }
@@ -47,20 +47,21 @@ import java.io.File
* by compilation that depends on this compilation. Note that package.json will be executed only for * by compilation that depends on this compilation. Note that package.json will be executed only for
* required compilations, while other may be missed. * required compilations, while other may be missed.
* *
* **installed**. Global final state. Initiated by executing global `rootPackageJson` task. * **Prepared**.
* Global final state. Initiated by executing global `rootPackageJson` task.
* *
* **resolved**. * **Installed**.
* All created package.json files will be gathered and package manager will be executed. * All created package.json files will be gathered and package manager will be executed.
* Package manager will create lock file, that will be parsed for transitive npm dependencies * Package manager will create lock file, that will be parsed for transitive npm dependencies
* that will be added to the root [NpmDependency] objects. `kotlinNpmInstall` task may be up-to-date. * that will be added to the root [NpmDependency] objects. `kotlinNpmInstall` task may be up-to-date.
* In this case, installed state will be reached by first call of [prepareIfNeeded] without executing * In this case, installed state will be reached by first call of [installIfNeeded] without executing
* package manager. * package manager.
* *
* Resolution will be used from [NpmDependency] by calling [getNpmDependencyResolvedCompilation]. * Resolution will be used from [NpmDependency] by calling [getNpmDependencyResolvedCompilation].
* Also resolution will be checked before calling [NpmProject.require] and executing any task * Also resolution will be checked before calling [NpmProject.require] and executing any task
* that requires npm dependencies or node_modules. * that requires npm dependencies or node_modules.
* *
* User can call [requirePrepared] to get resolution info. * User can call [requireInstalled] to get resolution info.
* *
* ## Resolving process during Idea import * ## Resolving process during Idea import
* *
@@ -115,7 +116,7 @@ class KotlinNpmResolutionManager(private val nodeJsSettings: NodeJsRootExtension
} }
@Incubating @Incubating
internal fun requirePrepared() = prepareIfNeeded(requireUpToDateReason = "") internal fun requireInstalled() = installIfNeeded(reason = "")
internal fun requireConfiguringState(): KotlinRootNpmResolver = internal fun requireConfiguringState(): KotlinRootNpmResolver =
(this.state as? ResolutionState.Configuring ?: error("NPM Dependencies already resolved and installed")).resolver (this.state as? ResolutionState.Configuring ?: error("NPM Dependencies already resolved and installed")).resolver
@@ -74,7 +74,7 @@ open class KotlinPackageJsonTask : DefaultTask() {
task.inputs.file(packageJsonTask.map { it.packageJson }) task.inputs.file(packageJsonTask.map { it.packageJson })
} }
npmInstallTask.mustRunAfter(packageJsonTask) nodeJs.rootPackageJsonTask.mustRunAfter(packageJsonTask)
compilation.compileKotlinTask.dependsOn( compilation.compileKotlinTask.dependsOn(
npmInstallTask, npmInstallTask,
@@ -10,7 +10,6 @@ import org.gradle.api.Project
import org.gradle.api.plugins.BasePlugin import org.gradle.api.plugins.BasePlugin
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
import org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinNpmInstallTask import org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinNpmInstallTask
import org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinPackageJsonTask
import org.jetbrains.kotlin.gradle.targets.js.npm.tasks.RootPackageJsonTask import org.jetbrains.kotlin.gradle.targets.js.npm.tasks.RootPackageJsonTask
import org.jetbrains.kotlin.gradle.tasks.CleanDataTask import org.jetbrains.kotlin.gradle.tasks.CleanDataTask
@@ -34,8 +33,6 @@ open class YarnPlugin : Plugin<Project> {
task.description = "Create root package.json" task.description = "Create root package.json"
task.mustRunAfter(rootClean) task.mustRunAfter(rootClean)
task.mustRunAfter(tasks.withType(KotlinPackageJsonTask::class.java))
} }
tasks.named(KotlinNpmInstallTask.NAME).configure { tasks.named(KotlinNpmInstallTask.NAME).configure {